fix: duplicate board

This commit is contained in:
nathan
2022-09-24 20:34:31 +08:00
parent fa0a485c85
commit e66b3b07db
13 changed files with 55 additions and 17 deletions

View File

@ -33,4 +33,3 @@ impl std::convert::From<GridNotification> for i32 {
pub fn send_dart_notification(id: &str, ty: GridNotification) -> DartNotifyBuilder {
DartNotifyBuilder::new(id, ty, OBSERVABLE_CATEGORY)
}

View File

@ -183,7 +183,14 @@ pub async fn make_grid_view_data(
grid_manager: Arc<GridManager>,
build_context: BuildGridContext,
) -> FlowyResult<Bytes> {
for block_meta_data in &build_context.blocks {
let BuildGridContext {
field_revs,
block_metas,
blocks,
grid_view_revision_data,
} = build_context;
for block_meta_data in &blocks {
let block_id = &block_meta_data.block_id;
// Indexing the block's rows
block_meta_data.rows.iter().for_each(|row| {
@ -200,7 +207,7 @@ pub async fn make_grid_view_data(
// Will replace the grid_id with the value returned by the gen_grid_id()
let grid_id = view_id.to_owned();
let grid_rev = GridRevision::from_build_context(&grid_id, build_context);
let grid_rev = GridRevision::from_build_context(&grid_id, field_revs, block_metas);
// Create grid
let grid_rev_delta = make_grid_delta(&grid_rev);
@ -210,7 +217,11 @@ pub async fn make_grid_view_data(
let _ = grid_manager.create_grid(&grid_id, repeated_revision).await?;
// Create grid view
let grid_view = GridViewRevision::new(grid_id, view_id.to_owned(), layout.into());
let grid_view = if grid_view_revision_data.is_empty() {
GridViewRevision::new(grid_id, view_id.to_owned(), layout.into())
} else {
GridViewRevision::from_json(grid_view_revision_data)?
};
let grid_view_delta = make_grid_view_delta(&grid_view);
let grid_view_delta_bytes = grid_view_delta.json_bytes();
let repeated_revision: RepeatedRevision =

View File

@ -673,6 +673,7 @@ impl GridRevisionEditor {
pub async fn duplicate_grid(&self) -> FlowyResult<BuildGridContext> {
let grid_pad = self.grid_pad.read().await;
let grid_view_revision_data = self.view_manager.duplicate_grid_view().await?;
let original_blocks = grid_pad.get_block_meta_revs();
let (duplicated_fields, duplicated_blocks) = grid_pad.duplicate_grid_block_meta().await;
@ -698,6 +699,7 @@ impl GridRevisionEditor {
field_revs: duplicated_fields.into_iter().map(Arc::new).collect(),
block_metas: duplicated_blocks,
blocks: blocks_meta_data,
grid_view_revision_data,
})
}

View File

@ -74,6 +74,11 @@ impl GridViewRevisionEditor {
})
}
pub(crate) async fn duplicate_view_data(&self) -> FlowyResult<String> {
let json_str = self.pad.read().await.json_str()?;
Ok(json_str)
}
pub(crate) async fn will_create_row(&self, row_rev: &mut RowRevision, params: &CreateRowParams) {
if params.group_id.is_none() {
return;

View File

@ -56,6 +56,12 @@ impl GridViewManager {
})
}
pub(crate) async fn duplicate_grid_view(&self) -> FlowyResult<String> {
let editor = self.get_default_view_editor().await?;
let view_data = editor.duplicate_view_data().await?;
Ok(view_data)
}
/// When the row was created, we may need to modify the [RowRevision] according to the [CreateRowParams].
pub(crate) async fn will_create_row(&self, row_rev: &mut RowRevision, params: &CreateRowParams) {
for view_editor in self.view_editors.iter() {

View File

@ -1,10 +1,12 @@
use crate::entities::{ GroupChangesetPB, GroupViewChangesetPB, InsertedRowPB, RowPB};
use crate::services::cell::{decode_any_cell_data, CellBytesParser,};
use crate::entities::{GroupChangesetPB, GroupViewChangesetPB, InsertedRowPB, RowPB};
use crate::services::cell::{decode_any_cell_data, CellBytesParser};
use crate::services::group::action::GroupAction;
use crate::services::group::configuration::GroupContext;
use crate::services::group::entities::Group;
use flowy_error::FlowyResult;
use flowy_grid_data_model::revision::{ FieldRevision, GroupConfigurationContentSerde, GroupRevision, RowChangeset, RowRevision, TypeOptionDataDeserializer};
use flowy_grid_data_model::revision::{
FieldRevision, GroupConfigurationContentSerde, GroupRevision, RowChangeset, RowRevision, TypeOptionDataDeserializer,
};
use std::marker::PhantomData;
use std::sync::Arc;

View File

@ -80,7 +80,7 @@ impl GroupAction for CheckboxGroupController {
fn move_row(&mut self, _cell_data: &Self::CellDataType, mut context: MoveGroupRowContext) -> Vec<GroupChangesetPB> {
let mut group_changeset = vec![];
self.group_ctx.iter_mut_all_groups(|group| {
if let Some(changeset) = move_group_row(group, &mut context) {
if let Some(changeset) = move_group_row(group, &mut context) {
group_changeset.push(changeset);
}
});

View File

@ -49,7 +49,7 @@ impl GroupAction for SingleSelectGroupController {
fn move_row(&mut self, _cell_data: &Self::CellDataType, mut context: MoveGroupRowContext) -> Vec<GroupChangesetPB> {
let mut group_changeset = vec![];
self.group_ctx.iter_mut_all_groups(|group| {
if let Some(changeset) = move_group_row(group, &mut context) {
if let Some(changeset) = move_group_row(group, &mut context) {
group_changeset.push(changeset);
}
});