mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-11-09 23:46:19 +03:00
fix: duplicate board
This commit is contained in:
parent
fa0a485c85
commit
e66b3b07db
@ -260,7 +260,7 @@ pub trait ViewDataProcessor {
|
||||
|
||||
fn close_container(&self, view_id: &str) -> FutureResult<(), FlowyError>;
|
||||
|
||||
fn get_delta_data(&self, view_id: &str) -> FutureResult<Bytes, FlowyError>;
|
||||
fn get_view_data(&self, view_id: &str) -> FutureResult<Bytes, FlowyError>;
|
||||
|
||||
fn create_default_view(
|
||||
&self,
|
||||
|
@ -61,11 +61,13 @@ impl ViewController {
|
||||
let processor = self.get_data_processor(params.data_type.clone())?;
|
||||
let user_id = self.user.user_id()?;
|
||||
if params.view_content_data.is_empty() {
|
||||
tracing::trace!("Create view with build-in data");
|
||||
let view_data = processor
|
||||
.create_default_view(&user_id, ¶ms.view_id, params.layout.clone())
|
||||
.await?;
|
||||
params.view_content_data = view_data.to_vec();
|
||||
} else {
|
||||
tracing::trace!("Create view with view data");
|
||||
let delta_data = processor
|
||||
.create_view_from_delta_data(
|
||||
&user_id,
|
||||
@ -231,7 +233,7 @@ impl ViewController {
|
||||
.await?;
|
||||
|
||||
let processor = self.get_data_processor(view_rev.data_type.clone())?;
|
||||
let delta_bytes = processor.get_delta_data(view_id).await?;
|
||||
let view_data = processor.get_view_data(view_id).await?;
|
||||
let duplicate_params = CreateViewParams {
|
||||
belong_to_id: view_rev.app_id.clone(),
|
||||
name: format!("{} (copy)", &view_rev.name),
|
||||
@ -239,7 +241,7 @@ impl ViewController {
|
||||
thumbnail: view_rev.thumbnail,
|
||||
data_type: view_rev.data_type.into(),
|
||||
layout: view_rev.layout.into(),
|
||||
view_content_data: delta_bytes.to_vec(),
|
||||
view_content_data: view_data.to_vec(),
|
||||
view_id: gen_view_id(),
|
||||
};
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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 =
|
||||
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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() {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
@ -170,7 +170,7 @@ impl ViewDataProcessor for TextBlockViewDataProcessor {
|
||||
})
|
||||
}
|
||||
|
||||
fn get_delta_data(&self, view_id: &str) -> FutureResult<Bytes, FlowyError> {
|
||||
fn get_view_data(&self, view_id: &str) -> FutureResult<Bytes, FlowyError> {
|
||||
let view_id = view_id.to_string();
|
||||
let manager = self.0.clone();
|
||||
FutureResult::new(async move {
|
||||
@ -247,7 +247,7 @@ impl ViewDataProcessor for GridViewDataProcessor {
|
||||
})
|
||||
}
|
||||
|
||||
fn get_delta_data(&self, view_id: &str) -> FutureResult<Bytes, FlowyError> {
|
||||
fn get_view_data(&self, view_id: &str) -> FutureResult<Bytes, FlowyError> {
|
||||
let view_id = view_id.to_string();
|
||||
let grid_manager = self.0.clone();
|
||||
FutureResult::new(async move {
|
||||
|
@ -34,11 +34,15 @@ impl GridRevision {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_build_context(grid_id: &str, context: BuildGridContext) -> Self {
|
||||
pub fn from_build_context(
|
||||
grid_id: &str,
|
||||
field_revs: Vec<Arc<FieldRevision>>,
|
||||
block_metas: Vec<GridBlockMetaRevision>,
|
||||
) -> Self {
|
||||
Self {
|
||||
grid_id: grid_id.to_owned(),
|
||||
fields: context.field_revs,
|
||||
blocks: context.block_metas.into_iter().map(Arc::new).collect(),
|
||||
fields: field_revs,
|
||||
blocks: block_metas.into_iter().map(Arc::new).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -188,6 +192,9 @@ pub struct BuildGridContext {
|
||||
pub field_revs: Vec<Arc<FieldRevision>>,
|
||||
pub block_metas: Vec<GridBlockMetaRevision>,
|
||||
pub blocks: Vec<GridBlockRevision>,
|
||||
|
||||
// String in JSON format. It can be deserialized into [GridViewRevision]
|
||||
pub grid_view_revision_data: String,
|
||||
}
|
||||
|
||||
impl BuildGridContext {
|
||||
|
@ -58,6 +58,10 @@ impl GridViewRevision {
|
||||
// row_orders: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_json(json: String) -> Result<Self, serde_json::Error> {
|
||||
serde_json::from_str(&json)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
|
Loading…
Reference in New Issue
Block a user