diff --git a/frontend/app_flowy/lib/plugins/board/board.dart b/frontend/app_flowy/lib/plugins/board/board.dart index 36d181ae3e..2954a7cbf9 100644 --- a/frontend/app_flowy/lib/plugins/board/board.dart +++ b/frontend/app_flowy/lib/plugins/board/board.dart @@ -31,7 +31,7 @@ class BoardPluginBuilder implements PluginBuilder { class BoardPluginConfig implements PluginConfig { @override - bool get creatable => true; + bool get creatable => false; } class BoardPlugin extends Plugin { diff --git a/frontend/rust-lib/flowy-grid/src/manager.rs b/frontend/rust-lib/flowy-grid/src/manager.rs index f99e6ca4c6..4b4ea3b167 100644 --- a/frontend/rust-lib/flowy-grid/src/manager.rs +++ b/frontend/rust-lib/flowy-grid/src/manager.rs @@ -1,5 +1,6 @@ use crate::services::block_editor::GridBlockRevisionCompactor; use crate::services::grid_editor::{GridRevisionCompactor, GridRevisionEditor}; +use crate::services::grid_view_manager::make_grid_view_rev_manager; use crate::services::persistence::block_index::BlockIndexCache; use crate::services::persistence::kv::GridKVPersistence; use crate::services::persistence::migration::GridMigration; @@ -9,10 +10,10 @@ use bytes::Bytes; use dashmap::DashMap; use flowy_database::ConnectionPool; use flowy_error::{FlowyError, FlowyResult}; -use flowy_grid_data_model::revision::{BuildGridContext, GridRevision}; +use flowy_grid_data_model::revision::{BuildGridContext, GridRevision, GridViewRevision}; use flowy_revision::disk::{SQLiteGridBlockRevisionPersistence, SQLiteGridRevisionPersistence}; use flowy_revision::{RevisionManager, RevisionPersistence, RevisionWebSocket, SQLiteRevisionSnapshotPersistence}; -use flowy_sync::client_grid::{make_grid_block_delta, make_grid_delta}; +use flowy_sync::client_grid::{make_grid_block_delta, make_grid_delta, make_grid_view_delta}; use flowy_sync::entities::revision::{RepeatedRevision, Revision}; use std::sync::Arc; use tokio::sync::RwLock; @@ -70,6 +71,15 @@ impl GridManager { let db_pool = self.grid_user.db_pool()?; let rev_manager = self.make_grid_rev_manager(grid_id, db_pool)?; let _ = rev_manager.reset_object(revisions).await?; + + Ok(()) + } + + #[tracing::instrument(level = "debug", skip_all, err)] + async fn create_grid_view>(&self, view_id: T, revisions: RepeatedRevision) -> FlowyResult<()> { + let view_id = view_id.as_ref(); + let rev_manager = make_grid_view_rev_manager(&self.grid_user, view_id).await?; + let _ = rev_manager.reset_object(revisions).await?; Ok(()) } @@ -198,14 +208,23 @@ pub async fn make_grid_view_data( let _ = grid_manager.create_grid_block(&block_id, repeated_revision).await?; } - let grid_rev = GridRevision::from_build_context(view_id, build_context); + let grid_id = view_id.to_owned(); + let grid_rev = GridRevision::from_build_context(&grid_id, build_context); // Create grid - let grid_meta_delta = make_grid_delta(&grid_rev); - let grid_delta_data = grid_meta_delta.json_bytes(); + let grid_rev_delta = make_grid_delta(&grid_rev); + let grid_rev_delta_bytes = grid_rev_delta.json_bytes(); let repeated_revision: RepeatedRevision = - Revision::initial_revision(user_id, view_id, grid_delta_data.clone()).into(); - let _ = grid_manager.create_grid(view_id, repeated_revision).await?; + Revision::initial_revision(user_id, &grid_id, grid_rev_delta_bytes.clone()).into(); + let _ = grid_manager.create_grid(&grid_id, repeated_revision).await?; - Ok(grid_delta_data) + // Create grid view + let grid_view = GridViewRevision::new(view_id.to_owned(), view_id.to_owned()); + let grid_view_delta = make_grid_view_delta(&grid_view); + let grid_view_delta_bytes = grid_view_delta.json_bytes(); + let repeated_revision: RepeatedRevision = + Revision::initial_revision(user_id, view_id, grid_view_delta_bytes).into(); + let _ = grid_manager.create_grid_view(view_id, repeated_revision).await?; + + Ok(grid_rev_delta_bytes) } diff --git a/frontend/rust-lib/flowy-grid/src/services/grid_view_manager.rs b/frontend/rust-lib/flowy-grid/src/services/grid_view_manager.rs index 4daf2af667..70768ef3a4 100644 --- a/frontend/rust-lib/flowy-grid/src/services/grid_view_manager.rs +++ b/frontend/rust-lib/flowy-grid/src/services/grid_view_manager.rs @@ -140,18 +140,31 @@ where DataSource: GridViewRevisionDataSource, { tracing::trace!("Open view:{} editor", view_id); + + let rev_manager = make_grid_view_rev_manager(user, view_id).await?; + let user_id = user.user_id()?; let token = user.token()?; + let view_id = view_id.to_owned(); + GridViewRevisionEditor::new(&user_id, &token, view_id, delegate, data_source, scheduler, rev_manager).await +} + +pub async fn make_grid_view_rev_manager(user: &Arc, view_id: &str) -> FlowyResult { + tracing::trace!("Open view:{} editor", view_id); let user_id = user.user_id()?; let pool = user.db_pool()?; - let view_id = view_id.to_owned(); let disk_cache = SQLiteGridViewRevisionPersistence::new(&user_id, pool.clone()); - let rev_persistence = RevisionPersistence::new(&user_id, &view_id, disk_cache); + let rev_persistence = RevisionPersistence::new(&user_id, view_id, disk_cache); let rev_compactor = GridViewRevisionCompactor(); - let snapshot_persistence = SQLiteRevisionSnapshotPersistence::new(&view_id, pool); - let rev_manager = RevisionManager::new(&user_id, &view_id, rev_persistence, rev_compactor, snapshot_persistence); - GridViewRevisionEditor::new(&user_id, &token, view_id, delegate, data_source, scheduler, rev_manager).await + let snapshot_persistence = SQLiteRevisionSnapshotPersistence::new(view_id, pool); + Ok(RevisionManager::new( + &user_id, + view_id, + rev_persistence, + rev_compactor, + snapshot_persistence, + )) } pub struct GridViewRevisionCompactor(); diff --git a/shared-lib/flowy-grid-data-model/src/revision/grid_view.rs b/shared-lib/flowy-grid-data-model/src/revision/grid_view.rs index 352b9e616c..2fcc2fc4eb 100644 --- a/shared-lib/flowy-grid-data-model/src/revision/grid_view.rs +++ b/shared-lib/flowy-grid-data-model/src/revision/grid_view.rs @@ -22,9 +22,9 @@ pub struct GridViewRevision { } impl GridViewRevision { - pub fn new(grid_id: String) -> Self { + pub fn new(grid_id: String, view_id: String) -> Self { GridViewRevision { - view_id: grid_id.clone(), + view_id, grid_id, setting: Default::default(), row_orders: vec![], diff --git a/shared-lib/flowy-grid-data-model/tests/serde_test.rs b/shared-lib/flowy-grid-data-model/tests/serde_test.rs index 8a630a4651..b544e10588 100644 --- a/shared-lib/flowy-grid-data-model/tests/serde_test.rs +++ b/shared-lib/flowy-grid-data-model/tests/serde_test.rs @@ -6,8 +6,5 @@ fn grid_default_serde_test() { let grid = GridRevision::new(&grid_id); let json = serde_json::to_string(&grid).unwrap(); - assert_eq!( - json, - r#"{"grid_id":"1","fields":[],"blocks":[],"setting":{"layout":0,"filters":[],"groups":[]}}"# - ) + assert_eq!(json, r#"{"grid_id":"1","fields":[],"blocks":[]}"#) } diff --git a/shared-lib/flowy-sync/src/client_grid/view_revision_pad.rs b/shared-lib/flowy-sync/src/client_grid/view_revision_pad.rs index fadd6d57a2..dd6cc6f977 100644 --- a/shared-lib/flowy-sync/src/client_grid/view_revision_pad.rs +++ b/shared-lib/flowy-sync/src/client_grid/view_revision_pad.rs @@ -25,8 +25,8 @@ impl std::ops::Deref for GridViewRevisionPad { } impl GridViewRevisionPad { - pub fn new(grid_id: String) -> Self { - let view = Arc::new(GridViewRevision::new(grid_id)); + pub fn new(grid_id: String, view_id: String) -> Self { + let view = Arc::new(GridViewRevision::new(grid_id, view_id)); let json = serde_json::to_string(&view).unwrap(); let delta = TextDeltaBuilder::new().insert(&json).build(); Self { view, delta } @@ -244,3 +244,8 @@ pub fn make_grid_view_rev_json_str(grid_revision: &GridViewRevision) -> Collabor .map_err(|err| internal_error(format!("Serialize grid view to json str failed. {:?}", err)))?; Ok(json) } + +pub fn make_grid_view_delta(grid_view: &GridViewRevision) -> TextDelta { + let json = serde_json::to_string(grid_view).unwrap(); + TextDeltaBuilder::new().insert(&json).build() +}