Skip to content

Commit 6fa79b6

Browse files
authored
Merge pull request #1150 from AppFlowy-IO/fix/1135_1
Fix/1135 issue 1
2 parents 55be554 + e66b3b0 commit 6fa79b6

File tree

15 files changed

+124
-43
lines changed

15 files changed

+124
-43
lines changed

frontend/rust-lib/flowy-folder/src/manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ pub trait ViewDataProcessor {
260260

261261
fn close_container(&self, view_id: &str) -> FutureResult<(), FlowyError>;
262262

263-
fn get_delta_data(&self, view_id: &str) -> FutureResult<Bytes, FlowyError>;
263+
fn get_view_data(&self, view_id: &str) -> FutureResult<Bytes, FlowyError>;
264264

265265
fn create_default_view(
266266
&self,

frontend/rust-lib/flowy-folder/src/services/view/controller.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ impl ViewController {
6161
let processor = self.get_data_processor(params.data_type.clone())?;
6262
let user_id = self.user.user_id()?;
6363
if params.view_content_data.is_empty() {
64+
tracing::trace!("Create view with build-in data");
6465
let view_data = processor
6566
.create_default_view(&user_id, &params.view_id, params.layout.clone())
6667
.await?;
6768
params.view_content_data = view_data.to_vec();
6869
} else {
70+
tracing::trace!("Create view with view data");
6971
let delta_data = processor
7072
.create_view_from_delta_data(
7173
&user_id,
@@ -231,15 +233,15 @@ impl ViewController {
231233
.await?;
232234

233235
let processor = self.get_data_processor(view_rev.data_type.clone())?;
234-
let delta_bytes = processor.get_delta_data(view_id).await?;
236+
let view_data = processor.get_view_data(view_id).await?;
235237
let duplicate_params = CreateViewParams {
236238
belong_to_id: view_rev.app_id.clone(),
237239
name: format!("{} (copy)", &view_rev.name),
238240
desc: view_rev.desc,
239241
thumbnail: view_rev.thumbnail,
240242
data_type: view_rev.data_type.into(),
241243
layout: view_rev.layout.into(),
242-
view_content_data: delta_bytes.to_vec(),
244+
view_content_data: view_data.to_vec(),
243245
view_id: gen_view_id(),
244246
};
245247

frontend/rust-lib/flowy-grid/src/dart_notification.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,3 @@ impl std::convert::From<GridNotification> for i32 {
3333
pub fn send_dart_notification(id: &str, ty: GridNotification) -> DartNotifyBuilder {
3434
DartNotifyBuilder::new(id, ty, OBSERVABLE_CATEGORY)
3535
}
36-
37-
#[tracing::instrument(level = "trace")]
38-
pub fn send_anonymous_dart_notification(ty: GridNotification) -> DartNotifyBuilder {
39-
DartNotifyBuilder::new("", ty, OBSERVABLE_CATEGORY)
40-
}

frontend/rust-lib/flowy-grid/src/manager.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,14 @@ pub async fn make_grid_view_data(
183183
grid_manager: Arc<GridManager>,
184184
build_context: BuildGridContext,
185185
) -> FlowyResult<Bytes> {
186-
for block_meta_data in &build_context.blocks {
186+
let BuildGridContext {
187+
field_revs,
188+
block_metas,
189+
blocks,
190+
grid_view_revision_data,
191+
} = build_context;
192+
193+
for block_meta_data in &blocks {
187194
let block_id = &block_meta_data.block_id;
188195
// Indexing the block's rows
189196
block_meta_data.rows.iter().for_each(|row| {
@@ -200,7 +207,7 @@ pub async fn make_grid_view_data(
200207

201208
// Will replace the grid_id with the value returned by the gen_grid_id()
202209
let grid_id = view_id.to_owned();
203-
let grid_rev = GridRevision::from_build_context(&grid_id, build_context);
210+
let grid_rev = GridRevision::from_build_context(&grid_id, field_revs, block_metas);
204211

205212
// Create grid
206213
let grid_rev_delta = make_grid_delta(&grid_rev);
@@ -210,7 +217,11 @@ pub async fn make_grid_view_data(
210217
let _ = grid_manager.create_grid(&grid_id, repeated_revision).await?;
211218

212219
// Create grid view
213-
let grid_view = GridViewRevision::new(grid_id, view_id.to_owned(), layout.into());
220+
let grid_view = if grid_view_revision_data.is_empty() {
221+
GridViewRevision::new(grid_id, view_id.to_owned(), layout.into())
222+
} else {
223+
GridViewRevision::from_json(grid_view_revision_data)?
224+
};
214225
let grid_view_delta = make_grid_view_delta(&grid_view);
215226
let grid_view_delta_bytes = grid_view_delta.json_bytes();
216227
let repeated_revision: RepeatedRevision =

frontend/rust-lib/flowy-grid/src/services/cell/any_cell_data.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ impl std::str::FromStr for AnyCellData {
1919
type Err = FlowyError;
2020

2121
fn from_str(s: &str) -> Result<Self, Self::Err> {
22-
let type_option_cell_data: AnyCellData = serde_json::from_str(s)?;
22+
let type_option_cell_data: AnyCellData = serde_json::from_str(s).map_err(|err| {
23+
let msg = format!("Deserialize {} to any cell data failed. Serde error: {}", s, err);
24+
FlowyError::internal().context(msg)
25+
})?;
2326
Ok(type_option_cell_data)
2427
}
2528
}

frontend/rust-lib/flowy-grid/src/services/cell/cell_operation.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::entities::FieldType;
22
use crate::services::cell::{AnyCellData, CellBytes};
33
use crate::services::field::*;
4+
use std::fmt::Debug;
45

56
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
67
use flowy_grid_data_model::revision::{CellRevision, FieldRevision, FieldTypeRevision};
@@ -73,20 +74,30 @@ pub fn apply_cell_data_changeset<C: ToString, T: AsRef<FieldRevision>>(
7374
Ok(AnyCellData::new(s, field_type).json())
7475
}
7576

76-
pub fn decode_any_cell_data<T: TryInto<AnyCellData>>(data: T, field_rev: &FieldRevision) -> CellBytes {
77-
if let Ok(any_cell_data) = data.try_into() {
78-
let AnyCellData { data, field_type } = any_cell_data;
79-
let to_field_type = field_rev.ty.into();
80-
match try_decode_cell_data(data.into(), field_rev, &field_type, &to_field_type) {
81-
Ok(cell_bytes) => cell_bytes,
82-
Err(e) => {
83-
tracing::error!("Decode cell data failed, {:?}", e);
84-
CellBytes::default()
77+
pub fn decode_any_cell_data<T: TryInto<AnyCellData, Error = FlowyError> + Debug>(
78+
data: T,
79+
field_rev: &FieldRevision,
80+
) -> CellBytes {
81+
match data.try_into() {
82+
Ok(any_cell_data) => {
83+
let AnyCellData { data, field_type } = any_cell_data;
84+
let to_field_type = field_rev.ty.into();
85+
match try_decode_cell_data(data.into(), field_rev, &field_type, &to_field_type) {
86+
Ok(cell_bytes) => cell_bytes,
87+
Err(e) => {
88+
tracing::error!("Decode cell data failed, {:?}", e);
89+
CellBytes::default()
90+
}
8591
}
8692
}
87-
} else {
88-
tracing::error!("Decode type option data failed");
89-
CellBytes::default()
93+
Err(err) => {
94+
tracing::error!(
95+
"Decode type option data to type: {} failed: {:?}",
96+
std::any::type_name::<T>(),
97+
err,
98+
);
99+
CellBytes::default()
100+
}
90101
}
91102
}
92103

frontend/rust-lib/flowy-grid/src/services/grid_editor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ impl GridRevisionEditor {
673673

674674
pub async fn duplicate_grid(&self) -> FlowyResult<BuildGridContext> {
675675
let grid_pad = self.grid_pad.read().await;
676+
let grid_view_revision_data = self.view_manager.duplicate_grid_view().await?;
676677
let original_blocks = grid_pad.get_block_meta_revs();
677678
let (duplicated_fields, duplicated_blocks) = grid_pad.duplicate_grid_block_meta().await;
678679

@@ -698,6 +699,7 @@ impl GridRevisionEditor {
698699
field_revs: duplicated_fields.into_iter().map(Arc::new).collect(),
699700
block_metas: duplicated_blocks,
700701
blocks: blocks_meta_data,
702+
grid_view_revision_data,
701703
})
702704
}
703705

frontend/rust-lib/flowy-grid/src/services/grid_view_editor.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ impl GridViewRevisionEditor {
7474
})
7575
}
7676

77+
pub(crate) async fn duplicate_view_data(&self) -> FlowyResult<String> {
78+
let json_str = self.pad.read().await.json_str()?;
79+
Ok(json_str)
80+
}
81+
7782
pub(crate) async fn will_create_row(&self, row_rev: &mut RowRevision, params: &CreateRowParams) {
7883
if params.group_id.is_none() {
7984
return;

frontend/rust-lib/flowy-grid/src/services/grid_view_manager.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ impl GridViewManager {
5656
})
5757
}
5858

59+
pub(crate) async fn duplicate_grid_view(&self) -> FlowyResult<String> {
60+
let editor = self.get_default_view_editor().await?;
61+
let view_data = editor.duplicate_view_data().await?;
62+
Ok(view_data)
63+
}
64+
5965
/// When the row was created, we may need to modify the [RowRevision] according to the [CreateRowParams].
6066
pub(crate) async fn will_create_row(&self, row_rev: &mut RowRevision, params: &CreateRowParams) {
6167
for view_editor in self.view_editors.iter() {

frontend/rust-lib/flowy-grid/src/services/group/action.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ pub trait GroupAction: Send + Sync {
1414
fn can_group(&self, content: &str, cell_data: &Self::CellDataType) -> bool;
1515
fn add_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec<GroupChangesetPB>;
1616
fn remove_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec<GroupChangesetPB>;
17+
// Move row from one group to another
1718
fn move_row(&mut self, cell_data: &Self::CellDataType, context: MoveGroupRowContext) -> Vec<GroupChangesetPB>;
1819
}

0 commit comments

Comments
 (0)