mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: fill field_settings on creating linked view (#5598)
This commit is contained in:
parent
bbb3f95a13
commit
b24fbc6b60
@ -10,6 +10,7 @@ use flowy_document::entities::DocumentDataPB;
|
|||||||
use flowy_document::manager::DocumentManager;
|
use flowy_document::manager::DocumentManager;
|
||||||
use flowy_document::parser::json::parser::JsonToDocumentParser;
|
use flowy_document::parser::json::parser::JsonToDocumentParser;
|
||||||
use flowy_error::FlowyError;
|
use flowy_error::FlowyError;
|
||||||
|
use flowy_folder::entities::{CreateViewParams, ViewLayoutPB};
|
||||||
use flowy_folder::manager::{FolderManager, FolderUser};
|
use flowy_folder::manager::{FolderManager, FolderUser};
|
||||||
use flowy_folder::share::ImportType;
|
use flowy_folder::share::ImportType;
|
||||||
use flowy_folder::view_operation::{
|
use flowy_folder::view_operation::{
|
||||||
@ -182,17 +183,13 @@ impl FolderOperationHandler for DocumentFolderOperation {
|
|||||||
fn create_view_with_view_data(
|
fn create_view_with_view_data(
|
||||||
&self,
|
&self,
|
||||||
user_id: i64,
|
user_id: i64,
|
||||||
view_id: &str,
|
params: CreateViewParams,
|
||||||
_name: &str,
|
|
||||||
data: Vec<u8>,
|
|
||||||
layout: ViewLayout,
|
|
||||||
_meta: HashMap<String, String>,
|
|
||||||
) -> FutureResult<(), FlowyError> {
|
) -> FutureResult<(), FlowyError> {
|
||||||
debug_assert_eq!(layout, ViewLayout::Document);
|
debug_assert_eq!(params.layout, ViewLayoutPB::Document);
|
||||||
let view_id = view_id.to_string();
|
let view_id = params.view_id.to_string();
|
||||||
let manager = self.0.clone();
|
let manager = self.0.clone();
|
||||||
FutureResult::new(async move {
|
FutureResult::new(async move {
|
||||||
let data = DocumentDataPB::try_from(Bytes::from(data))?;
|
let data = DocumentDataPB::try_from(Bytes::from(params.initial_data))?;
|
||||||
manager
|
manager
|
||||||
.create_document(user_id, &view_id, Some(data.into()))
|
.create_document(user_id, &view_id, Some(data.into()))
|
||||||
.await?;
|
.await?;
|
||||||
@ -302,40 +299,43 @@ impl FolderOperationHandler for DatabaseFolderOperation {
|
|||||||
fn create_view_with_view_data(
|
fn create_view_with_view_data(
|
||||||
&self,
|
&self,
|
||||||
_user_id: i64,
|
_user_id: i64,
|
||||||
view_id: &str,
|
params: CreateViewParams,
|
||||||
name: &str,
|
|
||||||
data: Vec<u8>,
|
|
||||||
layout: ViewLayout,
|
|
||||||
meta: HashMap<String, String>,
|
|
||||||
) -> FutureResult<(), FlowyError> {
|
) -> FutureResult<(), FlowyError> {
|
||||||
match CreateDatabaseExtParams::from_map(meta) {
|
match CreateDatabaseExtParams::from_map(params.meta.clone()) {
|
||||||
None => {
|
None => {
|
||||||
let database_manager = self.0.clone();
|
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 {
|
FutureResult::new(async move {
|
||||||
database_manager
|
database_manager
|
||||||
.create_database_with_database_data(&view_id, data)
|
.create_database_with_database_data(&view_id, params.initial_data)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
Some(params) => {
|
Some(database_params) => {
|
||||||
let database_manager = self.0.clone();
|
let database_manager = self.0.clone();
|
||||||
|
|
||||||
let layout = match layout {
|
let layout = match params.layout {
|
||||||
ViewLayout::Board => DatabaseLayoutPB::Board,
|
ViewLayoutPB::Board => DatabaseLayoutPB::Board,
|
||||||
ViewLayout::Calendar => DatabaseLayoutPB::Calendar,
|
ViewLayoutPB::Calendar => DatabaseLayoutPB::Calendar,
|
||||||
ViewLayout::Grid => DatabaseLayoutPB::Grid,
|
ViewLayoutPB::Grid => DatabaseLayoutPB::Grid,
|
||||||
ViewLayout::Document | ViewLayout::Chat => {
|
ViewLayoutPB::Document | ViewLayoutPB::Chat => {
|
||||||
return FutureResult::new(async move { Err(FlowyError::not_support()) });
|
return FutureResult::new(async move { Err(FlowyError::not_support()) });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let name = name.to_string();
|
let name = params.name.to_string();
|
||||||
let database_view_id = view_id.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 {
|
FutureResult::new(async move {
|
||||||
database_manager
|
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?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@ -504,11 +504,7 @@ impl FolderOperationHandler for ChatFolderOperation {
|
|||||||
fn create_view_with_view_data(
|
fn create_view_with_view_data(
|
||||||
&self,
|
&self,
|
||||||
_user_id: i64,
|
_user_id: i64,
|
||||||
_view_id: &str,
|
_params: CreateViewParams,
|
||||||
_name: &str,
|
|
||||||
_data: Vec<u8>,
|
|
||||||
_layout: ViewLayout,
|
|
||||||
_meta: HashMap<String, String>,
|
|
||||||
) -> FutureResult<(), FlowyError> {
|
) -> FutureResult<(), FlowyError> {
|
||||||
FutureResult::new(async move { Err(FlowyError::not_support()) })
|
FutureResult::new(async move { Err(FlowyError::not_support()) })
|
||||||
}
|
}
|
||||||
|
@ -323,18 +323,23 @@ impl DatabaseManager {
|
|||||||
layout: DatabaseLayout,
|
layout: DatabaseLayout,
|
||||||
database_id: String,
|
database_id: String,
|
||||||
database_view_id: String,
|
database_view_id: String,
|
||||||
|
database_parent_view_id: String,
|
||||||
) -> FlowyResult<()> {
|
) -> FlowyResult<()> {
|
||||||
let wdb = self.get_database_indexer().await?;
|
let wdb = self.get_database_indexer().await?;
|
||||||
let mut params = CreateViewParams::new(database_id.clone(), database_view_id, name, layout);
|
let mut params = CreateViewParams::new(database_id.clone(), database_view_id, name, layout);
|
||||||
if let Some(database) = wdb.get_database(&database_id).await {
|
if let Some(database) = wdb.get_database(&database_id).await {
|
||||||
let (field, layout_setting) = DatabaseLayoutDepsResolver::new(database, layout)
|
let (field, layout_setting, field_settings_map) =
|
||||||
.resolve_deps_when_create_database_linked_view();
|
DatabaseLayoutDepsResolver::new(database, layout)
|
||||||
|
.resolve_deps_when_create_database_linked_view(&database_parent_view_id);
|
||||||
if let Some(field) = field {
|
if let Some(field) = field {
|
||||||
params = params.with_deps_fields(vec![field], vec![default_field_settings_by_layout_map()]);
|
params = params.with_deps_fields(vec![field], vec![default_field_settings_by_layout_map()]);
|
||||||
}
|
}
|
||||||
if let Some(layout_setting) = layout_setting {
|
if let Some(layout_setting) = layout_setting {
|
||||||
params = params.with_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?;
|
wdb.create_database_linked_view(params).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
use collab_database::database::{gen_field_id, MutexDatabase};
|
use collab_database::database::{gen_field_id, MutexDatabase};
|
||||||
use collab_database::fields::Field;
|
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 std::sync::Arc;
|
||||||
|
|
||||||
use crate::entities::FieldType;
|
use crate::entities::FieldType;
|
||||||
@ -28,23 +30,40 @@ impl DatabaseLayoutDepsResolver {
|
|||||||
|
|
||||||
pub fn resolve_deps_when_create_database_linked_view(
|
pub fn resolve_deps_when_create_database_linked_view(
|
||||||
&self,
|
&self,
|
||||||
) -> (Option<Field>, Option<LayoutSetting>) {
|
view_id: &str,
|
||||||
|
) -> (
|
||||||
|
Option<Field>,
|
||||||
|
Option<LayoutSetting>,
|
||||||
|
Option<FieldSettingsByFieldIdMap>,
|
||||||
|
) {
|
||||||
match self.database_layout {
|
match self.database_layout {
|
||||||
DatabaseLayout::Grid => (None, None),
|
DatabaseLayout::Grid => (None, None, None),
|
||||||
DatabaseLayout::Board => {
|
DatabaseLayout::Board => {
|
||||||
let layout_settings = BoardLayoutSetting::new().into();
|
let layout_settings = BoardLayoutSetting::new().into();
|
||||||
if !self
|
|
||||||
|
let field = if !self
|
||||||
.database
|
.database
|
||||||
.lock()
|
.lock()
|
||||||
.get_fields(None)
|
.get_fields(None)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.any(|field| FieldType::from(field.field_type).can_be_group())
|
.any(|field| FieldType::from(field.field_type).can_be_group())
|
||||||
{
|
{
|
||||||
let select_field = self.create_select_field();
|
Some(self.create_select_field())
|
||||||
(Some(select_field), Some(layout_settings))
|
|
||||||
} else {
|
} 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 => {
|
DatabaseLayout::Calendar => {
|
||||||
match self
|
match self
|
||||||
@ -56,12 +75,12 @@ impl DatabaseLayoutDepsResolver {
|
|||||||
{
|
{
|
||||||
Some(field) => {
|
Some(field) => {
|
||||||
let layout_setting = CalendarLayoutSetting::new(field.id).into();
|
let layout_setting = CalendarLayoutSetting::new(field.id).into();
|
||||||
(None, Some(layout_setting))
|
(None, Some(layout_setting), None)
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
let date_field = self.create_date_field();
|
let date_field = self.create_date_field();
|
||||||
let layout_setting = CalendarLayoutSetting::new(date_field.clone().id).into();
|
let layout_setting = CalendarLayoutSetting::new(date_field.clone().id).into();
|
||||||
(Some(date_field), Some(layout_setting))
|
(Some(date_field), Some(layout_setting), None)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -376,9 +376,8 @@ impl FolderManager {
|
|||||||
let view_layout: ViewLayout = params.layout.clone().into();
|
let view_layout: ViewLayout = params.layout.clone().into();
|
||||||
let handler = self.get_handler(&view_layout)?;
|
let handler = self.get_handler(&view_layout)?;
|
||||||
let user_id = self.user.user_id()?;
|
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");
|
tracing::trace!("Create view with build-in data");
|
||||||
handler
|
handler
|
||||||
.create_built_in_view(user_id, ¶ms.view_id, ¶ms.name, view_layout.clone())
|
.create_built_in_view(user_id, ¶ms.view_id, ¶ms.name, view_layout.clone())
|
||||||
@ -386,14 +385,7 @@ impl FolderManager {
|
|||||||
} else {
|
} else {
|
||||||
tracing::trace!("Create view with view data");
|
tracing::trace!("Create view with view data");
|
||||||
handler
|
handler
|
||||||
.create_view_with_view_data(
|
.create_view_with_view_data(user_id, params.clone())
|
||||||
user_id,
|
|
||||||
¶ms.view_id,
|
|
||||||
¶ms.name,
|
|
||||||
params.initial_data.clone(),
|
|
||||||
view_layout.clone(),
|
|
||||||
meta,
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,11 +63,7 @@ pub trait FolderOperationHandler {
|
|||||||
fn create_view_with_view_data(
|
fn create_view_with_view_data(
|
||||||
&self,
|
&self,
|
||||||
user_id: i64,
|
user_id: i64,
|
||||||
view_id: &str,
|
params: CreateViewParams,
|
||||||
name: &str,
|
|
||||||
data: Vec<u8>,
|
|
||||||
layout: ViewLayout,
|
|
||||||
meta: HashMap<String, String>,
|
|
||||||
) -> FutureResult<(), FlowyError>;
|
) -> FutureResult<(), FlowyError>;
|
||||||
|
|
||||||
/// Create a view with the pre-defined data.
|
/// Create a view with the pre-defined data.
|
||||||
|
Loading…
Reference in New Issue
Block a user