From f5f3f51cca280cd330482a4585a62897657b0371 Mon Sep 17 00:00:00 2001 From: appflowy Date: Tue, 23 Aug 2022 20:36:28 +0800 Subject: [PATCH] chore: update column name when field was changed --- .../app_flowy/lib/plugins/board/board.dart | 2 +- .../group_entities/group_changeset.rs | 25 ++++++++++++++----- .../src/services/grid_view_editor.rs | 23 +++++++++++------ .../src/services/grid_view_manager.rs | 6 +++++ .../flowy-grid/src/services/group/action.rs | 12 +++------ .../src/services/group/controller.rs | 20 +++++++++------ .../controller_impls/checkbox_controller.rs | 16 +++--------- .../multi_select_controller.rs | 16 +++--------- .../single_select_controller.rs | 16 +++--------- .../select_option_controller/util.rs | 20 +++++++-------- .../src/services/group/group_service.rs | 15 ++++++++--- 11 files changed, 91 insertions(+), 80 deletions(-) diff --git a/frontend/app_flowy/lib/plugins/board/board.dart b/frontend/app_flowy/lib/plugins/board/board.dart index c55d7f2e17..213cc8bc3c 100644 --- a/frontend/app_flowy/lib/plugins/board/board.dart +++ b/frontend/app_flowy/lib/plugins/board/board.dart @@ -31,7 +31,7 @@ class BoardPluginBuilder implements PluginBuilder { class BoardPluginConfig implements PluginConfig { @override - bool get creatable => false; + bool get creatable => true; } class BoardPlugin extends Plugin { diff --git a/frontend/rust-lib/flowy-grid/src/entities/group_entities/group_changeset.rs b/frontend/rust-lib/flowy-grid/src/entities/group_entities/group_changeset.rs index a3ebee9cb7..b7fdda8b3d 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/group_entities/group_changeset.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/group_entities/group_changeset.rs @@ -1,25 +1,29 @@ use crate::entities::{GroupPB, InsertedRowPB, RowPB}; +use diesel::insertable::ColumnInsertValue::Default; use flowy_derive::ProtoBuf; use flowy_error::ErrorCode; use flowy_grid_data_model::parser::NotEmptyStr; use std::fmt::Formatter; #[derive(Debug, Default, ProtoBuf)] -pub struct GroupRowsChangesetPB { +pub struct GroupChangesetPB { #[pb(index = 1)] pub group_id: String, - #[pb(index = 2)] - pub inserted_rows: Vec, + #[pb(index = 2, one_of)] + pub group_name: Option, #[pb(index = 3)] - pub deleted_rows: Vec, + pub inserted_rows: Vec, #[pb(index = 4)] + pub deleted_rows: Vec, + + #[pb(index = 5)] pub updated_rows: Vec, } -impl std::fmt::Display for GroupRowsChangesetPB { +impl std::fmt::Display for GroupChangesetPB { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { for inserted_row in &self.inserted_rows { let _ = f.write_fmt(format_args!( @@ -36,10 +40,19 @@ impl std::fmt::Display for GroupRowsChangesetPB { } } -impl GroupRowsChangesetPB { +impl GroupChangesetPB { pub fn is_empty(&self) -> bool { self.inserted_rows.is_empty() && self.deleted_rows.is_empty() && self.updated_rows.is_empty() } + + pub fn name(group_id: String, name: &str) -> Self { + Self { + group_id, + group_name: Some(name.to_owned()), + ..Default::default() + } + } + pub fn insert(group_id: String, inserted_rows: Vec) -> Self { Self { group_id, 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 4e23d9be19..015756954b 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 @@ -1,8 +1,8 @@ use crate::dart_notification::{send_dart_notification, GridNotification}; use crate::entities::{ CreateFilterParams, CreateRowParams, DeleteFilterParams, GridFilterConfiguration, GridLayout, GridLayoutPB, - GridSettingPB, GroupPB, GroupRowsChangesetPB, GroupViewChangesetPB, InsertedGroupPB, InsertedRowPB, - MoveGroupParams, RepeatedGridConfigurationFilterPB, RepeatedGridGroupConfigurationPB, RowPB, + GridSettingPB, GroupChangesetPB, GroupPB, GroupViewChangesetPB, InsertedGroupPB, InsertedRowPB, MoveGroupParams, + RepeatedGridConfigurationFilterPB, RepeatedGridGroupConfigurationPB, RowPB, }; use crate::services::grid_editor_task::GridServiceTaskScheduler; use crate::services::grid_view_manager::{GridViewFieldDelegate, GridViewRowDelegate}; @@ -99,8 +99,8 @@ impl GridViewRevisionEditor { row: row_pb.clone(), index: None, }; - let changeset = GroupRowsChangesetPB::insert(group_id.clone(), vec![inserted_row]); - self.notify_did_update_group_rows(changeset).await; + let changeset = GroupChangesetPB::insert(group_id.clone(), vec![inserted_row]); + self.notify_did_update_group(changeset).await; } } } @@ -115,7 +115,7 @@ impl GridViewRevisionEditor { .await { for changeset in changesets { - self.notify_did_update_group_rows(changeset).await; + self.notify_did_update_group(changeset).await; } } } @@ -129,7 +129,7 @@ impl GridViewRevisionEditor { .await { for changeset in changesets { - self.notify_did_update_group_rows(changeset).await; + self.notify_did_update_group(changeset).await; } } } @@ -151,7 +151,7 @@ impl GridViewRevisionEditor { .await { for changeset in changesets { - self.notify_did_update_group_rows(changeset).await; + self.notify_did_update_group(changeset).await; } } } @@ -253,7 +253,14 @@ impl GridViewRevisionEditor { .await } - async fn notify_did_update_group_rows(&self, changeset: GroupRowsChangesetPB) { + pub(crate) async fn did_update_field(&self, field_id: &str) -> FlowyResult<()> { + if let Some(field_rev) = self.field_delegate.get_field_rev(&field_id).await { + let _ = self.group_service.write().await.did_update_field(&field_rev).await?; + } + Ok(()) + } + + async fn notify_did_update_group(&self, changeset: GroupChangesetPB) { send_dart_notification(&changeset.group_id, GridNotification::DidUpdateGroup) .payload(changeset) .send(); diff --git a/frontend/rust-lib/flowy-grid/src/services/grid_view_manager.rs b/frontend/rust-lib/flowy-grid/src/services/grid_view_manager.rs index b0e578f804..b93ac2871f 100644 --- a/frontend/rust-lib/flowy-grid/src/services/grid_view_manager.rs +++ b/frontend/rust-lib/flowy-grid/src/services/grid_view_manager.rs @@ -149,6 +149,12 @@ impl GridViewManager { } } + pub(crate) async fn did_update_field(&self, field_id: &str) -> FlowyResult<()> { + let view_editor = self.get_default_view_editor().await?; + let _ = view_editor.did_update_field(field_id).await?; + Ok(()) + } + pub(crate) async fn get_view_editor(&self, view_id: &str) -> FlowyResult> { debug_assert!(!view_id.is_empty()); match self.view_editors.get(view_id) { diff --git a/frontend/rust-lib/flowy-grid/src/services/group/action.rs b/frontend/rust-lib/flowy-grid/src/services/group/action.rs index 29dc51cc37..d19be8395e 100644 --- a/frontend/rust-lib/flowy-grid/src/services/group/action.rs +++ b/frontend/rust-lib/flowy-grid/src/services/group/action.rs @@ -1,4 +1,4 @@ -use crate::entities::GroupRowsChangesetPB; +use crate::entities::GroupChangesetPB; use crate::services::group::controller::MoveGroupRowContext; use flowy_grid_data_model::revision::RowRevision; @@ -6,12 +6,8 @@ use flowy_grid_data_model::revision::RowRevision; pub trait GroupAction: Send + Sync { type CellDataType; fn can_group(&self, content: &str, cell_data: &Self::CellDataType) -> bool; - fn add_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec; - fn remove_row_if_match( - &mut self, - row_rev: &RowRevision, - cell_data: &Self::CellDataType, - ) -> Vec; + fn add_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec; + fn remove_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec; - fn move_row(&mut self, cell_data: &Self::CellDataType, context: MoveGroupRowContext) -> Vec; + fn move_row(&mut self, cell_data: &Self::CellDataType, context: MoveGroupRowContext) -> Vec; } 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 1a5ee23694..7cf7897dfc 100644 --- a/frontend/rust-lib/flowy-grid/src/services/group/controller.rs +++ b/frontend/rust-lib/flowy-grid/src/services/group/controller.rs @@ -1,4 +1,4 @@ -use crate::entities::{GroupRowsChangesetPB, RowPB}; +use crate::entities::{GroupChangesetPB, RowPB}; use crate::services::cell::{decode_any_cell_data, CellBytesParser}; use crate::services::group::action::GroupAction; use crate::services::group::configuration::GenericGroupConfiguration; @@ -51,15 +51,17 @@ pub trait GroupControllerSharedOperation: Send + Sync { &mut self, row_rev: &RowRevision, field_rev: &FieldRevision, - ) -> FlowyResult>; + ) -> FlowyResult>; fn did_delete_row( &mut self, row_rev: &RowRevision, field_rev: &FieldRevision, - ) -> FlowyResult>; + ) -> FlowyResult>; - fn move_group_row(&mut self, context: MoveGroupRowContext) -> FlowyResult>; + fn move_group_row(&mut self, context: MoveGroupRowContext) -> FlowyResult>; + + fn did_update_field(&mut self, field_rev: &FieldRevision) -> FlowyResult<()>; } /// C: represents the group configuration that impl [GroupConfigurationSerde] @@ -173,7 +175,7 @@ where &mut self, row_rev: &RowRevision, field_rev: &FieldRevision, - ) -> FlowyResult> { + ) -> FlowyResult> { if let Some(cell_rev) = row_rev.cells.get(&self.field_id) { let cell_bytes = decode_any_cell_data(cell_rev.data.clone(), field_rev); let cell_data = cell_bytes.parser::

()?; @@ -187,7 +189,7 @@ where &mut self, row_rev: &RowRevision, field_rev: &FieldRevision, - ) -> FlowyResult> { + ) -> FlowyResult> { if let Some(cell_rev) = row_rev.cells.get(&self.field_id) { let cell_bytes = decode_any_cell_data(cell_rev.data.clone(), field_rev); let cell_data = cell_bytes.parser::

()?; @@ -197,7 +199,7 @@ where } } - fn move_group_row(&mut self, context: MoveGroupRowContext) -> FlowyResult> { + fn move_group_row(&mut self, context: MoveGroupRowContext) -> FlowyResult> { if let Some(cell_rev) = context.row_rev.cells.get(&self.field_id) { let cell_bytes = decode_any_cell_data(cell_rev.data.clone(), context.field_rev); let cell_data = cell_bytes.parser::

()?; @@ -206,6 +208,10 @@ where Ok(vec![]) } } + + fn did_update_field(&mut self, field_rev: &FieldRevision) -> FlowyResult<()> { + todo!() + } } struct GroupRow { 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 ffcbf117fe..4c06ba63ce 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 @@ -1,4 +1,4 @@ -use crate::entities::GroupRowsChangesetPB; +use crate::entities::GroupChangesetPB; use crate::services::field::{CheckboxCellData, CheckboxCellDataParser, CheckboxTypeOptionPB, CHECK, UNCHECK}; use crate::services::group::action::GroupAction; use crate::services::group::configuration::GenericGroupConfiguration; @@ -24,11 +24,7 @@ impl GroupAction for CheckboxGroupController { false } - fn add_row_if_match( - &mut self, - _row_rev: &RowRevision, - _cell_data: &Self::CellDataType, - ) -> Vec { + fn add_row_if_match(&mut self, _row_rev: &RowRevision, _cell_data: &Self::CellDataType) -> Vec { todo!() } @@ -36,15 +32,11 @@ impl GroupAction for CheckboxGroupController { &mut self, _row_rev: &RowRevision, _cell_data: &Self::CellDataType, - ) -> Vec { + ) -> Vec { todo!() } - fn move_row( - &mut self, - _cell_data: &Self::CellDataType, - _context: MoveGroupRowContext, - ) -> Vec { + fn move_row(&mut self, _cell_data: &Self::CellDataType, _context: MoveGroupRowContext) -> Vec { todo!() } } 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 cce2698158..0c1a7117d4 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::GroupRowsChangesetPB; +use crate::entities::GroupChangesetPB; use crate::services::cell::insert_select_option_cell; use crate::services::field::{MultiSelectTypeOptionPB, SelectOptionCellDataPB, SelectOptionCellDataParser}; use crate::services::group::action::GroupAction; @@ -25,7 +25,7 @@ impl GroupAction for MultiSelectGroupController { cell_data.select_options.iter().any(|option| option.id == content) } - fn add_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec { + fn add_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec { let mut changesets = vec![]; self.configuration.with_mut_groups(|group| { add_row(group, &mut changesets, cell_data, row_rev); @@ -33,11 +33,7 @@ impl GroupAction for MultiSelectGroupController { changesets } - fn remove_row_if_match( - &mut self, - row_rev: &RowRevision, - cell_data: &Self::CellDataType, - ) -> Vec { + fn remove_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec { let mut changesets = vec![]; self.configuration.with_mut_groups(|group| { remove_row(group, &mut changesets, cell_data, row_rev); @@ -45,11 +41,7 @@ impl GroupAction for MultiSelectGroupController { changesets } - fn move_row( - &mut self, - cell_data: &Self::CellDataType, - mut context: MoveGroupRowContext, - ) -> Vec { + fn move_row(&mut self, cell_data: &Self::CellDataType, mut context: MoveGroupRowContext) -> Vec { let mut group_changeset = vec![]; self.configuration.with_mut_groups(|group| { move_select_option_row(group, &mut group_changeset, cell_data, &mut context); 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 d48cdd8ee7..ad4d296fab 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 @@ -1,4 +1,4 @@ -use crate::entities::{GroupRowsChangesetPB, RowPB}; +use crate::entities::{GroupChangesetPB, RowPB}; use crate::services::cell::insert_select_option_cell; use crate::services::field::{SelectOptionCellDataPB, SelectOptionCellDataParser, SingleSelectTypeOptionPB}; use crate::services::group::action::GroupAction; @@ -25,7 +25,7 @@ impl GroupAction for SingleSelectGroupController { cell_data.select_options.iter().any(|option| option.id == content) } - fn add_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec { + fn add_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec { let mut changesets = vec![]; self.configuration.with_mut_groups(|group| { add_row(group, &mut changesets, cell_data, row_rev); @@ -33,11 +33,7 @@ impl GroupAction for SingleSelectGroupController { changesets } - fn remove_row_if_match( - &mut self, - row_rev: &RowRevision, - cell_data: &Self::CellDataType, - ) -> Vec { + fn remove_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec { let mut changesets = vec![]; self.configuration.with_mut_groups(|group| { remove_row(group, &mut changesets, cell_data, row_rev); @@ -45,11 +41,7 @@ impl GroupAction for SingleSelectGroupController { changesets } - fn move_row( - &mut self, - cell_data: &Self::CellDataType, - mut context: MoveGroupRowContext, - ) -> Vec { + fn move_row(&mut self, cell_data: &Self::CellDataType, mut context: MoveGroupRowContext) -> Vec { let mut group_changeset = vec![]; self.configuration.with_mut_groups(|group| { move_select_option_row(group, &mut group_changeset, cell_data, &mut context); diff --git a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/util.rs b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/util.rs index bdca688531..9a1658c19f 100644 --- a/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/util.rs +++ b/frontend/rust-lib/flowy-grid/src/services/group/controller_impls/select_option_controller/util.rs @@ -1,4 +1,4 @@ -use crate::entities::{GroupRowsChangesetPB, InsertedRowPB, RowPB}; +use crate::entities::{GroupChangesetPB, InsertedRowPB, RowPB}; use crate::services::cell::insert_select_option_cell; use crate::services::field::SelectOptionCellDataPB; use crate::services::group::configuration::GenericGroupConfiguration; @@ -11,7 +11,7 @@ pub type SelectOptionGroupConfiguration = GenericGroupConfiguration, + changesets: &mut Vec, cell_data: &SelectOptionCellDataPB, row_rev: &RowRevision, ) { @@ -19,14 +19,14 @@ pub fn add_row( if option.id == group.id { if !group.contains_row(&row_rev.id) { let row_pb = RowPB::from(row_rev); - changesets.push(GroupRowsChangesetPB::insert( + changesets.push(GroupChangesetPB::insert( group.id.clone(), vec![InsertedRowPB::new(row_pb.clone())], )); group.add_row(row_pb); } } else if group.contains_row(&row_rev.id) { - changesets.push(GroupRowsChangesetPB::delete(group.id.clone(), vec![row_rev.id.clone()])); + changesets.push(GroupChangesetPB::delete(group.id.clone(), vec![row_rev.id.clone()])); group.remove_row(&row_rev.id); } }); @@ -34,13 +34,13 @@ pub fn add_row( pub fn remove_row( group: &mut Group, - changesets: &mut Vec, + changesets: &mut Vec, cell_data: &SelectOptionCellDataPB, row_rev: &RowRevision, ) { cell_data.select_options.iter().for_each(|option| { if option.id == group.id && group.contains_row(&row_rev.id) { - changesets.push(GroupRowsChangesetPB::delete(group.id.clone(), vec![row_rev.id.clone()])); + changesets.push(GroupChangesetPB::delete(group.id.clone(), vec![row_rev.id.clone()])); group.remove_row(&row_rev.id); } }); @@ -48,7 +48,7 @@ pub fn remove_row( pub fn move_select_option_row( group: &mut Group, - group_changeset: &mut Vec, + group_changeset: &mut Vec, _cell_data: &SelectOptionCellDataPB, context: &mut MoveGroupRowContext, ) { @@ -68,7 +68,7 @@ pub fn move_select_option_row( // Remove the row in which group contains it if from_index.is_some() { - group_changeset.push(GroupRowsChangesetPB::delete(group.id.clone(), vec![row_rev.id.clone()])); + group_changeset.push(GroupChangesetPB::delete(group.id.clone(), vec![row_rev.id.clone()])); tracing::debug!("Group:{} remove row:{}", group.id, row_rev.id); group.remove_row(&row_rev.id); } @@ -78,7 +78,7 @@ pub fn move_select_option_row( let mut inserted_row = InsertedRowPB::new(row_pb.clone()); match to_index { None => { - group_changeset.push(GroupRowsChangesetPB::insert(group.id.clone(), vec![inserted_row])); + group_changeset.push(GroupChangesetPB::insert(group.id.clone(), vec![inserted_row])); tracing::debug!("Group:{} append row:{}", group.id, row_rev.id); group.add_row(row_pb); } @@ -91,7 +91,7 @@ pub fn move_select_option_row( tracing::debug!("Group:{} append row:{}", group.id, row_rev.id); group.add_row(row_pb); } - group_changeset.push(GroupRowsChangesetPB::insert(group.id.clone(), vec![inserted_row])); + group_changeset.push(GroupChangesetPB::insert(group.id.clone(), vec![inserted_row])); } } diff --git a/frontend/rust-lib/flowy-grid/src/services/group/group_service.rs b/frontend/rust-lib/flowy-grid/src/services/group/group_service.rs index 6afec9dd82..a6ae504c05 100644 --- a/frontend/rust-lib/flowy-grid/src/services/group/group_service.rs +++ b/frontend/rust-lib/flowy-grid/src/services/group/group_service.rs @@ -1,4 +1,4 @@ -use crate::entities::{FieldType, GroupRowsChangesetPB}; +use crate::entities::{FieldType, GroupChangesetPB}; use crate::services::group::configuration::GroupConfigurationReader; use crate::services::group::controller::{GroupController, MoveGroupRowContext}; use crate::services::group::{ @@ -86,7 +86,7 @@ impl GroupService { &mut self, row_rev: &RowRevision, get_field_fn: F, - ) -> Option> + ) -> Option> where F: FnOnce(String) -> O, O: Future>> + Send + Sync + 'static, @@ -111,7 +111,7 @@ impl GroupService { to_group_id: &str, to_row_id: Option, get_field_fn: F, - ) -> Option> + ) -> Option> where F: FnOnce(String) -> O, O: Future>> + Send + Sync + 'static, @@ -141,7 +141,7 @@ impl GroupService { &mut self, row_rev: &RowRevision, get_field_fn: F, - ) -> Option> + ) -> Option> where F: FnOnce(String) -> O, O: Future>> + Send + Sync + 'static, @@ -170,6 +170,13 @@ impl GroupService { } } + pub(crate) async fn did_update_field(&mut self, field_rev: &FieldRevision) -> FlowyResult<()> { + match self.group_controller.as_mut() { + None => Ok(()), + Some(group_controller) => group_controller.did_update_field(field_rev), + } + } + #[tracing::instrument(level = "trace", skip(self, field_rev), err)] async fn make_group_controller( &self,