mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: notify all views of field type option (#4229)
This commit is contained in:
parent
2ca911950c
commit
54fcc4ac5b
@ -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?;
|
||||
},
|
||||
_ => {
|
||||
|
@ -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 cell
|
||||
self
|
||||
.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(())
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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>;
|
||||
|
@ -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<TypeOptionDat
|
||||
action(&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
|
||||
}
|
||||
|
@ -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();
|
||||
},
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user