chore: remove unuse code

This commit is contained in:
nathan 2022-10-11 01:04:13 +08:00
parent 1f94d9d496
commit b8895ce787
6 changed files with 66 additions and 53 deletions

View File

@ -335,38 +335,52 @@ pub(crate) async fn update_select_option_handler(
let changeset: SelectOptionChangeset = data.into_inner().try_into()?;
let editor = manager.get_grid_editor(&changeset.cell_identifier.grid_id)?;
if let Some(mut field_rev) = editor.get_field_rev(&changeset.cell_identifier.field_id).await {
let mut_field_rev = Arc::make_mut(&mut field_rev);
let mut type_option = select_option_operation(mut_field_rev)?;
let mut cell_content_changeset = None;
let _ = editor
.modify_field_rev(&changeset.cell_identifier.field_id, |field_rev| {
let mut type_option = select_option_operation(field_rev)?;
let mut cell_content_changeset = None;
let mut is_changed = None;
if let Some(option) = changeset.insert_option {
cell_content_changeset = Some(SelectOptionCellChangeset::from_insert(&option.id).to_str());
type_option.insert_option(option);
}
if let Some(option) = changeset.insert_option {
cell_content_changeset = Some(SelectOptionCellChangeset::from_insert(&option.id).to_str());
type_option.insert_option(option);
is_changed = Some(());
}
if let Some(option) = changeset.update_option {
type_option.insert_option(option);
}
if let Some(option) = changeset.update_option {
type_option.insert_option(option);
is_changed = Some(());
}
if let Some(option) = changeset.delete_option {
cell_content_changeset = Some(SelectOptionCellChangeset::from_delete(&option.id).to_str());
type_option.delete_option(option);
}
if let Some(option) = changeset.delete_option {
cell_content_changeset = Some(SelectOptionCellChangeset::from_delete(&option.id).to_str());
type_option.delete_option(option);
is_changed = Some(());
}
mut_field_rev.insert_type_option(&*type_option);
let _ = editor.replace_field(field_rev).await?;
if is_changed.is_some() {
field_rev.insert_type_option(&*type_option);
}
if let Some(cell_content_changeset) = cell_content_changeset {
let changeset = CellChangesetPB {
grid_id: changeset.cell_identifier.grid_id,
row_id: changeset.cell_identifier.row_id,
field_id: changeset.cell_identifier.field_id.clone(),
content: cell_content_changeset,
};
let cloned_editor = editor.clone();
tokio::spawn(async move {
match cloned_editor.update_cell(changeset).await {
Ok(_) => {}
Err(_) => {}
}
});
}
Ok(is_changed)
})
.await?;
if let Some(cell_content_changeset) = cell_content_changeset {
let changeset = CellChangesetPB {
grid_id: changeset.cell_identifier.grid_id,
row_id: changeset.cell_identifier.row_id,
field_id: changeset.cell_identifier.field_id,
content: cell_content_changeset,
};
let _ = editor.update_cell(changeset).await?;
}
}
Ok(())
}

View File

@ -16,7 +16,7 @@ use flowy_grid_data_model::revision::*;
use flowy_revision::{RevisionCloudService, RevisionCompactor, RevisionManager, RevisionObjectBuilder};
use flowy_sync::client_grid::{GridRevisionChangeset, GridRevisionPad, JsonDeserializer};
use flowy_sync::entities::revision::Revision;
use flowy_sync::errors::CollaborateResult;
use flowy_sync::errors::{CollaborateError, CollaborateResult};
use flowy_sync::util::make_operations_from_revisions;
use lib_infra::future::{wrap_future, FutureResult};
@ -157,18 +157,28 @@ impl GridRevisionEditor {
}
}
// Replaces the field revision with new field revision.
pub async fn replace_field(&self, field_rev: Arc<FieldRevision>) -> FlowyResult<()> {
let field_id = field_rev.id.clone();
pub async fn modify_field_rev<F>(&self, field_id: &str, f: F) -> FlowyResult<()>
where
F: for<'a> FnOnce(&'a mut FieldRevision) -> FlowyResult<Option<()>>,
{
let mut is_changed = false;
let _ = self
.modify(|grid_pad| Ok(grid_pad.replace_field_rev(field_rev.clone())?))
.modify(|grid| {
let changeset = grid.modify_field(field_id, |field_rev| {
Ok(f(field_rev).map_err(|e| CollaborateError::internal().context(e))?)
})?;
is_changed = changeset.is_some();
Ok(changeset)
})
.await?;
match self.view_manager.did_update_view_field(&field_rev.id).await {
Ok(_) => {}
Err(e) => tracing::error!("View manager update field failed: {:?}", e),
if is_changed {
match self.view_manager.did_update_view_field_type_option(field_id).await {
Ok(_) => {}
Err(e) => tracing::error!("View manager update field failed: {:?}", e),
}
let _ = self.notify_did_update_grid_field(field_id).await?;
}
let _ = self.notify_did_update_grid_field(&field_id).await?;
Ok(())
}

View File

@ -283,15 +283,8 @@ impl GridViewRevisionEditor {
.await
}
#[tracing::instrument(level = "trace", skip_all, err)]
pub(crate) async fn did_update_view_field(&self, field_id: &str) -> FlowyResult<()> {
if let Some(field_rev) = self.field_delegate.get_field_rev(field_id).await {
match self.group_controller.write().await.did_update_group_field(&field_rev)? {
None => {}
Some(changeset) => {
self.notify_did_update_view(changeset).await;
}
}
}
pub(crate) async fn did_update_view_field(&self, _field_id: &str) -> FlowyResult<()> {
// Do nothing
Ok(())
}

View File

@ -179,8 +179,7 @@ impl GridViewManager {
#[tracing::instrument(level = "trace", skip(self), err)]
pub(crate) async fn did_update_view_field(&self, field_id: &str) -> FlowyResult<()> {
let view_editor = self.get_default_view_editor().await?;
// Only the field_id of the updated field is equal to the field_id of the group.
// Update the group
// Update the group if the group_id equal to the field_id
if view_editor.group_id().await != field_id {
return Ok(());
}

View File

@ -172,7 +172,7 @@ where
/// [GroupConfigurationRevision] as old groups. The old groups and the new groups will be merged
/// while keeping the order of the old groups.
///
#[tracing::instrument(level = "debug", skip(self, generated_group_configs), err)]
#[tracing::instrument(level = "trace", skip(self, generated_group_configs), err)]
pub(crate) fn init_groups(
&mut self,
generated_group_configs: Vec<GeneratedGroupConfig>,

View File

@ -319,11 +319,8 @@ where
}
}
fn did_update_group_field(&mut self, field_rev: &FieldRevision) -> FlowyResult<Option<GroupViewChangesetPB>> {
let type_option = field_rev.get_type_option::<T>(field_rev.ty);
let groups = G::generate_groups(&field_rev.id, &self.group_ctx, &type_option);
let changeset = self.group_ctx.init_groups(groups)?;
Ok(changeset)
fn did_update_group_field(&mut self, _field_rev: &FieldRevision) -> FlowyResult<Option<GroupViewChangesetPB>> {
Ok(None)
}
}