Skip to content

Commit

Permalink
initial work on language output
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfig committed Feb 5, 2025
1 parent f1e905b commit 5533d62
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
6 changes: 1 addition & 5 deletions quadratic-client/src/app/gridGL/cells/tables/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export class Table extends Container {
}

shouldHideTableName(): boolean {
return !this.codeCell.show_ui;
return !this.codeCell.show_ui || !this.codeCell.show_name;
}

isCodeCell = (): boolean => {
Expand All @@ -255,8 +255,4 @@ export class Table extends Container {
isSingleValue = (): boolean => {
return this.codeCell.w === 1 && this.codeCell.h === 1;
};

isSingleCellOutputCodeCell = (): boolean => {
return this.isCodeCell() && this.isSingleValue();
};
}
4 changes: 2 additions & 2 deletions quadratic-core/src/controller/execution/run_code/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ impl GridController {
))
}
};
let has_headers = result.has_headers;
match &transaction.waiting_for_async {
None => {
return Err(CoreError::TransactionNotFound("Expected transaction to be waiting_for_async to be defined in transaction::complete".into()));
Expand Down Expand Up @@ -257,8 +258,7 @@ impl GridController {
new_data_table.name = existing_data_table.name.clone();
new_data_table.show_ui = existing_data_table.show_ui;
} else {
new_data_table.show_ui = !new_data_table.is_single_value();
new_data_table.show_columns = !new_data_table.is_single_column();
new_data_table.show_columns = has_headers;
}
}

Expand Down
44 changes: 43 additions & 1 deletion quadratic-core/src/grid/data_table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,11 @@ impl DataTable {

size
}
Value::Single(_) | Value::Tuple(_) => ArraySize::_1X1,
Value::Single(_) | Value::Tuple(_) => {
let mut height: u32 = 1;
height = height.saturating_add_signed(self.y_adjustment(true) as i32);
ArraySize::new(1, height).unwrap_or(ArraySize::_1X1)
}
}
}
}
Expand Down Expand Up @@ -924,4 +928,42 @@ pub mod test {
assert_eq!(data_table.get_column_index_from_display_index(0), 1);
assert_eq!(data_table.get_column_index_from_display_index(1), 3);
}

#[test]
fn test_output_size_single_value() {
let code_run = CodeRun {
std_out: None,
std_err: None,
cells_accessed: Default::default(),
error: None,
return_type: Some("number".into()),
line_number: None,
output_type: None,
};

// Test with show_ui = false (no name or columns shown)
let data_table = DataTable::new(
DataTableKind::CodeRun(code_run.clone()),
"Table 1",
Value::Single(CellValue::Number(1.into())),
false,
false,
false,
None,
);
assert_eq!(data_table.output_size(), ArraySize::_1X1);

// Test with show_ui = true (name and columns shown)
let data_table = DataTable::new(
DataTableKind::CodeRun(code_run),
"Table 1",
Value::Single(CellValue::Number(1.into())),
false,
false,
true,
None,
);
// Height should be 3 (1 for value + 1 for name + 1 for columns)
assert_eq!(data_table.output_size(), ArraySize::new(1, 3).unwrap());
}
}

0 comments on commit 5533d62

Please sign in to comment.