mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: allow fields to not wrap cell content (#5128)
This commit is contained in:
@ -1,11 +1,13 @@
|
||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||
use flowy_error::ErrorCode;
|
||||
use lib_infra::validator_fn::required_not_empty_str;
|
||||
use std::ops::Deref;
|
||||
use validator::Validate;
|
||||
|
||||
use crate::entities::parser::NotEmptyStr;
|
||||
use crate::entities::RepeatedFieldIdPB;
|
||||
use crate::impl_into_field_visibility;
|
||||
use crate::services::field_settings::{FieldSettings, FieldSettingsChangesetParams};
|
||||
use crate::services::field_settings::FieldSettings;
|
||||
|
||||
/// Defines the field settings for a field in a view.
|
||||
#[derive(Debug, Default, Clone, ProtoBuf, Eq, PartialEq)]
|
||||
@ -18,6 +20,9 @@ pub struct FieldSettingsPB {
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub width: i32,
|
||||
|
||||
#[pb(index = 4)]
|
||||
pub wrap_cell_content: bool,
|
||||
}
|
||||
|
||||
impl From<FieldSettings> for FieldSettingsPB {
|
||||
@ -26,6 +31,7 @@ impl From<FieldSettings> for FieldSettingsPB {
|
||||
field_id: value.field_id,
|
||||
visibility: value.visibility,
|
||||
width: value.width,
|
||||
wrap_cell_content: value.wrap_cell_content,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -93,11 +99,13 @@ impl std::convert::From<Vec<FieldSettingsPB>> for RepeatedFieldSettingsPB {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, ProtoBuf)]
|
||||
#[derive(Debug, Default, Clone, ProtoBuf, Validate)]
|
||||
pub struct FieldSettingsChangesetPB {
|
||||
#[validate(custom = "required_not_empty_str")]
|
||||
#[pb(index = 1)]
|
||||
pub view_id: String,
|
||||
|
||||
#[validate(custom = "required_not_empty_str")]
|
||||
#[pb(index = 2)]
|
||||
pub field_id: String,
|
||||
|
||||
@ -106,28 +114,7 @@ pub struct FieldSettingsChangesetPB {
|
||||
|
||||
#[pb(index = 4, one_of)]
|
||||
pub width: Option<i32>,
|
||||
}
|
||||
|
||||
impl From<FieldSettingsChangesetParams> for FieldSettingsChangesetPB {
|
||||
fn from(value: FieldSettingsChangesetParams) -> Self {
|
||||
Self {
|
||||
view_id: value.view_id,
|
||||
field_id: value.field_id,
|
||||
visibility: value.visibility,
|
||||
width: value.width,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<FieldSettingsChangesetPB> for FieldSettingsChangesetParams {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_from(value: FieldSettingsChangesetPB) -> Result<Self, Self::Error> {
|
||||
Ok(FieldSettingsChangesetParams {
|
||||
view_id: value.view_id,
|
||||
field_id: value.field_id,
|
||||
visibility: value.visibility,
|
||||
width: value.width,
|
||||
})
|
||||
}
|
||||
#[pb(index = 5, one_of)]
|
||||
pub wrap_cell_content: Option<bool>,
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ use crate::services::field::{
|
||||
type_option_data_from_pb, ChecklistCellChangeset, DateCellChangeset, RelationCellChangeset,
|
||||
SelectOptionCellChangeset,
|
||||
};
|
||||
use crate::services::field_settings::FieldSettingsChangesetParams;
|
||||
use crate::services::group::GroupChangeset;
|
||||
use crate::services::share::csv::CSVFormat;
|
||||
|
||||
@ -944,7 +943,7 @@ pub(crate) async fn update_field_settings_handler(
|
||||
manager: AFPluginState<Weak<DatabaseManager>>,
|
||||
) -> FlowyResult<()> {
|
||||
let manager = upgrade_manager(manager)?;
|
||||
let params: FieldSettingsChangesetParams = data.into_inner().try_into()?;
|
||||
let params = data.try_into_inner()?;
|
||||
let database_editor = manager.get_database_with_view_id(¶ms.view_id).await?;
|
||||
database_editor
|
||||
.update_field_settings_with_changeset(params)
|
||||
|
@ -12,9 +12,7 @@ use crate::services::field::{
|
||||
type_option_data_from_pb, ChecklistCellChangeset, RelationTypeOption, SelectOptionCellChangeset,
|
||||
StrCellData, TimestampCellData, TypeOptionCellDataHandler, TypeOptionCellExt,
|
||||
};
|
||||
use crate::services::field_settings::{
|
||||
default_field_settings_by_layout_map, FieldSettings, FieldSettingsChangesetParams,
|
||||
};
|
||||
use crate::services::field_settings::{default_field_settings_by_layout_map, FieldSettings};
|
||||
use crate::services::filter::{Filter, FilterChangeset};
|
||||
use crate::services::group::{default_group_setting, GroupChangeset, GroupSetting, RowChangeset};
|
||||
use crate::services::share::csv::{CSVExport, CSVFormat};
|
||||
@ -1296,17 +1294,10 @@ impl DatabaseEditor {
|
||||
|
||||
pub async fn update_field_settings_with_changeset(
|
||||
&self,
|
||||
params: FieldSettingsChangesetParams,
|
||||
params: FieldSettingsChangesetPB,
|
||||
) -> FlowyResult<()> {
|
||||
let view = self.database_views.get_view_editor(¶ms.view_id).await?;
|
||||
view
|
||||
.v_update_field_settings(
|
||||
¶ms.view_id,
|
||||
¶ms.field_id,
|
||||
params.visibility,
|
||||
params.width,
|
||||
)
|
||||
.await?;
|
||||
view.v_update_field_settings(params).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -1735,45 +1726,43 @@ impl DatabaseViewOperation for DatabaseViewOperationImpl {
|
||||
field_settings
|
||||
}
|
||||
|
||||
fn update_field_settings(
|
||||
&self,
|
||||
view_id: &str,
|
||||
field_id: &str,
|
||||
visibility: Option<FieldVisibility>,
|
||||
width: Option<i32>,
|
||||
) {
|
||||
let field_settings_map = self.get_field_settings(view_id, &[field_id.to_string()]);
|
||||
fn update_field_settings(&self, params: FieldSettingsChangesetPB) {
|
||||
let field_settings_map = self.get_field_settings(¶ms.view_id, &[params.field_id.clone()]);
|
||||
|
||||
let new_field_settings = if let Some(field_settings) = field_settings_map.get(field_id) {
|
||||
FieldSettings {
|
||||
field_id: field_settings.field_id.clone(),
|
||||
visibility: visibility.unwrap_or(field_settings.visibility.clone()),
|
||||
width: width.unwrap_or(field_settings.width),
|
||||
}
|
||||
} else {
|
||||
let layout_type = self.get_layout_for_view(view_id);
|
||||
let default_field_settings = default_field_settings_by_layout_map()
|
||||
.get(&layout_type)
|
||||
.unwrap()
|
||||
.to_owned();
|
||||
let field_settings =
|
||||
FieldSettings::from_any_map(field_id, layout_type, &default_field_settings);
|
||||
FieldSettings {
|
||||
field_id: field_settings.field_id.clone(),
|
||||
visibility: visibility.unwrap_or(field_settings.visibility),
|
||||
width: width.unwrap_or(field_settings.width),
|
||||
}
|
||||
let field_settings = field_settings_map
|
||||
.get(¶ms.field_id)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| {
|
||||
let layout_type = self.get_layout_for_view(¶ms.view_id);
|
||||
let default_field_settings = default_field_settings_by_layout_map();
|
||||
let default_field_settings = default_field_settings.get(&layout_type).unwrap();
|
||||
|
||||
FieldSettings::from_any_map(¶ms.field_id, layout_type, default_field_settings)
|
||||
});
|
||||
|
||||
let new_field_settings = FieldSettings {
|
||||
visibility: params
|
||||
.visibility
|
||||
.unwrap_or_else(|| field_settings.visibility.clone()),
|
||||
width: params.width.unwrap_or(field_settings.width),
|
||||
wrap_cell_content: params
|
||||
.wrap_cell_content
|
||||
.unwrap_or(field_settings.wrap_cell_content),
|
||||
..field_settings
|
||||
};
|
||||
|
||||
self.database.lock().update_field_settings(
|
||||
view_id,
|
||||
Some(vec![field_id.to_string()]),
|
||||
¶ms.view_id,
|
||||
Some(vec![params.field_id]),
|
||||
new_field_settings.clone(),
|
||||
);
|
||||
|
||||
send_notification(view_id, DatabaseNotification::DidUpdateFieldSettings)
|
||||
.payload(FieldSettingsPB::from(new_field_settings))
|
||||
.send()
|
||||
send_notification(
|
||||
¶ms.view_id,
|
||||
DatabaseNotification::DidUpdateFieldSettings,
|
||||
)
|
||||
.payload(FieldSettingsPB::from(new_field_settings))
|
||||
.send()
|
||||
}
|
||||
|
||||
fn update_calculation(&self, view_id: &str, calculation: Calculation) {
|
||||
|
@ -15,10 +15,10 @@ use lib_dispatch::prelude::af_spawn;
|
||||
|
||||
use crate::entities::{
|
||||
CalendarEventPB, CreateRowParams, CreateRowPayloadPB, DatabaseLayoutMetaPB,
|
||||
DatabaseLayoutSettingPB, DeleteSortPayloadPB, FieldType, FieldVisibility, GroupChangesPB,
|
||||
GroupPB, LayoutSettingChangeset, LayoutSettingParams, RemoveCalculationChangesetPB,
|
||||
ReorderSortPayloadPB, RowMetaPB, RowsChangePB, SortChangesetNotificationPB, SortPB,
|
||||
UpdateCalculationChangesetPB, UpdateSortPayloadPB,
|
||||
DatabaseLayoutSettingPB, DeleteSortPayloadPB, FieldSettingsChangesetPB, FieldType,
|
||||
GroupChangesPB, GroupPB, LayoutSettingChangeset, LayoutSettingParams,
|
||||
RemoveCalculationChangesetPB, ReorderSortPayloadPB, RowMetaPB, RowsChangePB,
|
||||
SortChangesetNotificationPB, SortPB, UpdateCalculationChangesetPB, UpdateSortPayloadPB,
|
||||
};
|
||||
use crate::notification::{send_notification, DatabaseNotification};
|
||||
use crate::services::calculations::{Calculation, CalculationChangeset, CalculationsController};
|
||||
@ -1034,20 +1034,8 @@ impl DatabaseViewEditor {
|
||||
self.delegate.get_field_settings(&self.view_id, field_ids)
|
||||
}
|
||||
|
||||
// pub async fn v_get_all_field_settings(&self) -> HashMap<String, FieldSettings> {
|
||||
// self.delegate.get_all_field_settings(&self.view_id)
|
||||
// }
|
||||
|
||||
pub async fn v_update_field_settings(
|
||||
&self,
|
||||
view_id: &str,
|
||||
field_id: &str,
|
||||
visibility: Option<FieldVisibility>,
|
||||
width: Option<i32>,
|
||||
) -> FlowyResult<()> {
|
||||
self
|
||||
.delegate
|
||||
.update_field_settings(view_id, field_id, visibility, width);
|
||||
pub async fn v_update_field_settings(&self, params: FieldSettingsChangesetPB) -> FlowyResult<()> {
|
||||
self.delegate.update_field_settings(params);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ use flowy_error::FlowyError;
|
||||
use lib_infra::future::{Fut, FutureResult};
|
||||
use lib_infra::priority_task::TaskDispatcher;
|
||||
|
||||
use crate::entities::{FieldType, FieldVisibility};
|
||||
use crate::entities::{FieldSettingsChangesetPB, FieldType};
|
||||
use crate::services::calculations::Calculation;
|
||||
use crate::services::field::TypeOptionCellDataHandler;
|
||||
use crate::services::field_settings::FieldSettings;
|
||||
@ -126,11 +126,5 @@ pub trait DatabaseViewOperation: Send + Sync + 'static {
|
||||
field_ids: &[String],
|
||||
) -> HashMap<String, FieldSettings>;
|
||||
|
||||
fn update_field_settings(
|
||||
&self,
|
||||
view_id: &str,
|
||||
field_id: &str,
|
||||
visibility: Option<FieldVisibility>,
|
||||
width: Option<i32>,
|
||||
);
|
||||
fn update_field_settings(&self, params: FieldSettingsChangesetPB);
|
||||
}
|
||||
|
@ -10,12 +10,13 @@ pub struct FieldSettings {
|
||||
pub field_id: String,
|
||||
pub visibility: FieldVisibility,
|
||||
pub width: i32,
|
||||
pub wrap_cell_content: bool,
|
||||
}
|
||||
|
||||
pub const VISIBILITY: &str = "visibility";
|
||||
pub const WIDTH: &str = "width";
|
||||
|
||||
pub const DEFAULT_WIDTH: i32 = 150;
|
||||
pub const WRAP_CELL_CONTENT: &str = "wrap";
|
||||
|
||||
impl FieldSettings {
|
||||
pub fn from_any_map(
|
||||
@ -31,11 +32,15 @@ impl FieldSettings {
|
||||
.get_i64_value(WIDTH)
|
||||
.map(|value| value as i32)
|
||||
.unwrap_or(DEFAULT_WIDTH);
|
||||
let wrap_cell_content = field_settings
|
||||
.get_bool_value(WRAP_CELL_CONTENT)
|
||||
.unwrap_or(false);
|
||||
|
||||
Self {
|
||||
field_id: field_id.to_string(),
|
||||
visibility,
|
||||
width,
|
||||
wrap_cell_content,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -45,15 +50,7 @@ impl From<FieldSettings> for FieldSettingsMap {
|
||||
FieldSettingsMapBuilder::new()
|
||||
.insert_i64_value(VISIBILITY, field_settings.visibility.into())
|
||||
.insert_i64_value(WIDTH, field_settings.width as i64)
|
||||
.insert_bool_value(WRAP_CELL_CONTENT, field_settings.wrap_cell_content)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
/// Contains the changeset to a field's settings.
|
||||
/// A `Some` value constitutes a change in that particular setting
|
||||
pub struct FieldSettingsChangesetParams {
|
||||
pub view_id: String,
|
||||
pub field_id: String,
|
||||
pub visibility: Option<FieldVisibility>,
|
||||
pub width: Option<i32>,
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ use collab_database::views::{
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::entities::FieldVisibility;
|
||||
use crate::services::field_settings::{FieldSettings, VISIBILITY};
|
||||
use crate::services::field_settings::{FieldSettings, DEFAULT_WIDTH, VISIBILITY};
|
||||
|
||||
/// Helper struct to create a new field setting
|
||||
pub struct FieldSettingsBuilder {
|
||||
@ -19,8 +19,10 @@ impl FieldSettingsBuilder {
|
||||
let field_settings = FieldSettings {
|
||||
field_id: field_id.to_string(),
|
||||
visibility: FieldVisibility::AlwaysShown,
|
||||
width: 150,
|
||||
width: DEFAULT_WIDTH,
|
||||
wrap_cell_content: false,
|
||||
};
|
||||
|
||||
Self {
|
||||
inner: field_settings,
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
use flowy_database2::entities::FieldVisibility;
|
||||
use flowy_database2::services::field_settings::FieldSettingsChangesetParams;
|
||||
use flowy_database2::entities::{FieldSettingsChangesetPB, FieldVisibility};
|
||||
|
||||
use crate::database::database_editor::DatabaseEditorTest;
|
||||
|
||||
@ -60,11 +59,12 @@ impl FieldSettingsTest {
|
||||
visibility: Option<FieldVisibility>,
|
||||
width: Option<i32>,
|
||||
) {
|
||||
let params = FieldSettingsChangesetParams {
|
||||
let params = FieldSettingsChangesetPB {
|
||||
view_id: self.view_id.clone(),
|
||||
field_id,
|
||||
visibility,
|
||||
width,
|
||||
wrap_cell_content: None,
|
||||
};
|
||||
let _ = self
|
||||
.editor
|
||||
|
Reference in New Issue
Block a user