fix: row disappear when update the row in checkbox board (#1266)

This commit is contained in:
Nathan.fooo 2022-10-12 10:20:26 +08:00 committed by GitHub
parent 1adf6530fe
commit a516ec82bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 13 deletions

View File

@ -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 {

View File

@ -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::<P>()?;
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![])

View File

@ -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);
}