diff --git a/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs b/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs index 9eee9d7875a2a..0550f18f9f959 100644 --- a/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs +++ b/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs @@ -10,6 +10,7 @@ use flowy_document::entities::DocumentDataPB; use flowy_document::manager::DocumentManager; use flowy_document::parser::json::parser::JsonToDocumentParser; use flowy_error::FlowyError; +use flowy_folder::entities::{CreateViewParams, ViewLayoutPB}; use flowy_folder::manager::{FolderManager, FolderUser}; use flowy_folder::share::ImportType; use flowy_folder::view_operation::{ @@ -182,17 +183,13 @@ impl FolderOperationHandler for DocumentFolderOperation { fn create_view_with_view_data( &self, user_id: i64, - view_id: &str, - _name: &str, - data: Vec, - layout: ViewLayout, - _meta: HashMap, + params: CreateViewParams, ) -> FutureResult<(), FlowyError> { - debug_assert_eq!(layout, ViewLayout::Document); - let view_id = view_id.to_string(); + debug_assert_eq!(params.layout, ViewLayoutPB::Document); + let view_id = params.view_id.to_string(); let manager = self.0.clone(); FutureResult::new(async move { - let data = DocumentDataPB::try_from(Bytes::from(data))?; + let data = DocumentDataPB::try_from(Bytes::from(params.initial_data))?; manager .create_document(user_id, &view_id, Some(data.into())) .await?; @@ -302,40 +299,43 @@ impl FolderOperationHandler for DatabaseFolderOperation { fn create_view_with_view_data( &self, _user_id: i64, - view_id: &str, - name: &str, - data: Vec, - layout: ViewLayout, - meta: HashMap, + params: CreateViewParams, ) -> FutureResult<(), FlowyError> { - match CreateDatabaseExtParams::from_map(meta) { + match CreateDatabaseExtParams::from_map(params.meta.clone()) { None => { let database_manager = self.0.clone(); - let view_id = view_id.to_string(); + let view_id = params.view_id.to_string(); FutureResult::new(async move { database_manager - .create_database_with_database_data(&view_id, data) + .create_database_with_database_data(&view_id, params.initial_data) .await?; Ok(()) }) }, - Some(params) => { + Some(database_params) => { let database_manager = self.0.clone(); - let layout = match layout { - ViewLayout::Board => DatabaseLayoutPB::Board, - ViewLayout::Calendar => DatabaseLayoutPB::Calendar, - ViewLayout::Grid => DatabaseLayoutPB::Grid, - ViewLayout::Document | ViewLayout::Chat => { + let layout = match params.layout { + ViewLayoutPB::Board => DatabaseLayoutPB::Board, + ViewLayoutPB::Calendar => DatabaseLayoutPB::Calendar, + ViewLayoutPB::Grid => DatabaseLayoutPB::Grid, + ViewLayoutPB::Document | ViewLayoutPB::Chat => { return FutureResult::new(async move { Err(FlowyError::not_support()) }); }, }; - let name = name.to_string(); - let database_view_id = view_id.to_string(); + let name = params.name.to_string(); + let database_view_id = params.view_id.to_string(); + let database_parent_view_id = params.parent_view_id.to_string(); FutureResult::new(async move { database_manager - .create_linked_view(name, layout.into(), params.database_id, database_view_id) + .create_linked_view( + name, + layout.into(), + database_params.database_id, + database_view_id, + database_parent_view_id, + ) .await?; Ok(()) }) @@ -504,11 +504,7 @@ impl FolderOperationHandler for ChatFolderOperation { fn create_view_with_view_data( &self, _user_id: i64, - _view_id: &str, - _name: &str, - _data: Vec, - _layout: ViewLayout, - _meta: HashMap, + _params: CreateViewParams, ) -> FutureResult<(), FlowyError> { FutureResult::new(async move { Err(FlowyError::not_support()) }) } diff --git a/frontend/rust-lib/flowy-database2/src/manager.rs b/frontend/rust-lib/flowy-database2/src/manager.rs index 598d3cec37cdc..06ca2753da97e 100644 --- a/frontend/rust-lib/flowy-database2/src/manager.rs +++ b/frontend/rust-lib/flowy-database2/src/manager.rs @@ -323,18 +323,23 @@ impl DatabaseManager { layout: DatabaseLayout, database_id: String, database_view_id: String, + database_parent_view_id: String, ) -> FlowyResult<()> { let wdb = self.get_database_indexer().await?; let mut params = CreateViewParams::new(database_id.clone(), database_view_id, name, layout); if let Some(database) = wdb.get_database(&database_id).await { - let (field, layout_setting) = DatabaseLayoutDepsResolver::new(database, layout) - .resolve_deps_when_create_database_linked_view(); + let (field, layout_setting, field_settings_map) = + DatabaseLayoutDepsResolver::new(database, layout) + .resolve_deps_when_create_database_linked_view(&database_parent_view_id); if let Some(field) = field { params = params.with_deps_fields(vec![field], vec![default_field_settings_by_layout_map()]); } if let Some(layout_setting) = layout_setting { params = params.with_layout_setting(layout_setting); } + if let Some(field_settings_map) = field_settings_map { + params = params.with_field_settings_map(field_settings_map); + } }; wdb.create_database_linked_view(params).await?; Ok(()) diff --git a/frontend/rust-lib/flowy-database2/src/services/database_view/layout_deps.rs b/frontend/rust-lib/flowy-database2/src/services/database_view/layout_deps.rs index 5d5e3b4c3f670..33a4dd8a4ed87 100644 --- a/frontend/rust-lib/flowy-database2/src/services/database_view/layout_deps.rs +++ b/frontend/rust-lib/flowy-database2/src/services/database_view/layout_deps.rs @@ -1,6 +1,8 @@ use collab_database::database::{gen_field_id, MutexDatabase}; use collab_database::fields::Field; -use collab_database::views::{DatabaseLayout, LayoutSetting, OrderObjectPosition}; +use collab_database::views::{ + DatabaseLayout, FieldSettingsByFieldIdMap, LayoutSetting, OrderObjectPosition, +}; use std::sync::Arc; use crate::entities::FieldType; @@ -28,23 +30,40 @@ impl DatabaseLayoutDepsResolver { pub fn resolve_deps_when_create_database_linked_view( &self, - ) -> (Option, Option) { + view_id: &str, + ) -> ( + Option, + Option, + Option, + ) { match self.database_layout { - DatabaseLayout::Grid => (None, None), + DatabaseLayout::Grid => (None, None, None), DatabaseLayout::Board => { let layout_settings = BoardLayoutSetting::new().into(); - if !self + + let field = if !self .database .lock() .get_fields(None) .into_iter() .any(|field| FieldType::from(field.field_type).can_be_group()) { - let select_field = self.create_select_field(); - (Some(select_field), Some(layout_settings)) + Some(self.create_select_field()) } else { - (None, Some(layout_settings)) - } + None + }; + + let field_settings_map = self.database.lock().get_field_settings(view_id, None); + tracing::info!( + "resolve_deps_when_create_database_linked_view {:?}", + field_settings_map + ); + + ( + field, + Some(layout_settings), + Some(field_settings_map.into()), + ) }, DatabaseLayout::Calendar => { match self @@ -56,12 +75,12 @@ impl DatabaseLayoutDepsResolver { { Some(field) => { let layout_setting = CalendarLayoutSetting::new(field.id).into(); - (None, Some(layout_setting)) + (None, Some(layout_setting), None) }, None => { let date_field = self.create_date_field(); let layout_setting = CalendarLayoutSetting::new(date_field.clone().id).into(); - (Some(date_field), Some(layout_setting)) + (Some(date_field), Some(layout_setting), None) }, } }, diff --git a/frontend/rust-lib/flowy-folder/src/manager.rs b/frontend/rust-lib/flowy-folder/src/manager.rs index 28d802b6dbf55..fa8c68831032f 100644 --- a/frontend/rust-lib/flowy-folder/src/manager.rs +++ b/frontend/rust-lib/flowy-folder/src/manager.rs @@ -376,9 +376,8 @@ impl FolderManager { let view_layout: ViewLayout = params.layout.clone().into(); let handler = self.get_handler(&view_layout)?; let user_id = self.user.user_id()?; - let meta = params.meta.clone(); - if meta.is_empty() && params.initial_data.is_empty() { + if params.meta.is_empty() && params.initial_data.is_empty() { tracing::trace!("Create view with build-in data"); handler .create_built_in_view(user_id, ¶ms.view_id, ¶ms.name, view_layout.clone()) @@ -386,14 +385,7 @@ impl FolderManager { } else { tracing::trace!("Create view with view data"); handler - .create_view_with_view_data( - user_id, - ¶ms.view_id, - ¶ms.name, - params.initial_data.clone(), - view_layout.clone(), - meta, - ) + .create_view_with_view_data(user_id, params.clone()) .await?; } diff --git a/frontend/rust-lib/flowy-folder/src/view_operation.rs b/frontend/rust-lib/flowy-folder/src/view_operation.rs index 3132384e777ba..43aede739f0c3 100644 --- a/frontend/rust-lib/flowy-folder/src/view_operation.rs +++ b/frontend/rust-lib/flowy-folder/src/view_operation.rs @@ -63,11 +63,7 @@ pub trait FolderOperationHandler { fn create_view_with_view_data( &self, user_id: i64, - view_id: &str, - name: &str, - data: Vec, - layout: ViewLayout, - meta: HashMap, + params: CreateViewParams, ) -> FutureResult<(), FlowyError>; /// Create a view with the pre-defined data.