Skip to content

Commit

Permalink
Merge branch 'data-tables-v1' of github.com:quadratichq/quadratic int…
Browse files Browse the repository at this point in the history
…o data-tables-v1
  • Loading branch information
AyushAgrawal-A2 committed Feb 7, 2025
2 parents 61cbe72 + 15d0cf3 commit d041781
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 53 deletions.
12 changes: 11 additions & 1 deletion quadratic-client/src/app/gridGL/UI/Cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class Cursor extends Container {
}

// draw cursor
if (tableName) {
if (table && tableName) {
this.graphics.lineStyle({
width: 1,
color: 0xffffff,
Expand All @@ -134,6 +134,16 @@ export class Cursor extends Container {
this.graphics.moveTo(x + width - offset - 1, y + height - offset);
this.graphics.lineTo(x + offset, y + height - offset);
this.graphics.lineTo(x + offset, y + offset);

// create the corner icon
this.graphics.lineStyle({
color: getCSSVariableTint('primary'),
width: 1,
alignment: 0,
});
this.graphics.beginFill(0xffffff, 1);
this.graphics.drawShape(new Rectangle(x + width - 4, y + table.tableBounds.height - 4, 8, 8));
this.graphics.endFill();
} else {
this.graphics.lineStyle({
width: CURSOR_THICKNESS,
Expand Down
15 changes: 13 additions & 2 deletions quadratic-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ path = "src/bin/upgrade_file.rs"
[features]
default = ["console_error_panic_hook", "js"]
# "js" feature is disabled for testing (particularly WASI benchmarks)
js = ["js-sys", "serde-wasm-bindgen", "ts-rs", "wasm-bindgen", "wasm-bindgen-futures"]
js = [
"js-sys",
"serde-wasm-bindgen",
"ts-rs",
"wasm-bindgen",
"wasm-bindgen-futures",
]
show-operations = []
multiplayer = []
files = []
Expand Down Expand Up @@ -82,7 +88,12 @@ csv = "1.3.0"
indexmap = { version = "2.0.2", features = ["serde"] }
thiserror = "1.0.52"
lazy_static = "1.4.0"
parquet = { version = "51.0.0", default-features = false, features = ["arrow", "arrow-array", "flate2", "snap"] }
parquet = { version = "51.0.0", default-features = false, features = [
"arrow",
"arrow-array",
"flate2",
"snap",
] }
bytes = "1.5.0"
arrow-array = "51.0.0"
arrow-schema = "51.0.0"
Expand Down
10 changes: 5 additions & 5 deletions quadratic-core/src/a1/a1_selection/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ impl A1Selection {
return false;
}
if let Some(CellRefRange::Table { range }) = self.ranges.first() {
range.data
range.data || range.headers
} else {
false
}
Expand Down Expand Up @@ -426,9 +426,9 @@ impl A1Selection {
.ranges
.iter()
.filter_map(|range| match range {
CellRefRange::Table { range } => {
range.convert_to_ref_range_bounds(false, context, false, true).map(|range| CellRefRange::Sheet { range })
}
CellRefRange::Table { range } => range
.convert_to_ref_range_bounds(false, context, false, true)
.map(|range| CellRefRange::Sheet { range }),
_ => Some(range.clone()),
})
.collect();
Expand Down Expand Up @@ -808,7 +808,7 @@ mod tests {
let context = A1Context::test(&[], &[("Table1", &["A", "B"], Rect::test_a1("A1:B2"))]);
assert!(A1Selection::test_a1_context("Table1", &context).has_table_headers());
assert!(A1Selection::test_a1_context("Table1[#ALL]", &context).has_table_headers());
assert!(!A1Selection::test_a1_context("Table1[#headers]", &context).has_table_headers());
assert!(A1Selection::test_a1_context("Table1[#headers]", &context).has_table_headers());
assert!(A1Selection::test_a1_context("Table1[#all]", &context).has_table_headers());
}

Expand Down
4 changes: 2 additions & 2 deletions quadratic-core/src/a1/a1_selection/select_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ mod tests {
"Table1[Col1]"
);

assert_eq!(selection.cursor, pos!(A3));
assert_eq!(selection.cursor, pos!(A1));
let mut selection = A1Selection::test_a1("A1");
selection.select_table("Table1", None, &context, 1, true, false);
assert_eq!(selection.ranges.len(), 2);
Expand Down Expand Up @@ -336,7 +336,7 @@ mod tests {
selection.move_to(1, 1, false, &context);

selection.select_table("Table1", None, &context, 3, false, false);
assert_eq!(selection.cursor, pos!(A7));
assert_eq!(selection.cursor, pos!(A5));
assert_eq!(
selection.to_string(Some(SheetId::test()), &context),
"Table1"
Expand Down
44 changes: 18 additions & 26 deletions quadratic-core/src/a1/cell_ref_range/to_table_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ impl CellRefRange {

if let Some(table) = context.table_from_pos(start) {
let b = table.bounds;
let adjust_for_name = if table.show_ui && table.show_name {
1
} else {
0
};
let adjust_for_columns = if table.show_ui && table.show_columns {
1
} else {
0
};

// if we're in the name cell of the table, then we should return the table ref
if start == end
Expand Down Expand Up @@ -82,8 +92,8 @@ impl CellRefRange {
// only column headers
if table.show_ui
&& table.show_columns
&& start.y == b.min.y + (if table.show_name { 1 } else { 0 })
&& end.y == b.min.y + (if table.show_name { 1 } else { 0 })
&& start.y == b.min.y + adjust_for_name
&& end.y == b.min.y + adjust_for_name
{
return Some(CellRefRange::Table {
range: TableRef {
Expand All @@ -97,20 +107,7 @@ impl CellRefRange {
}

// only data
if start.y
== b.min.y
+ (if table.show_ui && table.show_name {
1
} else {
0
})
+ (if table.show_ui && table.show_columns {
1
} else {
0
})
&& end.y == b.max.y
{
if start.y == b.min.y + adjust_for_name + adjust_for_columns && end.y == b.max.y {
return Some(CellRefRange::Table {
range: TableRef {
table_name: table.table_name.clone(),
Expand All @@ -122,16 +119,11 @@ impl CellRefRange {
});
}

// data and column headers
if start.y
== b.min.y
+ (if table.show_ui && table.show_name {
1
} else {
0
})
&& end.y == b.max.y
{
let full_table = start.y == b.min.y && end.y == b.max.y;
let data_and_headers = start.y == b.min.y + adjust_for_name && end.y == b.max.y;

// full table or data and column headers
if full_table || data_and_headers {
return Some(CellRefRange::Table {
range: TableRef {
table_name: table.table_name.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ impl GridController {
// easily implement cut/paste/move without resorting to this
// approach.
let mut operations = VecDeque::new();
let selection = A1Selection::from_rect(source);
let context = self.grid.a1_context();
let mut selection = A1Selection::from_rect(source);
selection.check_for_table_ref(&context);

if let Ok((cut_ops, js_clipboard)) = self.cut_to_clipboard_operations(&selection) {
operations.extend(cut_ops);

Expand All @@ -37,3 +40,31 @@ impl GridController {
}
}
}

#[cfg(test)]
mod tests {
use crate::{
controller::user_actions::import::tests::simple_csv, test_util::print_table, Rect, SheetPos,
};

use super::*;

#[test]
fn test_move_cells() {
let (mut gc, sheet_id, pos, _) = simple_csv();
let sheet_pos = SheetPos::from((pos, sheet_id));
let data_table = gc.sheet(sheet_id).data_table(pos).unwrap().to_owned();

print_table(&gc, sheet_id, Rect::new(1, 1, 4, 12));

let dest_pos = pos![F1];
let sheet_dest_pos = SheetPos::from((dest_pos, sheet_id));
let mut transaction = PendingTransaction::default();
let op = Operation::MoveCells {
source: data_table.output_sheet_rect(sheet_pos, true),
dest: sheet_dest_pos,
};
gc.execute_move_cells(&mut transaction, op);
print_table(&gc, sheet_id, Rect::new(6, 1, 10, 12));
}
}
16 changes: 2 additions & 14 deletions quadratic-core/src/controller/execution/receive_multiplayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,10 @@ impl GridController {
}

#[cfg(test)]
#[serial_test::parallel]
mod tests {
use bigdecimal::BigDecimal;
use serial_test::{parallel, serial};
use serial_test::serial;
use uuid::Uuid;

use super::*;
Expand All @@ -315,7 +316,6 @@ mod tests {
use crate::{CellValue, Pos, SheetPos};

#[test]
#[parallel]
fn test_multiplayer_hello_world() {
let mut gc1 = GridController::test();
let sheet_id = gc1.sheet_ids()[0];
Expand Down Expand Up @@ -359,7 +359,6 @@ mod tests {
}

#[test]
#[parallel]
fn test_apply_multiplayer_before_unsaved_transaction() {
let mut gc1 = GridController::test();
let sheet_id = gc1.sheet_ids()[0];
Expand Down Expand Up @@ -411,7 +410,6 @@ mod tests {
}

#[test]
#[parallel]
fn test_server_apply_transaction() {
let mut client = GridController::test();
let sheet_id = client.sheet_ids()[0];
Expand Down Expand Up @@ -444,7 +442,6 @@ mod tests {
}

#[test]
#[parallel]
fn test_handle_receipt_of_earlier_transactions() {
// client is where the multiplayer transactions are applied from other
let mut client = GridController::test();
Expand Down Expand Up @@ -499,7 +496,6 @@ mod tests {
}

#[test]
#[parallel]
fn test_handle_receipt_of_out_of_order_transactions() {
// client is where the multiplayer transactions are applied from other
let mut client = GridController::test();
Expand Down Expand Up @@ -561,7 +557,6 @@ mod tests {
}

#[test]
#[parallel]
fn test_handle_receipt_of_earlier_transactions_and_out_of_order_transactions() {
let mut client = GridController::test();
let sheet_id = client.sheet_ids()[0];
Expand Down Expand Up @@ -729,7 +724,6 @@ mod tests {
}

#[test]
#[parallel]
fn test_receive_multiplayer_while_waiting_for_async() {
let mut client = GridController::test();
let sheet_id = client.sheet_ids()[0];
Expand Down Expand Up @@ -812,7 +806,6 @@ mod tests {
}

#[test]
#[parallel]
fn test_receive_overlapping_multiplayer_while_waiting_for_async() {
// Unlike previous test, we receive a multiplayer transaction that will be underneath the async code_cell.
// We expect the async code_cell to overwrite it when it completes.
Expand Down Expand Up @@ -950,7 +943,6 @@ mod tests {
}

#[test]
#[parallel]
fn python_multiple_calculations_receive_back_afterwards() {
let mut gc = GridController::test();
let (transaction_id_0, operations_0) = create_multiple_calculations_0(&mut gc);
Expand Down Expand Up @@ -987,7 +979,6 @@ mod tests {
}

#[test]
#[parallel]
fn test_python_multiple_calculations_receive_back_between() {
let mut gc = GridController::test();
let (transaction_id_0, operations_0) = create_multiple_calculations_0(&mut gc);
Expand Down Expand Up @@ -1015,7 +1006,6 @@ mod tests {
}

#[test]
#[parallel]
fn test_receive_offline_unsaved_transaction() {
let mut gc = GridController::test();
let sheet_id = gc.sheet_ids()[0];
Expand Down Expand Up @@ -1049,7 +1039,6 @@ mod tests {
}

#[test]
#[parallel]
fn ensure_code_run_ordering_is_maintained_for_undo() {
let mut gc = GridController::test();
let sheet_id = gc.sheet_ids()[0];
Expand Down Expand Up @@ -1127,7 +1116,6 @@ mod tests {
}

#[test]
#[parallel]
fn receive_our_transactions_out_of_order() {
let mut gc = GridController::test();
let (transaction_id_0, operations_0) = create_multiple_calculations_0(&mut gc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ mod test {
w: 2,
h: 1,
two_dimensional: true,
has_headers: false,
has_headers: true,
})
);
}
Expand Down
2 changes: 1 addition & 1 deletion quadratic-core/src/formulas/parser/rules/atoms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl SyntaxRule for TableReference {
}

fn consume_match(&self, p: &mut Parser<'_>) -> CodeResult<Self::Output> {
let start_span = p.peek_next_span();
// let start_span = p.peek_next_span();

// Sheet name is allowed but ignored for table references.
// Table names are unique across the whole file.
Expand Down

0 comments on commit d041781

Please sign in to comment.