Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: transaction would not save for manually resized rows having wrap #1743

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 27 additions & 29 deletions quadratic-core/src/controller/execution/auto_resize_row_heights.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
use uuid::Uuid;

use super::GridController;
use crate::{
controller::{
active_transactions::pending_transaction::PendingTransaction,
operations::operation::Operation,
},
error_core::Result,
grid::{js_types::JsRowHeight, SheetId},
};
use crate::controller::active_transactions::pending_transaction::PendingTransaction;
use crate::controller::operations::operation::Operation;
use crate::error_core::Result;
use crate::grid::js_types::JsRowHeight;
use crate::grid::SheetId;

impl GridController {
pub fn start_auto_resize_row_heights(
&mut self,
transaction: &mut PendingTransaction,
sheet_id: SheetId,
rows: Vec<i64>,
) {
) -> bool {
if (!cfg!(target_family = "wasm") && !cfg!(test))
|| !transaction.is_user()
|| rows.is_empty()
{
return;
return false;

Check warning on line 21 in quadratic-core/src/controller/execution/auto_resize_row_heights.rs

View check run for this annotation

Codecov / codecov/patch

quadratic-core/src/controller/execution/auto_resize_row_heights.rs#L21

Added line #L21 was not covered by tests
}

if let Some(sheet) = self.try_sheet(sheet_id) {
let mut auto_resize_rows = sheet.get_auto_resize_rows(rows);
if auto_resize_rows.is_empty() {
return;
return false;

Check warning on line 27 in quadratic-core/src/controller/execution/auto_resize_row_heights.rs

View check run for this annotation

Codecov / codecov/patch

quadratic-core/src/controller/execution/auto_resize_row_heights.rs#L27

Added line #L27 was not covered by tests
}
auto_resize_rows.sort();
if let Ok(rows_string) = serde_json::to_string(&auto_resize_rows) {
Expand All @@ -40,13 +37,15 @@
// as we will not receive renderer callback during tests and the transaction will never complete
if !cfg!(test) {
self.transactions.add_async_transaction(transaction);
return true;

Check warning on line 40 in quadratic-core/src/controller/execution/auto_resize_row_heights.rs

View check run for this annotation

Codecov / codecov/patch

quadratic-core/src/controller/execution/auto_resize_row_heights.rs#L40

Added line #L40 was not covered by tests
}
} else {
dbgjs!("[control_transactions] start_auto_resize_row_heights: Failed to serialize auto resize rows");
}
} else {
dbgjs!("[control_transactions] start_auto_resize_row_heights: Sheet not found");
}
false
}

pub fn complete_auto_resize_row_heights(
Expand All @@ -70,27 +69,26 @@

#[cfg(test)]
mod tests {
use crate::{
controller::{
active_transactions::pending_transaction::PendingTransaction,
execution::run_code::get_cells::JsGetCellResponse, operations::operation::Operation,
transaction_types::JsCodeResult, GridController,
},
grid::{
formats::{format_update::FormatUpdate, Formats},
js_types::JsRowHeight,
CellAlign, CellVerticalAlign, CellWrap, CodeCellLanguage, NumericFormat,
NumericFormatKind, RenderSize, SheetId,
},
selection::Selection,
sheet_offsets::resize_transient::TransientResize,
wasm_bindings::js::{clear_js_calls, expect_js_call, expect_js_call_count},
CellValue, Pos, SheetPos, SheetRect,
};

use bigdecimal::BigDecimal;
use serial_test::serial;

use crate::controller::active_transactions::pending_transaction::PendingTransaction;
use crate::controller::execution::run_code::get_cells::JsGetCellResponse;
use crate::controller::operations::operation::Operation;
use crate::controller::transaction_types::JsCodeResult;
use crate::controller::GridController;
use crate::grid::formats::format_update::FormatUpdate;
use crate::grid::formats::Formats;
use crate::grid::js_types::JsRowHeight;
use crate::grid::{
CellAlign, CellVerticalAlign, CellWrap, CodeCellLanguage, NumericFormat, NumericFormatKind,
RenderSize, SheetId,
};
use crate::selection::Selection;
use crate::sheet_offsets::resize_transient::TransientResize;
use crate::wasm_bindings::js::{clear_js_calls, expect_js_call, expect_js_call_count};
use crate::{CellValue, Pos, SheetPos, SheetRect};

fn mock_auto_resize_row_heights(
gc: &mut GridController,
sheet_id: SheetId,
Expand Down
49 changes: 22 additions & 27 deletions quadratic-core/src/controller/execution/control_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@ use chrono::Utc;
use uuid::Uuid;

use super::{GridController, TransactionType};
use crate::{
controller::{
active_transactions::{
pending_transaction::PendingTransaction, transaction_name::TransactionName,
},
operations::operation::Operation,
transaction::Transaction,
transaction_summary::{CELL_SHEET_HEIGHT, CELL_SHEET_WIDTH},
transaction_types::JsCodeResult,
},
error_core::Result,
grid::{CodeRun, CodeRunResult},
parquet::parquet_to_vec,
Pos, Value,
};
use crate::controller::active_transactions::pending_transaction::PendingTransaction;
use crate::controller::active_transactions::transaction_name::TransactionName;
use crate::controller::operations::operation::Operation;
use crate::controller::transaction::Transaction;
use crate::controller::transaction_summary::{CELL_SHEET_HEIGHT, CELL_SHEET_WIDTH};
use crate::controller::transaction_types::JsCodeResult;
use crate::error_core::Result;
use crate::grid::{CodeRun, CodeRunResult};
use crate::parquet::parquet_to_vec;
use crate::{Pos, Value};

impl GridController {
// loop compute cycle until complete or an async call is made
Expand Down Expand Up @@ -46,12 +41,13 @@ impl GridController {
.map(|(&k, v)| (k, v.clone()))
{
transaction.resize_rows.remove(&sheet_id);
if !rows.is_empty() {
self.start_auto_resize_row_heights(
transaction,
sheet_id,
rows.into_iter().collect(),
);
let resizing = self.start_auto_resize_row_heights(
transaction,
sheet_id,
rows.into_iter().collect(),
);
// break only if async resize operation is being executed
if resizing {
break;
}
}
Expand Down Expand Up @@ -226,14 +222,13 @@ impl From<Pos> for CellHash {

#[cfg(test)]
mod tests {
use super::*;
use crate::{
cell_values::CellValues,
grid::{CodeCellLanguage, ConnectionKind, GridBounds},
CellValue, Pos, Rect, SheetPos,
};
use serial_test::parallel;

use super::*;
use crate::cell_values::CellValues;
use crate::grid::{CodeCellLanguage, ConnectionKind, GridBounds};
use crate::{CellValue, Pos, Rect, SheetPos};

fn add_cell_value(sheet_pos: SheetPos, value: CellValue) -> Operation {
Operation::SetCellValues {
sheet_pos,
Expand Down
Loading