mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
refactor: hide ungrouped feature (#3817)
* refactor: remove unused notification and listener * revert: remove hide_ungrouped from group settings * chore: add board layout setting * chore: listen to layout settings on ui * fix: duplicated group controller initialization * chore: add a tooltip to the ungrouped items button * chore: trailing comma
This commit is contained in:
@ -0,0 +1,25 @@
|
||||
use flowy_derive::ProtoBuf;
|
||||
|
||||
use crate::services::setting::BoardLayoutSetting;
|
||||
|
||||
#[derive(Debug, Clone, Default, Eq, PartialEq, ProtoBuf)]
|
||||
pub struct BoardLayoutSettingPB {
|
||||
#[pb(index = 1)]
|
||||
pub hide_ungrouped_column: bool,
|
||||
}
|
||||
|
||||
impl From<BoardLayoutSetting> for BoardLayoutSettingPB {
|
||||
fn from(setting: BoardLayoutSetting) -> Self {
|
||||
Self {
|
||||
hide_ungrouped_column: setting.hide_ungrouped_column,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BoardLayoutSettingPB> for BoardLayoutSetting {
|
||||
fn from(setting: BoardLayoutSettingPB) -> Self {
|
||||
Self {
|
||||
hide_ungrouped_column: setting.hide_ungrouped_column,
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ use flowy_error::ErrorCode;
|
||||
|
||||
use crate::entities::parser::NotEmptyStr;
|
||||
use crate::entities::{FieldType, RowMetaPB};
|
||||
use crate::services::group::{GroupChangeset, GroupData, GroupSetting, GroupSettingChangeset};
|
||||
use crate::services::group::{GroupChangeset, GroupData, GroupSetting};
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct GroupSettingPB {
|
||||
@ -14,9 +14,6 @@ pub struct GroupSettingPB {
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub field_id: String,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub hide_ungrouped: bool,
|
||||
}
|
||||
|
||||
impl std::convert::From<&GroupSetting> for GroupSettingPB {
|
||||
@ -24,7 +21,6 @@ impl std::convert::From<&GroupSetting> for GroupSettingPB {
|
||||
GroupSettingPB {
|
||||
id: rev.id.clone(),
|
||||
field_id: rev.field_id.clone(),
|
||||
hide_ungrouped: rev.hide_ungrouped,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -52,26 +48,6 @@ impl std::convert::From<Vec<GroupSetting>> for RepeatedGroupSettingPB {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, ProtoBuf)]
|
||||
pub struct GroupSettingChangesetPB {
|
||||
#[pb(index = 1)]
|
||||
pub view_id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub group_configuration_id: String,
|
||||
|
||||
#[pb(index = 3, one_of)]
|
||||
pub hide_ungrouped: Option<bool>,
|
||||
}
|
||||
|
||||
impl From<GroupSettingChangesetPB> for GroupSettingChangeset {
|
||||
fn from(value: GroupSettingChangesetPB) -> Self {
|
||||
Self {
|
||||
hide_ungrouped: value.hide_ungrouped,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct RepeatedGroupPB {
|
||||
#[pb(index = 1)]
|
||||
|
@ -1,3 +1,4 @@
|
||||
mod board_entities;
|
||||
mod calendar_entities;
|
||||
mod cell_entities;
|
||||
mod database_entities;
|
||||
@ -16,6 +17,7 @@ mod macros;
|
||||
mod share_entities;
|
||||
mod type_option_entities;
|
||||
|
||||
pub use board_entities::*;
|
||||
pub use calendar_entities::*;
|
||||
pub use cell_entities::*;
|
||||
pub use database_entities::*;
|
||||
|
@ -13,7 +13,9 @@ use crate::entities::{
|
||||
RepeatedSortPB, UpdateFilterParams, UpdateFilterPayloadPB, UpdateGroupPB, UpdateSortParams,
|
||||
UpdateSortPayloadPB,
|
||||
};
|
||||
use crate::services::setting::CalendarLayoutSetting;
|
||||
use crate::services::setting::{BoardLayoutSetting, CalendarLayoutSetting};
|
||||
|
||||
use super::BoardLayoutSettingPB;
|
||||
|
||||
/// [DatabaseViewSettingPB] defines the setting options for the grid. Such as the filter, group, and sort.
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
@ -151,19 +153,51 @@ pub struct DatabaseLayoutSettingPB {
|
||||
pub layout_type: DatabaseLayoutPB,
|
||||
|
||||
#[pb(index = 2, one_of)]
|
||||
pub board: Option<BoardLayoutSettingPB>,
|
||||
|
||||
#[pb(index = 3, one_of)]
|
||||
pub calendar: Option<CalendarLayoutSettingPB>,
|
||||
}
|
||||
|
||||
impl DatabaseLayoutSettingPB {
|
||||
pub fn from_board(layout_setting: BoardLayoutSetting) -> Self {
|
||||
Self {
|
||||
layout_type: DatabaseLayoutPB::Board,
|
||||
board: Some(layout_setting.into()),
|
||||
calendar: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_calendar(layout_setting: CalendarLayoutSetting) -> Self {
|
||||
Self {
|
||||
layout_type: DatabaseLayoutPB::Calendar,
|
||||
calendar: Some(layout_setting.into()),
|
||||
board: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct LayoutSettingParams {
|
||||
pub layout_type: DatabaseLayout,
|
||||
pub board: Option<BoardLayoutSetting>,
|
||||
pub calendar: Option<CalendarLayoutSetting>,
|
||||
}
|
||||
|
||||
impl LayoutSettingParams {
|
||||
pub fn new(layout_type: DatabaseLayout) -> Self {
|
||||
Self {
|
||||
layout_type,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LayoutSettingParams> for DatabaseLayoutSettingPB {
|
||||
fn from(data: LayoutSettingParams) -> Self {
|
||||
Self {
|
||||
layout_type: data.layout_type.into(),
|
||||
board: data.board.map(|board| board.into()),
|
||||
calendar: data.calendar.map(|calendar| calendar.into()),
|
||||
}
|
||||
}
|
||||
@ -178,6 +212,9 @@ pub struct LayoutSettingChangesetPB {
|
||||
pub layout_type: DatabaseLayoutPB,
|
||||
|
||||
#[pb(index = 3, one_of)]
|
||||
pub board: Option<BoardLayoutSettingPB>,
|
||||
|
||||
#[pb(index = 4, one_of)]
|
||||
pub calendar: Option<CalendarLayoutSettingPB>,
|
||||
}
|
||||
|
||||
@ -185,9 +222,17 @@ pub struct LayoutSettingChangesetPB {
|
||||
pub struct LayoutSettingChangeset {
|
||||
pub view_id: String,
|
||||
pub layout_type: DatabaseLayout,
|
||||
pub board: Option<BoardLayoutSetting>,
|
||||
pub calendar: Option<CalendarLayoutSetting>,
|
||||
}
|
||||
|
||||
impl LayoutSettingChangeset {
|
||||
pub fn is_valid(&self) -> bool {
|
||||
self.board.is_some() && self.layout_type == DatabaseLayout::Board
|
||||
|| self.calendar.is_some() && self.layout_type == DatabaseLayout::Calendar
|
||||
}
|
||||
}
|
||||
|
||||
impl TryInto<LayoutSettingChangeset> for LayoutSettingChangesetPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
@ -199,7 +244,8 @@ impl TryInto<LayoutSettingChangeset> for LayoutSettingChangesetPB {
|
||||
Ok(LayoutSettingChangeset {
|
||||
view_id,
|
||||
layout_type: self.layout_type.into(),
|
||||
calendar: self.calendar.map(|calendar| calendar.into()),
|
||||
board: self.board.map(Into::into),
|
||||
calendar: self.calendar.map(Into::into),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -646,36 +646,6 @@ pub(crate) async fn update_date_cell_handler(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||
pub(crate) async fn get_group_configurations_handler(
|
||||
data: AFPluginData<DatabaseViewIdPB>,
|
||||
manager: AFPluginState<Weak<DatabaseManager>>,
|
||||
) -> DataResult<RepeatedGroupSettingPB, FlowyError> {
|
||||
let manager = upgrade_manager(manager)?;
|
||||
let params = data.into_inner();
|
||||
let database_editor = manager.get_database_with_view_id(params.as_ref()).await?;
|
||||
let group_configs = database_editor
|
||||
.get_group_configuration_settings(params.as_ref())
|
||||
.await?;
|
||||
data_result_ok(group_configs.into())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||
pub(crate) async fn update_group_configuration_handler(
|
||||
data: AFPluginData<GroupSettingChangesetPB>,
|
||||
manager: AFPluginState<Weak<DatabaseManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let manager = upgrade_manager(manager)?;
|
||||
let params = data.into_inner();
|
||||
let view_id = params.view_id.clone();
|
||||
let database_editor = manager.get_database_with_view_id(&view_id).await?;
|
||||
database_editor
|
||||
.update_group_configuration_setting(&view_id, params.into())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||
pub(crate) async fn get_groups_handler(
|
||||
data: AFPluginData<DatabaseViewIdPB>,
|
||||
@ -786,15 +756,11 @@ pub(crate) async fn set_layout_setting_handler(
|
||||
manager: AFPluginState<Weak<DatabaseManager>>,
|
||||
) -> FlowyResult<()> {
|
||||
let manager = upgrade_manager(manager)?;
|
||||
let params: LayoutSettingChangeset = data.into_inner().try_into()?;
|
||||
let database_editor = manager.get_database_with_view_id(¶ms.view_id).await?;
|
||||
let layout_params = LayoutSettingParams {
|
||||
layout_type: params.layout_type,
|
||||
calendar: params.calendar,
|
||||
};
|
||||
database_editor
|
||||
.set_layout_setting(¶ms.view_id, layout_params)
|
||||
.await;
|
||||
let changeset = data.into_inner();
|
||||
let view_id = changeset.view_id.clone();
|
||||
let params: LayoutSettingChangeset = changeset.try_into()?;
|
||||
let database_editor = manager.get_database_with_view_id(&view_id).await?;
|
||||
database_editor.set_layout_setting(&view_id, params).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -54,8 +54,6 @@ pub fn init(database_manager: Weak<DatabaseManager>) -> AFPlugin {
|
||||
// Date
|
||||
.event(DatabaseEvent::UpdateDateCell, update_date_cell_handler)
|
||||
// Group
|
||||
.event(DatabaseEvent::GetGroupConfigurations, get_group_configurations_handler)
|
||||
.event(DatabaseEvent::UpdateGroupConfiguration, update_group_configuration_handler)
|
||||
.event(DatabaseEvent::SetGroupByField, set_group_by_field_handler)
|
||||
.event(DatabaseEvent::MoveGroup, move_group_handler)
|
||||
.event(DatabaseEvent::MoveGroupRow, move_group_row_handler)
|
||||
@ -266,14 +264,10 @@ pub enum DatabaseEvent {
|
||||
#[event(input = "DateChangesetPB")]
|
||||
UpdateDateCell = 80,
|
||||
|
||||
#[event(input = "DatabaseViewIdPB", output = "RepeatedGroupSettingPB")]
|
||||
GetGroupConfigurations = 90,
|
||||
|
||||
#[event(input = "GroupSettingChangesetPB")]
|
||||
UpdateGroupConfiguration = 91,
|
||||
|
||||
/// [SetGroupByField] event is used to create a new grouping in a database
|
||||
/// view based on the `field_id`
|
||||
#[event(input = "GroupByFieldPayloadPB")]
|
||||
SetGroupByField = 92,
|
||||
SetGroupByField = 90,
|
||||
|
||||
#[event(input = "DatabaseViewIdPB", output = "RepeatedGroupPB")]
|
||||
GetGroups = 100,
|
||||
|
@ -20,8 +20,6 @@ pub enum DatabaseNotification {
|
||||
DidUpdateCell = 40,
|
||||
/// Trigger after editing a field properties including rename,update type option, etc
|
||||
DidUpdateField = 50,
|
||||
/// Trigger after the group configuration is changed
|
||||
DidUpdateGroupConfiguration = 59,
|
||||
/// Trigger after the number of groups is changed
|
||||
DidUpdateNumOfGroups = 60,
|
||||
/// Trigger after inserting/deleting/updating/moving a row
|
||||
@ -42,18 +40,16 @@ pub enum DatabaseNotification {
|
||||
DidUpdateSettings = 70,
|
||||
// Trigger when the layout setting of the database is updated
|
||||
DidUpdateLayoutSettings = 80,
|
||||
// Trigger when the layout field of the database is changed
|
||||
DidSetNewLayoutField = 81,
|
||||
// Trigger when the layout of the database is changed
|
||||
DidUpdateDatabaseLayout = 82,
|
||||
DidUpdateDatabaseLayout = 81,
|
||||
// Trigger when the database view is deleted
|
||||
DidDeleteDatabaseView = 83,
|
||||
DidDeleteDatabaseView = 82,
|
||||
// Trigger when the database view is moved to trash
|
||||
DidMoveDatabaseViewToTrash = 84,
|
||||
DidUpdateDatabaseSyncUpdate = 85,
|
||||
DidUpdateDatabaseSnapshotState = 86,
|
||||
DidMoveDatabaseViewToTrash = 83,
|
||||
DidUpdateDatabaseSyncUpdate = 84,
|
||||
DidUpdateDatabaseSnapshotState = 85,
|
||||
// Trigger when the field setting is changed
|
||||
DidUpdateFieldSettings = 87,
|
||||
DidUpdateFieldSettings = 86,
|
||||
}
|
||||
|
||||
impl std::convert::From<DatabaseNotification> for i32 {
|
||||
@ -71,7 +67,6 @@ impl std::convert::From<i32> for DatabaseNotification {
|
||||
22 => DatabaseNotification::DidUpdateFields,
|
||||
40 => DatabaseNotification::DidUpdateCell,
|
||||
50 => DatabaseNotification::DidUpdateField,
|
||||
59 => DatabaseNotification::DidUpdateGroupConfiguration,
|
||||
60 => DatabaseNotification::DidUpdateNumOfGroups,
|
||||
61 => DatabaseNotification::DidUpdateGroupRow,
|
||||
62 => DatabaseNotification::DidGroupByField,
|
||||
@ -82,7 +77,6 @@ impl std::convert::From<i32> for DatabaseNotification {
|
||||
67 => DatabaseNotification::DidUpdateRowMeta,
|
||||
70 => DatabaseNotification::DidUpdateSettings,
|
||||
80 => DatabaseNotification::DidUpdateLayoutSettings,
|
||||
81 => DatabaseNotification::DidSetNewLayoutField,
|
||||
82 => DatabaseNotification::DidUpdateDatabaseLayout,
|
||||
83 => DatabaseNotification::DidDeleteDatabaseView,
|
||||
84 => DatabaseNotification::DidMoveDatabaseViewToTrash,
|
||||
|
@ -34,9 +34,7 @@ use crate::services::field_settings::{
|
||||
default_field_settings_by_layout_map, FieldSettings, FieldSettingsChangesetParams,
|
||||
};
|
||||
use crate::services::filter::Filter;
|
||||
use crate::services::group::{
|
||||
default_group_setting, GroupChangesets, GroupSetting, GroupSettingChangeset, RowChangeset,
|
||||
};
|
||||
use crate::services::group::{default_group_setting, GroupChangesets, GroupSetting, RowChangeset};
|
||||
use crate::services::share::csv::{CSVExport, CSVFormat};
|
||||
use crate::services::sort::Sort;
|
||||
|
||||
@ -870,40 +868,6 @@ impl DatabaseEditor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_group_configuration_settings(
|
||||
&self,
|
||||
view_id: &str,
|
||||
) -> FlowyResult<Vec<GroupSettingPB>> {
|
||||
let view = self.database_views.get_view_editor(view_id).await?;
|
||||
|
||||
let group_settings = view
|
||||
.v_get_group_configuration_settings()
|
||||
.await
|
||||
.into_iter()
|
||||
.map(|value| GroupSettingPB::from(&value))
|
||||
.collect::<Vec<GroupSettingPB>>();
|
||||
|
||||
Ok(group_settings)
|
||||
}
|
||||
|
||||
pub async fn update_group_configuration_setting(
|
||||
&self,
|
||||
view_id: &str,
|
||||
changeset: GroupSettingChangeset,
|
||||
) -> FlowyResult<()> {
|
||||
let view = self.database_views.get_view_editor(view_id).await?;
|
||||
let group_configuration = view.v_update_group_configuration_setting(changeset).await?;
|
||||
|
||||
if let Some(configuration) = group_configuration {
|
||||
let payload: RepeatedGroupSettingPB = vec![configuration].into();
|
||||
send_notification(view_id, DatabaseNotification::DidUpdateGroupConfiguration)
|
||||
.payload(payload)
|
||||
.send();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||
pub async fn load_groups(&self, view_id: &str) -> FlowyResult<RepeatedGroupPB> {
|
||||
let view = self.database_views.get_view_editor(view_id).await?;
|
||||
@ -994,11 +958,15 @@ impl DatabaseEditor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn set_layout_setting(&self, view_id: &str, layout_setting: LayoutSettingParams) {
|
||||
tracing::trace!("set_layout_setting: {:?}", layout_setting);
|
||||
if let Ok(view) = self.database_views.get_view_editor(view_id).await {
|
||||
let _ = view.v_set_layout_settings(layout_setting).await;
|
||||
};
|
||||
#[tracing::instrument(level = "trace", skip_all)]
|
||||
pub async fn set_layout_setting(
|
||||
&self,
|
||||
view_id: &str,
|
||||
layout_setting: LayoutSettingChangeset,
|
||||
) -> FlowyResult<()> {
|
||||
let view_editor = self.database_views.get_view_editor(view_id).await?;
|
||||
view_editor.v_set_layout_settings(layout_setting).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_layout_setting(
|
||||
|
@ -1,23 +1,27 @@
|
||||
use collab_database::views::DatabaseView;
|
||||
use collab_database::views::{DatabaseLayout, DatabaseView};
|
||||
|
||||
use crate::entities::{
|
||||
CalendarLayoutSettingPB, DatabaseLayoutPB, DatabaseLayoutSettingPB, DatabaseViewSettingPB,
|
||||
FieldSettingsPB, FilterPB, GroupSettingPB, SortPB,
|
||||
DatabaseLayoutPB, DatabaseLayoutSettingPB, DatabaseViewSettingPB, FieldSettingsPB, FilterPB,
|
||||
GroupSettingPB, SortPB,
|
||||
};
|
||||
use crate::services::field_settings::FieldSettings;
|
||||
use crate::services::filter::Filter;
|
||||
use crate::services::group::GroupSetting;
|
||||
use crate::services::setting::CalendarLayoutSetting;
|
||||
use crate::services::sort::Sort;
|
||||
|
||||
pub(crate) fn database_view_setting_pb_from_view(view: DatabaseView) -> DatabaseViewSettingPB {
|
||||
let layout_type: DatabaseLayoutPB = view.layout.into();
|
||||
let layout_setting = if let Some(layout_setting) = view.layout_settings.get(&view.layout) {
|
||||
let calendar_setting =
|
||||
CalendarLayoutSettingPB::from(CalendarLayoutSetting::from(layout_setting.clone()));
|
||||
DatabaseLayoutSettingPB {
|
||||
layout_type: layout_type.clone(),
|
||||
calendar: Some(calendar_setting),
|
||||
match view.layout {
|
||||
DatabaseLayout::Board => {
|
||||
let board_setting = layout_setting.clone().into();
|
||||
DatabaseLayoutSettingPB::from_board(board_setting)
|
||||
},
|
||||
DatabaseLayout::Calendar => {
|
||||
let calendar_setting = layout_setting.clone().into();
|
||||
DatabaseLayoutSettingPB::from_calendar(calendar_setting)
|
||||
},
|
||||
_ => DatabaseLayoutSettingPB::default(),
|
||||
}
|
||||
} else {
|
||||
DatabaseLayoutSettingPB::default()
|
||||
|
@ -6,7 +6,7 @@ use std::sync::Arc;
|
||||
use crate::entities::FieldType;
|
||||
use crate::services::field::{DateTypeOption, SingleSelectTypeOption};
|
||||
use crate::services::field_settings::default_field_settings_by_layout_map;
|
||||
use crate::services::setting::CalendarLayoutSetting;
|
||||
use crate::services::setting::{BoardLayoutSetting, CalendarLayoutSetting};
|
||||
|
||||
/// When creating a database, we need to resolve the dependencies of the views.
|
||||
/// Different database views have different dependencies. For example, a board
|
||||
@ -32,6 +32,7 @@ impl DatabaseLayoutDepsResolver {
|
||||
match self.database_layout {
|
||||
DatabaseLayout::Grid => (None, None),
|
||||
DatabaseLayout::Board => {
|
||||
let layout_settings = BoardLayoutSetting::new().into();
|
||||
if !self
|
||||
.database
|
||||
.lock()
|
||||
@ -40,9 +41,9 @@ impl DatabaseLayoutDepsResolver {
|
||||
.any(|field| FieldType::from(field.field_type).can_be_group())
|
||||
{
|
||||
let select_field = self.create_select_field();
|
||||
(Some(select_field), None)
|
||||
(Some(select_field), Some(layout_settings))
|
||||
} else {
|
||||
(None, None)
|
||||
(None, Some(layout_settings))
|
||||
}
|
||||
},
|
||||
DatabaseLayout::Calendar => {
|
||||
@ -74,7 +75,9 @@ impl DatabaseLayoutDepsResolver {
|
||||
// Insert the layout setting if it's not exist
|
||||
match &self.database_layout {
|
||||
DatabaseLayout::Grid => {},
|
||||
DatabaseLayout::Board => {},
|
||||
DatabaseLayout::Board => {
|
||||
self.create_board_layout_setting_if_need(view_id);
|
||||
},
|
||||
DatabaseLayout::Calendar => {
|
||||
let date_field_id = match fields
|
||||
.into_iter()
|
||||
@ -97,6 +100,21 @@ impl DatabaseLayoutDepsResolver {
|
||||
}
|
||||
}
|
||||
|
||||
fn create_board_layout_setting_if_need(&self, view_id: &str) {
|
||||
if self
|
||||
.database
|
||||
.lock()
|
||||
.get_layout_setting::<BoardLayoutSetting>(view_id, &self.database_layout)
|
||||
.is_none()
|
||||
{
|
||||
let layout_setting = BoardLayoutSetting::new();
|
||||
self
|
||||
.database
|
||||
.lock()
|
||||
.insert_layout_setting(view_id, &self.database_layout, layout_setting);
|
||||
}
|
||||
}
|
||||
|
||||
fn create_calendar_layout_setting_if_need(&self, view_id: &str, field_id: &str) {
|
||||
if self
|
||||
.database
|
||||
|
@ -13,8 +13,8 @@ use flowy_error::{FlowyError, FlowyResult};
|
||||
use crate::entities::{
|
||||
CalendarEventPB, DatabaseLayoutMetaPB, DatabaseLayoutSettingPB, DeleteFilterParams,
|
||||
DeleteGroupParams, DeleteSortParams, FieldType, FieldVisibility, GroupChangesPB, GroupPB,
|
||||
GroupRowsNotificationPB, InsertedRowPB, LayoutSettingParams, RowMetaPB, RowsChangePB,
|
||||
SortChangesetNotificationPB, SortPB, UpdateFilterParams, UpdateSortParams,
|
||||
GroupRowsNotificationPB, InsertedRowPB, LayoutSettingChangeset, LayoutSettingParams, RowMetaPB,
|
||||
RowsChangePB, SortChangesetNotificationPB, SortPB, UpdateFilterParams, UpdateSortParams,
|
||||
};
|
||||
use crate::notification::{send_notification, DatabaseNotification};
|
||||
use crate::services::cell::CellCache;
|
||||
@ -34,10 +34,7 @@ use crate::services::field_settings::FieldSettings;
|
||||
use crate::services::filter::{
|
||||
Filter, FilterChangeset, FilterController, FilterType, UpdatedFilterType,
|
||||
};
|
||||
use crate::services::group::{
|
||||
GroupChangesets, GroupController, GroupSetting, GroupSettingChangeset, MoveGroupRowContext,
|
||||
RowChangeset,
|
||||
};
|
||||
use crate::services::group::{GroupChangesets, GroupController, MoveGroupRowContext, RowChangeset};
|
||||
use crate::services::setting::CalendarLayoutSetting;
|
||||
use crate::services::sort::{DeletedSortType, Sort, SortChangeset, SortController, SortType};
|
||||
|
||||
@ -377,19 +374,6 @@ impl DatabaseViewEditor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn v_update_group_configuration_setting(
|
||||
&self,
|
||||
changeset: GroupSettingChangeset,
|
||||
) -> FlowyResult<Option<GroupSetting>> {
|
||||
let result = self
|
||||
.mut_group_controller(|group_controller, _| {
|
||||
group_controller.apply_group_configuration_setting_changeset(changeset)
|
||||
})
|
||||
.await;
|
||||
|
||||
Ok(result.flatten())
|
||||
}
|
||||
|
||||
pub async fn v_update_group(&self, changeset: GroupChangesets) -> FlowyResult<()> {
|
||||
let mut type_option_data = TypeOptionData::new();
|
||||
let old_field = if let Some(controller) = self.group_controller.write().await.as_mut() {
|
||||
@ -412,9 +396,6 @@ impl DatabaseViewEditor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn v_get_group_configuration_settings(&self) -> Vec<GroupSetting> {
|
||||
self.delegate.get_group_setting(&self.view_id)
|
||||
}
|
||||
pub async fn v_get_all_sorts(&self) -> Vec<Sort> {
|
||||
self.delegate.get_all_sorts(&self.view_id)
|
||||
}
|
||||
@ -550,7 +531,11 @@ impl DatabaseViewEditor {
|
||||
let mut layout_setting = LayoutSettingParams::default();
|
||||
match layout_ty {
|
||||
DatabaseLayout::Grid => {},
|
||||
DatabaseLayout::Board => {},
|
||||
DatabaseLayout::Board => {
|
||||
if let Some(value) = self.delegate.get_layout_setting(&self.view_id, layout_ty) {
|
||||
layout_setting.board = Some(value.into());
|
||||
}
|
||||
},
|
||||
DatabaseLayout::Calendar => {
|
||||
if let Some(value) = self.delegate.get_layout_setting(&self.view_id, layout_ty) {
|
||||
let calendar_setting = CalendarLayoutSetting::from(value);
|
||||
@ -574,48 +559,50 @@ impl DatabaseViewEditor {
|
||||
layout_setting
|
||||
}
|
||||
|
||||
/// Update the calendar settings and send the notification to refresh the UI
|
||||
pub async fn v_set_layout_settings(&self, params: LayoutSettingParams) -> FlowyResult<()> {
|
||||
// Maybe it needs no send notification to refresh the UI
|
||||
if let Some(new_calendar_setting) = params.calendar {
|
||||
if let Some(field) = self.delegate.get_field(&new_calendar_setting.field_id) {
|
||||
let field_type = FieldType::from(field.field_type);
|
||||
if field_type != FieldType::DateTime {
|
||||
return Err(FlowyError::unexpect_calendar_field_type());
|
||||
}
|
||||
/// Update the layout settings and send the notification to refresh the UI
|
||||
pub async fn v_set_layout_settings(&self, params: LayoutSettingChangeset) -> FlowyResult<()> {
|
||||
if self.v_get_layout_type().await != params.layout_type || !params.is_valid() {
|
||||
return Err(FlowyError::invalid_data());
|
||||
}
|
||||
|
||||
let old_calender_setting = self
|
||||
.v_get_layout_settings(¶ms.layout_type)
|
||||
.await
|
||||
.calendar;
|
||||
let layout_setting_pb = match params.layout_type {
|
||||
DatabaseLayout::Board => {
|
||||
let layout_setting = params.board.unwrap();
|
||||
|
||||
self.delegate.insert_layout_setting(
|
||||
&self.view_id,
|
||||
¶ms.layout_type,
|
||||
new_calendar_setting.clone().into(),
|
||||
layout_setting.clone().into(),
|
||||
);
|
||||
let new_field_id = new_calendar_setting.field_id.clone();
|
||||
let layout_setting_pb: DatabaseLayoutSettingPB = LayoutSettingParams {
|
||||
layout_type: params.layout_type,
|
||||
calendar: Some(new_calendar_setting),
|
||||
}
|
||||
.into();
|
||||
|
||||
if let Some(old_calendar_setting) = old_calender_setting {
|
||||
// compare the new layout field id is equal to old layout field id
|
||||
// if not equal, send the DidSetNewLayoutField notification
|
||||
// if equal, send the DidUpdateLayoutSettings notification
|
||||
if old_calendar_setting.field_id != new_field_id {
|
||||
send_notification(&self.view_id, DatabaseNotification::DidSetNewLayoutField)
|
||||
.payload(layout_setting_pb.clone())
|
||||
.send();
|
||||
Some(DatabaseLayoutSettingPB::from_board(layout_setting))
|
||||
},
|
||||
DatabaseLayout::Calendar => {
|
||||
let layout_setting = params.calendar.unwrap();
|
||||
|
||||
if let Some(field) = self.delegate.get_field(&layout_setting.field_id) {
|
||||
if FieldType::from(field.field_type) != FieldType::DateTime {
|
||||
return Err(FlowyError::unexpect_calendar_field_type());
|
||||
}
|
||||
}
|
||||
|
||||
send_notification(&self.view_id, DatabaseNotification::DidUpdateLayoutSettings)
|
||||
.payload(layout_setting_pb)
|
||||
.send();
|
||||
}
|
||||
self.delegate.insert_layout_setting(
|
||||
&self.view_id,
|
||||
¶ms.layout_type,
|
||||
layout_setting.clone().into(),
|
||||
);
|
||||
|
||||
Some(DatabaseLayoutSettingPB::from_calendar(layout_setting))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(payload) = layout_setting_pb {
|
||||
send_notification(&self.view_id, DatabaseNotification::DidUpdateLayoutSettings)
|
||||
.payload(payload)
|
||||
.send();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -6,10 +6,7 @@ use flowy_error::FlowyResult;
|
||||
|
||||
use crate::entities::{GroupChangesPB, GroupPB, GroupRowsNotificationPB, InsertedGroupPB};
|
||||
use crate::services::field::TypeOption;
|
||||
use crate::services::group::entities::GroupSetting;
|
||||
use crate::services::group::{
|
||||
GroupChangesets, GroupData, GroupSettingChangeset, MoveGroupRowContext,
|
||||
};
|
||||
use crate::services::group::{GroupChangesets, GroupData, MoveGroupRowContext};
|
||||
|
||||
/// Using polymorphism to provides the customs action for different group controller.
|
||||
///
|
||||
@ -119,11 +116,6 @@ pub trait GroupControllerOperation: Send + Sync {
|
||||
&mut self,
|
||||
changeset: &GroupChangesets,
|
||||
) -> FlowyResult<TypeOptionData>;
|
||||
|
||||
fn apply_group_configuration_setting_changeset(
|
||||
&mut self,
|
||||
changeset: GroupSettingChangeset,
|
||||
) -> FlowyResult<Option<GroupSetting>>;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -18,7 +18,6 @@ use crate::entities::{GroupChangesPB, GroupPB, InsertedGroupPB};
|
||||
use crate::services::field::RowSingleCellData;
|
||||
use crate::services::group::{
|
||||
default_group_setting, GeneratedGroups, Group, GroupChangeset, GroupData, GroupSetting,
|
||||
GroupSettingChangeset,
|
||||
};
|
||||
|
||||
pub trait GroupSettingReader: Send + Sync + 'static {
|
||||
@ -390,20 +389,6 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn update_configuration(
|
||||
&mut self,
|
||||
changeset: GroupSettingChangeset,
|
||||
) -> FlowyResult<Option<GroupSetting>> {
|
||||
self.mut_configuration(|configuration| match changeset.hide_ungrouped {
|
||||
Some(value) if value != configuration.hide_ungrouped => {
|
||||
configuration.hide_ungrouped = value;
|
||||
true
|
||||
},
|
||||
_ => false,
|
||||
})?;
|
||||
Ok(Some(GroupSetting::clone(&self.setting)))
|
||||
}
|
||||
|
||||
pub(crate) async fn get_all_cells(&self) -> Vec<RowSingleCellData> {
|
||||
self
|
||||
.reader
|
||||
@ -432,9 +417,7 @@ where
|
||||
let view_id = self.view_id.clone();
|
||||
tokio::spawn(async move {
|
||||
match writer.save_configuration(&view_id, configuration).await {
|
||||
Ok(_) => {
|
||||
tracing::trace!("SUCCESSFULLY SAVED CONFIGURATION"); // TODO(richard): remove this
|
||||
},
|
||||
Ok(_) => {},
|
||||
Err(e) => {
|
||||
tracing::error!("Save group configuration failed: {}", e);
|
||||
},
|
||||
|
@ -19,10 +19,8 @@ use crate::services::group::action::{
|
||||
DidMoveGroupRowResult, DidUpdateGroupRowResult, GroupControllerOperation, GroupCustomize,
|
||||
};
|
||||
use crate::services::group::configuration::GroupContext;
|
||||
use crate::services::group::entities::{GroupData, GroupSetting};
|
||||
use crate::services::group::{
|
||||
GroupChangeset, GroupChangesets, GroupSettingChangeset, GroupsBuilder, MoveGroupRowContext,
|
||||
};
|
||||
use crate::services::group::entities::GroupData;
|
||||
use crate::services::group::{GroupChangeset, GroupChangesets, GroupsBuilder, MoveGroupRowContext};
|
||||
|
||||
// use collab_database::views::Group;
|
||||
|
||||
@ -361,13 +359,6 @@ where
|
||||
}
|
||||
Ok(type_option_data)
|
||||
}
|
||||
|
||||
fn apply_group_configuration_setting_changeset(
|
||||
&mut self,
|
||||
changeset: GroupSettingChangeset,
|
||||
) -> FlowyResult<Option<GroupSetting>> {
|
||||
self.context.update_configuration(changeset)
|
||||
}
|
||||
}
|
||||
|
||||
struct GroupedRow {
|
||||
|
@ -10,10 +10,7 @@ use crate::entities::GroupChangesPB;
|
||||
use crate::services::group::action::{
|
||||
DidMoveGroupRowResult, DidUpdateGroupRowResult, GroupControllerOperation,
|
||||
};
|
||||
use crate::services::group::{
|
||||
GroupChangesets, GroupController, GroupData, GroupSetting, GroupSettingChangeset,
|
||||
MoveGroupRowContext,
|
||||
};
|
||||
use crate::services::group::{GroupChangesets, GroupController, GroupData, MoveGroupRowContext};
|
||||
|
||||
/// A [DefaultGroupController] is used to handle the group actions for the [FieldType] that doesn't
|
||||
/// implement its own group controller. The default group controller only contains one group, which
|
||||
@ -110,13 +107,6 @@ impl GroupControllerOperation for DefaultGroupController {
|
||||
) -> FlowyResult<TypeOptionData> {
|
||||
Ok(TypeOptionData::default())
|
||||
}
|
||||
|
||||
fn apply_group_configuration_setting_changeset(
|
||||
&mut self,
|
||||
_changeset: GroupSettingChangeset,
|
||||
) -> FlowyResult<Option<GroupSetting>> {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
impl GroupController for DefaultGroupController {
|
||||
|
@ -12,11 +12,6 @@ pub struct GroupSetting {
|
||||
pub field_type: i64,
|
||||
pub groups: Vec<Group>,
|
||||
pub content: String,
|
||||
pub hide_ungrouped: bool,
|
||||
}
|
||||
|
||||
pub struct GroupSettingChangeset {
|
||||
pub hide_ungrouped: Option<bool>,
|
||||
}
|
||||
|
||||
pub struct GroupChangesets {
|
||||
@ -38,14 +33,13 @@ pub struct GroupChangeset {
|
||||
}
|
||||
|
||||
impl GroupSetting {
|
||||
pub fn new(field_id: String, field_type: i64, content: String, hide_ungrouped: bool) -> Self {
|
||||
pub fn new(field_id: String, field_type: i64, content: String) -> Self {
|
||||
Self {
|
||||
id: gen_database_group_id(),
|
||||
field_id,
|
||||
field_type,
|
||||
groups: vec![],
|
||||
content,
|
||||
hide_ungrouped,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -55,7 +49,6 @@ const FIELD_ID: &str = "field_id";
|
||||
const FIELD_TYPE: &str = "ty";
|
||||
const GROUPS: &str = "groups";
|
||||
const CONTENT: &str = "content";
|
||||
const HIDE_UNGROUPED: &str = "hide_ungrouped";
|
||||
|
||||
impl TryFrom<GroupSettingMap> for GroupSetting {
|
||||
type Error = anyhow::Error;
|
||||
@ -65,9 +58,8 @@ impl TryFrom<GroupSettingMap> for GroupSetting {
|
||||
value.get_str_value(GROUP_ID),
|
||||
value.get_str_value(FIELD_ID),
|
||||
value.get_i64_value(FIELD_TYPE),
|
||||
value.get_bool_value(HIDE_UNGROUPED),
|
||||
) {
|
||||
(Some(id), Some(field_id), Some(field_type), Some(hide_ungrouped)) => {
|
||||
(Some(id), Some(field_id), Some(field_type)) => {
|
||||
let content = value.get_str_value(CONTENT).unwrap_or_default();
|
||||
let groups = value.try_get_array(GROUPS);
|
||||
Ok(Self {
|
||||
@ -76,7 +68,6 @@ impl TryFrom<GroupSettingMap> for GroupSetting {
|
||||
field_type,
|
||||
groups,
|
||||
content,
|
||||
hide_ungrouped,
|
||||
})
|
||||
},
|
||||
_ => {
|
||||
@ -94,7 +85,6 @@ impl From<GroupSetting> for GroupSettingMap {
|
||||
.insert_i64_value(FIELD_TYPE, setting.field_type)
|
||||
.insert_maps(GROUPS, setting.groups)
|
||||
.insert_str_value(CONTENT, setting.content)
|
||||
.insert_bool_value(HIDE_UNGROUPED, setting.hide_ungrouped)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ pub fn find_new_grouping_field(
|
||||
///
|
||||
pub fn default_group_setting(field: &Field) -> GroupSetting {
|
||||
let field_id = field.id.clone();
|
||||
GroupSetting::new(field_id, field.field_type, "".to_owned(), false)
|
||||
GroupSetting::new(field_id, field.field_type, "".to_owned())
|
||||
}
|
||||
|
||||
pub fn make_no_status_group(field: &Field) -> Group {
|
||||
|
@ -8,5 +8,5 @@ mod group_builder;
|
||||
pub(crate) use configuration::*;
|
||||
pub(crate) use controller::*;
|
||||
pub(crate) use controller_impls::*;
|
||||
pub use entities::*;
|
||||
pub(crate) use entities::*;
|
||||
pub(crate) use group_builder::*;
|
||||
|
@ -89,3 +89,32 @@ impl CalendarLayout {
|
||||
pub const DEFAULT_FIRST_DAY_OF_WEEK: i32 = 0;
|
||||
pub const DEFAULT_SHOW_WEEKENDS: bool = true;
|
||||
pub const DEFAULT_SHOW_WEEK_NUMBERS: bool = true;
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct BoardLayoutSetting {
|
||||
pub hide_ungrouped_column: bool,
|
||||
}
|
||||
|
||||
impl BoardLayoutSetting {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LayoutSetting> for BoardLayoutSetting {
|
||||
fn from(setting: LayoutSetting) -> Self {
|
||||
Self {
|
||||
hide_ungrouped_column: setting
|
||||
.get_bool_value("hide_ungrouped_column")
|
||||
.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BoardLayoutSetting> for LayoutSetting {
|
||||
fn from(setting: BoardLayoutSetting) -> Self {
|
||||
LayoutSettingBuilder::new()
|
||||
.insert_bool_value("hide_ungrouped_column", setting.hide_ungrouped_column)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ use crate::services::field::{
|
||||
FieldBuilder, SelectOption, SelectOptionColor, SingleSelectTypeOption,
|
||||
};
|
||||
use crate::services::field_settings::DatabaseFieldSettingsMapBuilder;
|
||||
use crate::services::setting::CalendarLayoutSetting;
|
||||
use crate::services::setting::{BoardLayoutSetting, CalendarLayoutSetting};
|
||||
|
||||
pub fn make_default_grid(view_id: &str, name: &str) -> CreateDatabaseParams {
|
||||
let text_field = FieldBuilder::from_field_type(FieldType::RichText)
|
||||
@ -93,12 +93,15 @@ pub fn make_default_board(view_id: &str, name: &str) -> CreateDatabaseParams {
|
||||
let field_settings =
|
||||
DatabaseFieldSettingsMapBuilder::new(fields.clone(), DatabaseLayout::Board).build();
|
||||
|
||||
let mut layout_settings = LayoutSettings::default();
|
||||
layout_settings.insert(DatabaseLayout::Board, BoardLayoutSetting::new().into());
|
||||
|
||||
CreateDatabaseParams {
|
||||
database_id: gen_database_id(),
|
||||
view_id: view_id.to_string(),
|
||||
name: name.to_string(),
|
||||
layout: DatabaseLayout::Board,
|
||||
layout_settings: Default::default(),
|
||||
layout_settings,
|
||||
filters: vec![],
|
||||
groups: vec![],
|
||||
sorts: vec![],
|
||||
|
@ -28,23 +28,6 @@ async fn group_init_test() {
|
||||
test.run_scripts(scripts).await;
|
||||
}
|
||||
|
||||
// #[tokio::test]
|
||||
// async fn group_configuration_setting_test() {
|
||||
// let mut test = DatabaseGroupTest::new().await;
|
||||
// let scripts = vec![
|
||||
// AssertGroupConfiguration {
|
||||
// hide_ungrouped: false,
|
||||
// },
|
||||
// UpdateGroupConfiguration {
|
||||
// hide_ungrouped: Some(true),
|
||||
// },
|
||||
// AssertGroupConfiguration {
|
||||
// hide_ungrouped: true,
|
||||
// },
|
||||
// ];
|
||||
// test.run_scripts(scripts).await;
|
||||
// }
|
||||
|
||||
#[tokio::test]
|
||||
async fn group_move_row_test() {
|
||||
let mut test = DatabaseGroupTest::new().await;
|
||||
|
@ -1,13 +1,15 @@
|
||||
use collab_database::fields::Field;
|
||||
use collab_database::views::DatabaseLayout;
|
||||
|
||||
use flowy_database2::entities::FieldType;
|
||||
use flowy_database2::services::setting::CalendarLayoutSetting;
|
||||
use flowy_database2::entities::{FieldType, LayoutSettingChangeset, LayoutSettingParams};
|
||||
use flowy_database2::services::setting::{BoardLayoutSetting, CalendarLayoutSetting};
|
||||
|
||||
use crate::database::database_editor::DatabaseEditorTest;
|
||||
|
||||
pub enum LayoutScript {
|
||||
AssertBoardLayoutSetting { expected: BoardLayoutSetting },
|
||||
AssertCalendarLayoutSetting { expected: CalendarLayoutSetting },
|
||||
UpdateBoardLayoutSetting { new_setting: BoardLayoutSetting },
|
||||
AssertDefaultAllCalendarEvents,
|
||||
AssertAllCalendarEventsCount { expected: usize },
|
||||
UpdateDatabaseLayout { layout: DatabaseLayout },
|
||||
@ -23,21 +25,39 @@ impl DatabaseLayoutTest {
|
||||
Self { database_test }
|
||||
}
|
||||
|
||||
pub async fn new_board() -> Self {
|
||||
let database_test = DatabaseEditorTest::new_board().await;
|
||||
Self { database_test }
|
||||
}
|
||||
|
||||
pub async fn new_calendar() -> Self {
|
||||
let database_test = DatabaseEditorTest::new_calendar().await;
|
||||
Self { database_test }
|
||||
}
|
||||
|
||||
pub async fn get_first_date_field(&self) -> Field {
|
||||
self.database_test.get_first_field(FieldType::DateTime)
|
||||
}
|
||||
|
||||
async fn get_layout_setting(
|
||||
&self,
|
||||
view_id: &str,
|
||||
layout_ty: DatabaseLayout,
|
||||
) -> LayoutSettingParams {
|
||||
self
|
||||
.database_test
|
||||
.editor
|
||||
.get_layout_setting(view_id, layout_ty)
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub async fn run_scripts(&mut self, scripts: Vec<LayoutScript>) {
|
||||
for script in scripts {
|
||||
self.run_script(script).await;
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_first_date_field(&self) -> Field {
|
||||
self.database_test.get_first_field(FieldType::DateTime)
|
||||
}
|
||||
|
||||
pub async fn run_script(&mut self, script: LayoutScript) {
|
||||
match script {
|
||||
LayoutScript::UpdateDatabaseLayout { layout } => {
|
||||
@ -56,19 +76,27 @@ impl DatabaseLayoutTest {
|
||||
.await;
|
||||
assert_eq!(events.len(), expected);
|
||||
},
|
||||
LayoutScript::AssertBoardLayoutSetting { expected } => {
|
||||
let view_id = self.database_test.view_id.clone();
|
||||
let layout_ty = DatabaseLayout::Board;
|
||||
|
||||
let layout_settings = self.get_layout_setting(&view_id, layout_ty).await;
|
||||
|
||||
assert!(layout_settings.calendar.is_none());
|
||||
assert_eq!(
|
||||
layout_settings.board.unwrap().hide_ungrouped_column,
|
||||
expected.hide_ungrouped_column
|
||||
);
|
||||
},
|
||||
LayoutScript::AssertCalendarLayoutSetting { expected } => {
|
||||
let view_id = self.database_test.view_id.clone();
|
||||
let layout_ty = DatabaseLayout::Calendar;
|
||||
|
||||
let calendar_setting = self
|
||||
.database_test
|
||||
.editor
|
||||
.get_layout_setting(&view_id, layout_ty)
|
||||
.await
|
||||
.unwrap()
|
||||
.calendar
|
||||
.unwrap();
|
||||
let layout_settings = self.get_layout_setting(&view_id, layout_ty).await;
|
||||
|
||||
assert!(layout_settings.board.is_none());
|
||||
|
||||
let calendar_setting = layout_settings.calendar.unwrap();
|
||||
assert_eq!(calendar_setting.layout_ty, expected.layout_ty);
|
||||
assert_eq!(
|
||||
calendar_setting.first_day_of_week,
|
||||
@ -76,6 +104,20 @@ impl DatabaseLayoutTest {
|
||||
);
|
||||
assert_eq!(calendar_setting.show_weekends, expected.show_weekends);
|
||||
},
|
||||
LayoutScript::UpdateBoardLayoutSetting { new_setting } => {
|
||||
let changeset = LayoutSettingChangeset {
|
||||
view_id: self.database_test.view_id.clone(),
|
||||
layout_type: DatabaseLayout::Board,
|
||||
board: Some(new_setting),
|
||||
calendar: None,
|
||||
};
|
||||
self
|
||||
.database_test
|
||||
.editor
|
||||
.set_layout_setting(&self.database_test.view_id, changeset)
|
||||
.await
|
||||
.unwrap()
|
||||
},
|
||||
LayoutScript::AssertDefaultAllCalendarEvents => {
|
||||
let events = self
|
||||
.database_test
|
||||
|
@ -1,9 +1,31 @@
|
||||
use collab_database::views::DatabaseLayout;
|
||||
use flowy_database2::services::setting::BoardLayoutSetting;
|
||||
use flowy_database2::services::setting::CalendarLayoutSetting;
|
||||
|
||||
use crate::database::layout_test::script::DatabaseLayoutTest;
|
||||
use crate::database::layout_test::script::LayoutScript::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn board_layout_setting_test() {
|
||||
let mut test = DatabaseLayoutTest::new_board().await;
|
||||
let default_board_setting = BoardLayoutSetting::new();
|
||||
let new_board_setting = BoardLayoutSetting {
|
||||
hide_ungrouped_column: true,
|
||||
};
|
||||
let scripts = vec![
|
||||
AssertBoardLayoutSetting {
|
||||
expected: default_board_setting,
|
||||
},
|
||||
UpdateBoardLayoutSetting {
|
||||
new_setting: new_board_setting.clone(),
|
||||
},
|
||||
AssertBoardLayoutSetting {
|
||||
expected: new_board_setting,
|
||||
},
|
||||
];
|
||||
test.run_scripts(scripts).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn calendar_initial_layout_setting_test() {
|
||||
let mut test = DatabaseLayoutTest::new_calendar().await;
|
||||
|
@ -1,6 +1,7 @@
|
||||
use collab_database::database::{gen_database_id, gen_database_view_id, gen_row_id, DatabaseData};
|
||||
use collab_database::views::{DatabaseLayout, DatabaseView};
|
||||
use collab_database::views::{DatabaseLayout, DatabaseView, LayoutSetting, LayoutSettings};
|
||||
use flowy_database2::services::field_settings::DatabaseFieldSettingsMapBuilder;
|
||||
use flowy_database2::services::setting::BoardLayoutSetting;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use flowy_database2::entities::FieldType;
|
||||
@ -128,6 +129,8 @@ pub fn make_test_board() -> DatabaseData {
|
||||
}
|
||||
}
|
||||
|
||||
let board_setting: LayoutSetting = BoardLayoutSetting::new().into();
|
||||
|
||||
let field_settings =
|
||||
DatabaseFieldSettingsMapBuilder::new(fields.clone(), DatabaseLayout::Board).build();
|
||||
|
||||
@ -238,12 +241,15 @@ pub fn make_test_board() -> DatabaseData {
|
||||
rows.push(row);
|
||||
}
|
||||
|
||||
let mut layout_settings = LayoutSettings::new();
|
||||
layout_settings.insert(DatabaseLayout::Board, board_setting);
|
||||
|
||||
let view = DatabaseView {
|
||||
id: gen_database_view_id(),
|
||||
database_id: gen_database_id(),
|
||||
name: "".to_string(),
|
||||
layout: DatabaseLayout::Board,
|
||||
layout_settings: Default::default(),
|
||||
layout_settings,
|
||||
filters: vec![],
|
||||
group_settings: vec![],
|
||||
sorts: vec![],
|
||||
|
Reference in New Issue
Block a user