From a516ec82bcfb3c741aad76591d149c7399477384 Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Wed, 12 Oct 2022 10:20:26 +0800 Subject: [PATCH] fix: row disappear when update the row in checkbox board (#1266) --- .../checkbox_type_option_entities.rs | 4 ++ .../src/services/group/controller.rs | 12 ++++-- .../controller_impls/checkbox_controller.rs | 38 ++++++++++++++----- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_type_option_entities.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_type_option_entities.rs index cfc123fad9..cfe6a7b65d 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_type_option_entities.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/checkbox_type_option/checkbox_type_option_entities.rs @@ -12,6 +12,10 @@ impl CheckboxCellData { pub fn is_check(&self) -> bool { self.0 == CHECK } + + pub fn is_uncheck(&self) -> bool { + self.0 == UNCHECK + } } impl AsRef<[u8]> for CheckboxCellData { diff --git a/frontend/rust-lib/flowy-grid/src/services/group/controller.rs b/frontend/rust-lib/flowy-grid/src/services/group/controller.rs index 397fcdd9eb..7826ce50c6 100644 --- a/frontend/rust-lib/flowy-grid/src/services/group/controller.rs +++ b/frontend/rust-lib/flowy-grid/src/services/group/controller.rs @@ -270,12 +270,16 @@ where let cell_bytes = decode_any_cell_data(cell_rev.data.clone(), field_rev).1; let cell_data = cell_bytes.parser::
()?; let mut changesets = self.add_row_if_match(row_rev, &cell_data); - if let Some(default_group_changeset) = self.update_default_group(row_rev, &changesets) { - tracing::trace!("default_group_changeset: {}", default_group_changeset); - if !default_group_changeset.is_empty() { - changesets.push(default_group_changeset); + + if self.use_default_group() { + if let Some(default_group_changeset) = self.update_default_group(row_rev, &changesets) { + tracing::trace!("default_group_changeset: {}", default_group_changeset); + if !default_group_changeset.is_empty() { + changesets.push(default_group_changeset); + } } } + Ok(changesets) } else { Ok(vec![]) diff --git a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/checkbox_controller.rs b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/checkbox_controller.rs index b26ff9bdbe..7d41ccefc0 100644 --- a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/checkbox_controller.rs +++ b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/checkbox_controller.rs @@ -43,17 +43,37 @@ impl GroupAction for CheckboxGroupController { let mut changesets = vec![]; self.group_ctx.iter_mut_all_groups(|group| { let mut changeset = GroupChangesetPB::new(group.id.clone()); - let is_contained = group.contains_row(&row_rev.id); - if group.id == CHECK && cell_data.is_check() { - if !is_contained { - let row_pb = RowPB::from(row_rev); - changeset.inserted_rows.push(InsertedRowPB::new(row_pb.clone())); - group.add_row(row_pb); + let is_not_contained = !group.contains_row(&row_rev.id); + if group.id == CHECK { + if cell_data.is_uncheck() { + // Remove the row if the group.id is CHECK but the cell_data is UNCHECK + changeset.deleted_rows.push(row_rev.id.clone()); + group.remove_row(&row_rev.id); + } else { + // Add the row to the group if the group didn't contain the row + if is_not_contained { + let row_pb = RowPB::from(row_rev); + changeset.inserted_rows.push(InsertedRowPB::new(row_pb.clone())); + group.add_row(row_pb); + } } - } else if is_contained { - changeset.deleted_rows.push(row_rev.id.clone()); - group.remove_row(&row_rev.id); } + + if group.id == UNCHECK { + if cell_data.is_check() { + // Remove the row if the group.id is UNCHECK but the cell_data is CHECK + changeset.deleted_rows.push(row_rev.id.clone()); + group.remove_row(&row_rev.id); + } else { + // Add the row to the group if the group didn't contain the row + if is_not_contained { + let row_pb = RowPB::from(row_rev); + changeset.inserted_rows.push(InsertedRowPB::new(row_pb.clone())); + group.add_row(row_pb); + } + } + } + if !changeset.is_empty() { changesets.push(changeset); }