Merge pull request #987 from AppFlowy-IO/feat/fix_delete_card_bugs

fix: add new created row
This commit is contained in:
Nathan.fooo 2022-09-05 21:17:06 +08:00 committed by GitHub
commit dbcddc464f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 29 additions and 11 deletions

View File

@ -4,7 +4,6 @@ import 'package:app_flowy/plugins/grid/presentation/widgets/cell/cell_builder.da
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'board_cell.dart';
import 'define.dart';

View File

@ -107,7 +107,7 @@ impl GridBlockManager {
let editor = self.get_editor_from_row_id(&changeset.row_id).await?;
let _ = editor.update_row(changeset.clone()).await?;
match editor.get_row_rev(&changeset.row_id).await? {
None => tracing::error!("Internal error: can't find the row with id: {}", changeset.row_id),
None => tracing::error!("Update row failed, can't find the row with id: {}", changeset.row_id),
Some(row_rev) => {
let row_pb = make_row_from_row_rev(row_rev.clone());
let block_order_changeset = GridBlockChangesetPB::update(&editor.block_id, vec![row_pb]);

View File

@ -96,6 +96,8 @@ impl GridViewRevisionEditor {
None => Some(0),
Some(_) => None,
};
self.group_controller.write().await.did_create_row(row_pb, group_id);
let inserted_row = InsertedRowPB {
row: row_pb.clone(),
index,

View File

@ -15,6 +15,7 @@ use std::sync::Arc;
// a new row.
pub trait GroupController: GroupControllerSharedOperation + Send + Sync {
fn will_create_row(&mut self, row_rev: &mut RowRevision, field_rev: &FieldRevision, group_id: &str);
fn did_create_row(&mut self, row_pb: &RowPB, group_id: &str);
}
pub trait GroupGenerator {

View File

@ -28,11 +28,11 @@ impl GroupAction for CheckboxGroupController {
}
fn can_group(&self, content: &str, cell_data: &Self::CellDataType) -> bool {
return if cell_data.is_check() {
if cell_data.is_check() {
content == CHECK
} else {
content == UNCHECK
};
}
}
fn add_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec<GroupChangesetPB> {
@ -46,11 +46,9 @@ impl GroupAction for CheckboxGroupController {
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);
}
} else if is_contained {
changeset.deleted_rows.push(row_rev.id.clone());
group.remove_row(&row_rev.id);
}
if !changeset.is_empty() {
changesets.push(changeset);
@ -97,6 +95,12 @@ impl GroupController for CheckboxGroupController {
}
}
}
fn did_create_row(&mut self, row_pb: &RowPB, group_id: &str) {
if let Some(group) = self.group_ctx.get_mut_group(group_id) {
group.add_row(row_pb.clone())
}
}
}
pub struct CheckboxGroupGenerator();

View File

@ -77,4 +77,6 @@ impl GroupControllerSharedOperation for DefaultGroupController {
impl GroupController for DefaultGroupController {
fn will_create_row(&mut self, _row_rev: &mut RowRevision, _field_rev: &FieldRevision, _group_id: &str) {}
fn did_create_row(&mut self, _row_rev: &RowPB, _group_id: &str) {}
}

View File

@ -1,4 +1,4 @@
use crate::entities::GroupChangesetPB;
use crate::entities::{GroupChangesetPB, RowPB};
use crate::services::cell::insert_select_option_cell;
use crate::services::field::{MultiSelectTypeOptionPB, SelectOptionCellDataPB, SelectOptionCellDataParser};
use crate::services::group::action::GroupAction;
@ -67,6 +67,12 @@ impl GroupController for MultiSelectGroupController {
}
}
}
fn did_create_row(&mut self, row_pb: &RowPB, group_id: &str) {
if let Some(group) = self.group_ctx.get_mut_group(group_id) {
group.add_row(row_pb.clone())
}
}
}
pub struct MultiSelectGroupGenerator();

View File

@ -65,10 +65,14 @@ impl GroupController for SingleSelectGroupController {
Some(group) => {
let cell_rev = insert_select_option_cell(group.id.clone(), field_rev);
row_rev.cells.insert(field_rev.id.clone(), cell_rev);
group.add_row(RowPB::from(row_rev));
}
}
}
fn did_create_row(&mut self, row_pb: &RowPB, group_id: &str) {
if let Some(group) = self.group_ctx.get_mut_group(group_id) {
group.add_row(row_pb.clone())
}
}
}
pub struct SingleSelectGroupGenerator();