Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fill field_settings on creating linked view #5598

Merged
merged 5 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 26 additions & 30 deletions frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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<u8>,
layout: ViewLayout,
_meta: HashMap<String, String>,
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?;
Expand Down Expand Up @@ -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<u8>,
layout: ViewLayout,
meta: HashMap<String, String>,
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(())
})
Expand Down Expand Up @@ -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<u8>,
_layout: ViewLayout,
_meta: HashMap<String, String>,
_params: CreateViewParams,
) -> FutureResult<(), FlowyError> {
FutureResult::new(async move { Err(FlowyError::not_support()) })
}
Expand Down
9 changes: 7 additions & 2 deletions frontend/rust-lib/flowy-database2/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -28,23 +30,40 @@ impl DatabaseLayoutDepsResolver {

pub fn resolve_deps_when_create_database_linked_view(
&self,
) -> (Option<Field>, Option<LayoutSetting>) {
view_id: &str,
) -> (
Option<Field>,
Option<LayoutSetting>,
Option<FieldSettingsByFieldIdMap>,
) {
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
Expand All @@ -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)
},
}
},
Expand Down
12 changes: 2 additions & 10 deletions frontend/rust-lib/flowy-folder/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,24 +376,16 @@ 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, &params.view_id, &params.name, view_layout.clone())
.await?;
} else {
tracing::trace!("Create view with view data");
handler
.create_view_with_view_data(
user_id,
&params.view_id,
&params.name,
params.initial_data.clone(),
view_layout.clone(),
meta,
)
.create_view_with_view_data(user_id, params.clone())
.await?;
}

Expand Down
6 changes: 1 addition & 5 deletions frontend/rust-lib/flowy-folder/src/view_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ pub trait FolderOperationHandler {
fn create_view_with_view_data(
&self,
user_id: i64,
view_id: &str,
name: &str,
data: Vec<u8>,
layout: ViewLayout,
meta: HashMap<String, String>,
params: CreateViewParams,
) -> FutureResult<(), FlowyError>;

/// Create a view with the pre-defined data.
Expand Down
Loading