Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: notify all views of field type option (#4229)
Richard Shiue54fcc4ac5b5b
diff --git a/frontend/rust-lib/flowy-database2/src/event_handler.rs b/frontend/rust-lib/flowy-database2/src/event_handler.rsindex ad855390b0..eb447fc29e 100644--- a/frontend/rust-lib/flowy-database2/src/event_handler.rs+++ b/frontend/rust-lib/flowy-database2/src/event_handler.rs@@ -219,12 +219,7 @@ pub(crate) async fn update_field_type_option_handler(let field_type = FieldType::from(old_field.field_type);let type_option_data = type_option_data_from_pb(params.type_option_data, &field_type)?;database_editor- .update_field_type_option(- ¶ms.view_id,- ¶ms.field_id,- type_option_data,- old_field,- )+ .update_field_type_option(¶ms.field_id, type_option_data, old_field).await?;}Ok(())@@ -262,12 +257,7 @@ pub(crate) async fn switch_to_field_handler(match (old_field, new_type_option) {(Some(old_field), Some(new_type_option)) => {database_editor- .update_field_type_option(- ¶ms.view_id,- ¶ms.field_id,- new_type_option,- old_field,- )+ .update_field_type_option(¶ms.field_id, new_type_option, old_field).await?;},_ => {diff --git a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rsindex 9ca7389c25..edefb9206b 100644--- a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs+++ b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs@@ -317,13 +317,12 @@ impl DatabaseEditor {/// Do nothing if the [TypeOptionData] is empty.pub async fn update_field_type_option(&self,- view_id: &str,_field_id: &str,type_option_data: TypeOptionData,old_field: Field,) -> FlowyResult<()> {- let view_editor = self.database_views.get_view_editor(view_id).await?;- update_field_type_option_fn(&self.database, &view_editor, type_option_data, old_field).await?;+ let view_editors = self.database_views.editors().await;+ update_field_type_option_fn(&self.database, &view_editors, type_option_data, old_field).await?;Ok(())}@@ -808,9 +807,15 @@ impl DatabaseEditor {.for_each(|option| type_option.insert_option(option.into()));// Update the field's type option- self- .update_field_type_option(view_id, field_id, type_option.to_type_option_data(), field)- .await?;+ let view_editors = self.database_views.editors().await;+ update_field_type_option_fn(+ &self.database,+ &view_editors,+ type_option.to_type_option_data(),+ field.clone(),+ )+ .await?;+// Insert the options into the cellself.update_cell_with_changeset(view_id, row_id, field_id, cell_changeset)@@ -842,10 +847,10 @@ impl DatabaseEditor {type_option.delete_option(&option.id);}- let view_editor = self.database_views.get_view_editor(view_id).await?;+ let view_editors = self.database_views.editors().await;update_field_type_option_fn(&self.database,- &view_editor,+ &view_editors,type_option.to_type_option_data(),field.clone(),)@@ -1290,22 +1295,23 @@ impl DatabaseViewOperation for DatabaseViewOperationImpl {fn update_field(&self,- view_id: &str,type_option_data: TypeOptionData,old_field: Field,) -> FutureResult<(), FlowyError> {- let view_id = view_id.to_string();let weak_editor_by_view_id = Arc::downgrade(&self.editor_by_view_id);let weak_database = Arc::downgrade(&self.database);FutureResult::new(async move {if let (Some(database), Some(editor_by_view_id)) =(weak_database.upgrade(), weak_editor_by_view_id.upgrade()){- let view_editor = editor_by_view_id.read().await.get(&view_id).cloned();- if let Some(view_editor) = view_editor {- let _ =- update_field_type_option_fn(&database, &view_editor, type_option_data, old_field).await;- }+ let view_editors = editor_by_view_id+ .read()+ .await+ .values()+ .map(|editor| editor.clone())+ .collect();+ let _ =+ update_field_type_option_fn(&database, &view_editors, type_option_data, old_field).await;}Ok(())})@@ -1573,7 +1579,7 @@ impl DatabaseViewOperation for DatabaseViewOperationImpl {#[tracing::instrument(level = "trace", skip_all, err)]pub async fn update_field_type_option_fn(database: &Arc<MutexDatabase>,- view_editor: &Arc<DatabaseViewEditor>,+ view_editors: &Vec<Arc<DatabaseViewEditor>>,type_option_data: TypeOptionData,old_field: Field,) -> FlowyResult<()> {@@ -1601,9 +1607,12 @@ pub async fn update_field_type_option_fn(});let _ = notify_did_update_database_field(database, &old_field.id);- view_editor- .v_did_update_field_type_option(&old_field)- .await?;+ for view_editor in view_editors {+ view_editor+ .v_did_update_field_type_option(&old_field)+ .await?;+ }+Ok(())}diff --git a/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs b/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rsindex 72953295bf..28a8ffb00c 100644--- a/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs+++ b/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs@@ -363,7 +363,7 @@ impl DatabaseViewEditor {if let (Some(type_option_data), Some(payload)) = result {self.delegate- .update_field(&self.view_id, type_option_data, old_field)+ .update_field(type_option_data, old_field).await?;let group_changes = GroupChangesPB {@@ -402,10 +402,7 @@ impl DatabaseViewEditor {changes.deleted_rows.extend(deleted_rows);if let Some(type_option) = type_option_data {- self- .delegate- .update_field(&self.view_id, type_option, field)- .await?;+ self.delegate.update_field(type_option, field).await?;}let notification = GroupChangesPB {view_id: self.view_id.clone(),@@ -436,7 +433,7 @@ impl DatabaseViewEditor {if !type_option_data.is_empty() {self.delegate- .update_field(&self.view_id, type_option_data, old_field)+ .update_field(type_option_data, old_field).await?;}let notification = GroupChangesPB {diff --git a/frontend/rust-lib/flowy-database2/src/services/database_view/view_operation.rs b/frontend/rust-lib/flowy-database2/src/services/database_view/view_operation.rsindex a57f9f7459..46bb5d4cd7 100644--- a/frontend/rust-lib/flowy-database2/src/services/database_view/view_operation.rs+++ b/frontend/rust-lib/flowy-database2/src/services/database_view/view_operation.rs@@ -41,7 +41,6 @@ pub trait DatabaseViewOperation: Send + Sync + 'static {fn update_field(&self,- view_id: &str,type_option_data: TypeOptionData,old_field: Field,) -> FutureResult<(), FlowyError>;diff --git a/frontend/rust-lib/flowy-database2/src/services/field/field_operation.rs b/frontend/rust-lib/flowy-database2/src/services/field/field_operation.rsindex 1a5715163a..dd8812fbd6 100644--- a/frontend/rust-lib/flowy-database2/src/services/field/field_operation.rs+++ b/frontend/rust-lib/flowy-database2/src/services/field/field_operation.rs@@ -9,7 +9,6 @@ use crate::services::database::DatabaseEditor;use crate::services::field::{MultiSelectTypeOption, SingleSelectTypeOption};pub async fn edit_field_type_option<T: From<TypeOptionData> + Into<TypeOptionData>>(- view_id: &str,field_id: &str,editor: Arc<DatabaseEditor>,action: impl FnOnce(&mut T),@@ -25,7 +24,7 @@ pub async fn edit_field_type_option<T: From<TypeOptionData> + Into<TypeOptionDataction(&mut type_option);let type_option_data: TypeOptionData = type_option.into();editor- .update_field_type_option(view_id, field_id, type_option_data, old_field)+ .update_field_type_option(field_id, type_option_data, old_field).await?;}}@@ -34,19 +33,17 @@ pub async fn edit_field_type_option<T: From<TypeOptionData> + Into<TypeOptionDat}pub async fn edit_single_select_type_option(- view_id: &str,field_id: &str,editor: Arc<DatabaseEditor>,action: impl FnOnce(&mut SingleSelectTypeOption),) -> FlowyResult<()> {- edit_field_type_option(view_id, field_id, editor, action).await+ edit_field_type_option(field_id, editor, action).await}pub async fn edit_multi_select_type_option(- view_id: &str,field_id: &str,editor: Arc<DatabaseEditor>,action: impl FnOnce(&mut MultiSelectTypeOption),) -> FlowyResult<()> {- edit_field_type_option(view_id, field_id, editor, action).await+ edit_field_type_option(field_id, editor, action).await}diff --git a/frontend/rust-lib/flowy-database2/tests/database/field_test/script.rs b/frontend/rust-lib/flowy-database2/tests/database/field_test/script.rsindex e6e4de344e..3f4a1b26f9 100644--- a/frontend/rust-lib/flowy-database2/tests/database/field_test/script.rs+++ b/frontend/rust-lib/flowy-database2/tests/database/field_test/script.rs@@ -99,7 +99,7 @@ impl DatabaseFieldTest {let old_field = self.editor.get_field(&field_id).unwrap();self.editor- .update_field_type_option(&self.view_id, &field_id, type_option, old_field)+ .update_field_type_option(&field_id, type_option, old_field).await.unwrap();},diff --git a/frontend/rust-lib/flowy-database2/tests/database/group_test/script.rs b/frontend/rust-lib/flowy-database2/tests/database/group_test/script.rsindex 0b80be7994..2117a984c4 100644--- a/frontend/rust-lib/flowy-database2/tests/database/group_test/script.rs+++ b/frontend/rust-lib/flowy-database2/tests/database/group_test/script.rs@@ -306,14 +306,9 @@ impl DatabaseGroupTest {action: impl FnOnce(&mut SingleSelectTypeOption),) {let single_select = self.get_single_select_field().await;- edit_single_select_type_option(- &self.view_id,- &single_select.id,- self.editor.clone(),- action,- )- .await- .unwrap();+ edit_single_select_type_option(&single_select.id, self.editor.clone(), action)+ .await+ .unwrap();}pub async fn get_url_field(&self) -> Field {