From bfebea7b31d2b1ccaaae8b5e4cf7d2acee249164 Mon Sep 17 00:00:00 2001 From: appflowy Date: Mon, 5 Sep 2022 20:24:33 +0800 Subject: [PATCH] fix: add new created row --- .../presentation/card/board_text_cell.dart | 1 - .../flowy-grid/src/services/block_manager.rs | 2 +- .../src/services/grid_view_editor.rs | 2 ++ .../src/services/group/controller.rs | 1 + .../controller_impls/checkbox_controller.rs | 18 +++++++++++------- .../controller_impls/default_controller.rs | 2 ++ .../multi_select_controller.rs | 8 +++++++- .../single_select_controller.rs | 6 +++++- 8 files changed, 29 insertions(+), 11 deletions(-) diff --git a/frontend/app_flowy/lib/plugins/board/presentation/card/board_text_cell.dart b/frontend/app_flowy/lib/plugins/board/presentation/card/board_text_cell.dart index 02ab521222..99be8cdb3d 100644 --- a/frontend/app_flowy/lib/plugins/board/presentation/card/board_text_cell.dart +++ b/frontend/app_flowy/lib/plugins/board/presentation/card/board_text_cell.dart @@ -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'; diff --git a/frontend/rust-lib/flowy-grid/src/services/block_manager.rs b/frontend/rust-lib/flowy-grid/src/services/block_manager.rs index 9619bf52ab..800348fb97 100644 --- a/frontend/rust-lib/flowy-grid/src/services/block_manager.rs +++ b/frontend/rust-lib/flowy-grid/src/services/block_manager.rs @@ -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]); diff --git a/frontend/rust-lib/flowy-grid/src/services/grid_view_editor.rs b/frontend/rust-lib/flowy-grid/src/services/grid_view_editor.rs index ab8e8bd41f..30ff689027 100644 --- a/frontend/rust-lib/flowy-grid/src/services/grid_view_editor.rs +++ b/frontend/rust-lib/flowy-grid/src/services/grid_view_editor.rs @@ -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, 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 5825596aaa..75bc16f3b2 100644 --- a/frontend/rust-lib/flowy-grid/src/services/group/controller.rs +++ b/frontend/rust-lib/flowy-grid/src/services/group/controller.rs @@ -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 { 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 3f7943239e..c95a6e4af2 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 @@ -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 { @@ -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(); diff --git a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/default_controller.rs b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/default_controller.rs index 938bdd127e..2489df8af2 100644 --- a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/default_controller.rs +++ b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/default_controller.rs @@ -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) {} } diff --git a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/multi_select_controller.rs b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/multi_select_controller.rs index 2d8139bc73..8d18fa2a83 100644 --- a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/multi_select_controller.rs +++ b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/multi_select_controller.rs @@ -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(); diff --git a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/single_select_controller.rs b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/single_select_controller.rs index 5d2ddb9bd9..25da9eec17 100644 --- a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/single_select_controller.rs +++ b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/single_select_controller.rs @@ -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();