mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
refactor: baord configuration
This commit is contained in:
parent
edd520abda
commit
c81b6f10fa
@ -491,6 +491,27 @@ impl TryInto<FieldChangesetParams> for FieldChangesetPayloadPB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default)]
|
||||||
|
pub struct FieldChangesetParams {
|
||||||
|
pub field_id: String,
|
||||||
|
|
||||||
|
pub grid_id: String,
|
||||||
|
|
||||||
|
pub name: Option<String>,
|
||||||
|
|
||||||
|
pub desc: Option<String>,
|
||||||
|
|
||||||
|
pub field_type: Option<FieldTypeRevision>,
|
||||||
|
|
||||||
|
pub frozen: Option<bool>,
|
||||||
|
|
||||||
|
pub visibility: Option<bool>,
|
||||||
|
|
||||||
|
pub width: Option<i32>,
|
||||||
|
|
||||||
|
pub type_option_data: Option<Vec<u8>>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
Clone,
|
Clone,
|
||||||
|
@ -5,8 +5,7 @@ use crate::entities::{
|
|||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use flowy_grid_data_model::parser::NotEmptyStr;
|
use flowy_grid_data_model::parser::NotEmptyStr;
|
||||||
use flowy_grid_data_model::revision::{FieldRevision, FilterConfigurationRevision};
|
use flowy_grid_data_model::revision::{FieldRevision, FieldTypeRevision, FilterConfigurationRevision};
|
||||||
use flowy_sync::entities::grid::{CreateGridFilterParams, DeleteFilterParams};
|
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -72,6 +71,12 @@ impl TryInto<DeleteFilterParams> for DeleteFilterPayloadPB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct DeleteFilterParams {
|
||||||
|
pub field_id: String,
|
||||||
|
pub filter_id: String,
|
||||||
|
pub field_type_rev: FieldTypeRevision,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(ProtoBuf, Debug, Default, Clone)]
|
#[derive(ProtoBuf, Debug, Default, Clone)]
|
||||||
pub struct CreateGridFilterPayloadPB {
|
pub struct CreateGridFilterPayloadPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
@ -99,10 +104,10 @@ impl CreateGridFilterPayloadPB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryInto<CreateGridFilterParams> for CreateGridFilterPayloadPB {
|
impl TryInto<CreateFilterParams> for CreateGridFilterPayloadPB {
|
||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<CreateGridFilterParams, Self::Error> {
|
fn try_into(self) -> Result<CreateFilterParams, Self::Error> {
|
||||||
let field_id = NotEmptyStr::parse(self.field_id)
|
let field_id = NotEmptyStr::parse(self.field_id)
|
||||||
.map_err(|_| ErrorCode::FieldIdIsEmpty)?
|
.map_err(|_| ErrorCode::FieldIdIsEmpty)?
|
||||||
.0;
|
.0;
|
||||||
@ -125,7 +130,7 @@ impl TryInto<CreateGridFilterParams> for CreateGridFilterPayloadPB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(CreateGridFilterParams {
|
Ok(CreateFilterParams {
|
||||||
field_id,
|
field_id,
|
||||||
field_type_rev: self.field_type.into(),
|
field_type_rev: self.field_type.into(),
|
||||||
condition,
|
condition,
|
||||||
@ -133,3 +138,10 @@ impl TryInto<CreateGridFilterParams> for CreateGridFilterPayloadPB {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct CreateFilterParams {
|
||||||
|
pub field_id: String,
|
||||||
|
pub field_type_rev: FieldTypeRevision,
|
||||||
|
pub condition: u8,
|
||||||
|
pub content: Option<String>,
|
||||||
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||||
|
use flowy_grid_data_model::revision::{GroupRecordRevision, SelectOptionGroupConfigurationRevision};
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||||
pub struct UrlGroupConfigurationPB {
|
pub struct UrlGroupConfigurationPB {
|
||||||
@ -16,6 +17,36 @@ pub struct TextGroupConfigurationPB {
|
|||||||
pub struct SelectOptionGroupConfigurationPB {
|
pub struct SelectOptionGroupConfigurationPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
hide_empty: bool,
|
hide_empty: bool,
|
||||||
|
|
||||||
|
#[pb(index = 2)]
|
||||||
|
groups: Vec<GroupRecordPB>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::convert::From<SelectOptionGroupConfigurationRevision> for SelectOptionGroupConfigurationPB {
|
||||||
|
fn from(rev: SelectOptionGroupConfigurationRevision) -> Self {
|
||||||
|
Self {
|
||||||
|
hide_empty: rev.hide_empty,
|
||||||
|
groups: rev.groups.into_iter().map(GroupRecordPB::from).collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||||
|
pub struct GroupRecordPB {
|
||||||
|
#[pb(index = 1)]
|
||||||
|
group_id: String,
|
||||||
|
|
||||||
|
#[pb(index = 2)]
|
||||||
|
visible: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::convert::From<GroupRecordRevision> for GroupRecordPB {
|
||||||
|
fn from(rev: GroupRecordRevision) -> Self {
|
||||||
|
Self {
|
||||||
|
group_id: rev.group_id,
|
||||||
|
visible: rev.visible,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||||
|
@ -2,8 +2,7 @@ use crate::entities::{FieldType, RowPB};
|
|||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use flowy_grid_data_model::parser::NotEmptyStr;
|
use flowy_grid_data_model::parser::NotEmptyStr;
|
||||||
use flowy_grid_data_model::revision::GroupConfigurationRevision;
|
use flowy_grid_data_model::revision::{FieldTypeRevision, GroupConfigurationRevision};
|
||||||
use flowy_sync::entities::grid::{CreateGridGroupParams, DeleteGroupParams};
|
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -86,27 +85,28 @@ pub struct CreateGridGroupPayloadPB {
|
|||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub field_type: FieldType,
|
pub field_type: FieldType,
|
||||||
|
|
||||||
#[pb(index = 3, one_of)]
|
|
||||||
pub content: Option<Vec<u8>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryInto<CreateGridGroupParams> for CreateGridGroupPayloadPB {
|
impl TryInto<CreatGroupParams> for CreateGridGroupPayloadPB {
|
||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<CreateGridGroupParams, Self::Error> {
|
fn try_into(self) -> Result<CreatGroupParams, Self::Error> {
|
||||||
let field_id = NotEmptyStr::parse(self.field_id)
|
let field_id = NotEmptyStr::parse(self.field_id)
|
||||||
.map_err(|_| ErrorCode::FieldIdIsEmpty)?
|
.map_err(|_| ErrorCode::FieldIdIsEmpty)?
|
||||||
.0;
|
.0;
|
||||||
|
|
||||||
Ok(CreateGridGroupParams {
|
Ok(CreatGroupParams {
|
||||||
field_id,
|
field_id,
|
||||||
field_type_rev: self.field_type.into(),
|
field_type_rev: self.field_type.into(),
|
||||||
content: self.content,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct CreatGroupParams {
|
||||||
|
pub field_id: String,
|
||||||
|
pub field_type_rev: FieldTypeRevision,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(ProtoBuf, Debug, Default, Clone)]
|
#[derive(ProtoBuf, Debug, Default, Clone)]
|
||||||
pub struct DeleteGroupPayloadPB {
|
pub struct DeleteGroupPayloadPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
@ -137,3 +137,9 @@ impl TryInto<DeleteGroupParams> for DeleteGroupPayloadPB {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct DeleteGroupParams {
|
||||||
|
pub field_id: String,
|
||||||
|
pub group_id: String,
|
||||||
|
pub field_type_rev: FieldTypeRevision,
|
||||||
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
use crate::entities::{InsertedRowPB, RowPB};
|
use crate::entities::{GroupPB, InsertedRowPB, RowPB};
|
||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
|
use flowy_error::ErrorCode;
|
||||||
|
use flowy_grid_data_model::parser::NotEmptyStr;
|
||||||
use std::fmt::Formatter;
|
use std::fmt::Formatter;
|
||||||
|
|
||||||
#[derive(Debug, Default, ProtoBuf)]
|
#[derive(Debug, Default, ProtoBuf)]
|
||||||
@ -62,3 +64,55 @@ impl GroupRowsChangesetPB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[derive(Debug, Default, ProtoBuf)]
|
||||||
|
pub struct MoveGroupPayloadPB {
|
||||||
|
#[pb(index = 1)]
|
||||||
|
pub view_id: String,
|
||||||
|
|
||||||
|
#[pb(index = 2)]
|
||||||
|
pub from_group_id: String,
|
||||||
|
|
||||||
|
#[pb(index = 3)]
|
||||||
|
pub to_group_id: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct MoveGroupParams {
|
||||||
|
pub view_id: String,
|
||||||
|
pub from_group_id: String,
|
||||||
|
pub to_group_id: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryInto<MoveGroupParams> for MoveGroupPayloadPB {
|
||||||
|
type Error = ErrorCode;
|
||||||
|
|
||||||
|
fn try_into(self) -> Result<MoveGroupParams, Self::Error> {
|
||||||
|
let view_id = NotEmptyStr::parse(self.view_id)
|
||||||
|
.map_err(|_| ErrorCode::GridViewIdIsEmpty)?
|
||||||
|
.0;
|
||||||
|
let from_group_id = NotEmptyStr::parse(self.from_group_id)
|
||||||
|
.map_err(|_| ErrorCode::GroupIdIsEmpty)?
|
||||||
|
.0;
|
||||||
|
let to_group_id = NotEmptyStr::parse(self.to_group_id)
|
||||||
|
.map_err(|_| ErrorCode::GroupIdIsEmpty)?
|
||||||
|
.0;
|
||||||
|
Ok(MoveGroupParams {
|
||||||
|
view_id,
|
||||||
|
from_group_id,
|
||||||
|
to_group_id,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, ProtoBuf)]
|
||||||
|
pub struct GroupsChangesetPB {
|
||||||
|
#[pb(index = 1)]
|
||||||
|
pub view_id: String,
|
||||||
|
|
||||||
|
#[pb(index = 2)]
|
||||||
|
pub inserted_groups: Vec<GroupPB>,
|
||||||
|
|
||||||
|
#[pb(index = 3)]
|
||||||
|
pub deleted_groups: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GroupsChangesetPB {}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use crate::entities::{
|
use crate::entities::{
|
||||||
CreateGridFilterPayloadPB, CreateGridGroupPayloadPB, CreateGridSortPayloadPB, DeleteFilterPayloadPB,
|
CreatGroupParams, CreateFilterParams, CreateGridFilterPayloadPB, CreateGridGroupPayloadPB, CreateGridSortPayloadPB,
|
||||||
DeleteGroupPayloadPB, RepeatedGridConfigurationFilterPB, RepeatedGridGroupConfigurationPB, RepeatedGridSortPB,
|
CreateSortParams, DeleteFilterParams, DeleteFilterPayloadPB, DeleteGroupParams, DeleteGroupPayloadPB,
|
||||||
|
RepeatedGridConfigurationFilterPB, RepeatedGridGroupConfigurationPB, RepeatedGridSortPB,
|
||||||
};
|
};
|
||||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
@ -156,3 +157,20 @@ impl TryInto<GridSettingChangesetParams> for GridSettingChangesetPayloadPB {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct GridSettingChangesetParams {
|
||||||
|
pub grid_id: String,
|
||||||
|
pub layout_type: LayoutRevision,
|
||||||
|
pub insert_filter: Option<CreateFilterParams>,
|
||||||
|
pub delete_filter: Option<DeleteFilterParams>,
|
||||||
|
pub insert_group: Option<CreatGroupParams>,
|
||||||
|
pub delete_group: Option<DeleteGroupParams>,
|
||||||
|
pub insert_sort: Option<CreateSortParams>,
|
||||||
|
pub delete_sort: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GridSettingChangesetParams {
|
||||||
|
pub fn is_filter_changed(&self) -> bool {
|
||||||
|
self.insert_filter.is_some() || self.delete_filter.is_some()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -2,7 +2,6 @@ use flowy_derive::ProtoBuf;
|
|||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use flowy_grid_data_model::parser::NotEmptyStr;
|
use flowy_grid_data_model::parser::NotEmptyStr;
|
||||||
use flowy_grid_data_model::revision::SortConfigurationRevision;
|
use flowy_grid_data_model::revision::SortConfigurationRevision;
|
||||||
use flowy_sync::entities::grid::CreateGridSortParams;
|
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -51,15 +50,19 @@ pub struct CreateGridSortPayloadPB {
|
|||||||
pub field_id: Option<String>,
|
pub field_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryInto<CreateGridSortParams> for CreateGridSortPayloadPB {
|
impl TryInto<CreateSortParams> for CreateGridSortPayloadPB {
|
||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<CreateGridSortParams, Self::Error> {
|
fn try_into(self) -> Result<CreateSortParams, Self::Error> {
|
||||||
let field_id = match self.field_id {
|
let field_id = match self.field_id {
|
||||||
None => None,
|
None => None,
|
||||||
Some(field_id) => Some(NotEmptyStr::parse(field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?.0),
|
Some(field_id) => Some(NotEmptyStr::parse(field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?.0),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(CreateGridSortParams { field_id })
|
Ok(CreateSortParams { field_id })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct CreateSortParams {
|
||||||
|
pub field_id: Option<String>,
|
||||||
|
}
|
||||||
|
@ -437,3 +437,14 @@ pub(crate) async fn create_board_card_handler(
|
|||||||
let row = editor.create_row(params).await?;
|
let row = editor.create_row(params).await?;
|
||||||
data_result(row)
|
data_result(row)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
||||||
|
pub(crate) async fn move_group_handler(
|
||||||
|
data: Data<MoveGroupPayloadPB>,
|
||||||
|
manager: AppData<Arc<GridManager>>,
|
||||||
|
) -> DataResult<GroupsChangesetPB, FlowyError> {
|
||||||
|
let params: MoveGroupParams = data.into_inner().try_into()?;
|
||||||
|
let editor = manager.get_grid_editor(params.view_id.as_ref())?;
|
||||||
|
let changeset = editor.move_group(params).await?;
|
||||||
|
data_result(changeset)
|
||||||
|
}
|
||||||
|
@ -41,6 +41,7 @@ pub fn create(grid_manager: Arc<GridManager>) -> Module {
|
|||||||
.event(GridEvent::UpdateDateCell, update_date_cell_handler)
|
.event(GridEvent::UpdateDateCell, update_date_cell_handler)
|
||||||
// Group
|
// Group
|
||||||
.event(GridEvent::CreateBoardCard, create_board_card_handler)
|
.event(GridEvent::CreateBoardCard, create_board_card_handler)
|
||||||
|
.event(GridEvent::MoveGroup, move_group_handler)
|
||||||
.event(GridEvent::GetGroup, get_groups_handler);
|
.event(GridEvent::GetGroup, get_groups_handler);
|
||||||
|
|
||||||
module
|
module
|
||||||
@ -217,4 +218,7 @@ pub enum GridEvent {
|
|||||||
|
|
||||||
#[event(input = "CreateBoardCardPayloadPB", output = "RowPB")]
|
#[event(input = "CreateBoardCardPayloadPB", output = "RowPB")]
|
||||||
CreateBoardCard = 110,
|
CreateBoardCard = 110,
|
||||||
|
|
||||||
|
#[event(input = "MoveGroupPayloadPB", output = "GroupsChangesetPB")]
|
||||||
|
MoveGroup = 111,
|
||||||
}
|
}
|
||||||
|
@ -294,6 +294,11 @@ impl GridRevisionEditor {
|
|||||||
Ok(row_pb)
|
Ok(row_pb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn move_group(&self, params: MoveGroupParams) -> FlowyResult<GroupsChangesetPB> {
|
||||||
|
//
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn insert_rows(&self, row_revs: Vec<RowRevision>) -> FlowyResult<Vec<RowPB>> {
|
pub async fn insert_rows(&self, row_revs: Vec<RowRevision>) -> FlowyResult<Vec<RowPB>> {
|
||||||
let block_id = self.block_id().await?;
|
let block_id = self.block_id().await?;
|
||||||
let mut rows_by_block_id: HashMap<String, Vec<RowRevision>> = HashMap::new();
|
let mut rows_by_block_id: HashMap<String, Vec<RowRevision>> = HashMap::new();
|
||||||
|
@ -172,10 +172,15 @@ impl GridViewRevisionEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn update_setting(&self, changeset: GridSettingChangesetParams) -> FlowyResult<()> {
|
pub(crate) async fn update_setting(&self, changeset: GridSettingChangesetParams) -> FlowyResult<()> {
|
||||||
let _ = self.modify(|pad| Ok(pad.update_setting(changeset)?)).await;
|
// let _ = self.modify(|pad| Ok(pad.update_setting(changeset)?)).await;
|
||||||
Ok(())
|
// Ok(())
|
||||||
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pub(crate) async fn insert_group(&self, params: CreateGroupParams) -> FlowyResult<()> {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
pub(crate) async fn get_filters(&self) -> Vec<GridFilterConfiguration> {
|
pub(crate) async fn get_filters(&self) -> Vec<GridFilterConfiguration> {
|
||||||
let field_revs = self.field_delegate.get_field_revs().await;
|
let field_revs = self.field_delegate.get_field_revs().await;
|
||||||
match self.pad.read().await.get_setting_rev().get_all_filters(&field_revs) {
|
match self.pad.read().await.get_setting_rev().get_all_filters(&field_revs) {
|
||||||
|
@ -130,6 +130,8 @@ impl GridViewManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn move_group(&self) {}
|
||||||
|
|
||||||
pub(crate) async fn get_view_editor(&self, view_id: &str) -> FlowyResult<Arc<GridViewRevisionEditor>> {
|
pub(crate) async fn get_view_editor(&self, view_id: &str) -> FlowyResult<Arc<GridViewRevisionEditor>> {
|
||||||
debug_assert!(!view_id.is_empty());
|
debug_assert!(!view_id.is_empty());
|
||||||
match self.view_editors.get(view_id) {
|
match self.view_editors.get(view_id) {
|
||||||
|
@ -163,10 +163,12 @@ where
|
|||||||
G: GroupGenerator<ConfigurationType = C, TypeOptionType = T>,
|
G: GroupGenerator<ConfigurationType = C, TypeOptionType = T>,
|
||||||
{
|
{
|
||||||
pub fn new(field_rev: &Arc<FieldRevision>, configuration: GroupConfigurationRevision) -> FlowyResult<Self> {
|
pub fn new(field_rev: &Arc<FieldRevision>, configuration: GroupConfigurationRevision) -> FlowyResult<Self> {
|
||||||
let configuration = match configuration.content {
|
// let configuration = match configuration.content {
|
||||||
None => None,
|
// None => None,
|
||||||
Some(content) => Some(C::try_from(Bytes::from(content))?),
|
// Some(content) => Some(C::try_from(Bytes::from(content))?),
|
||||||
};
|
// };
|
||||||
|
|
||||||
|
let configuration = None;
|
||||||
let field_type_rev = field_rev.ty;
|
let field_type_rev = field_rev.ty;
|
||||||
let type_option = field_rev.get_type_option_entry::<T>(field_type_rev);
|
let type_option = field_rev.get_type_option_entry::<T>(field_type_rev);
|
||||||
let groups = G::generate_groups(&field_rev.id, &configuration, &type_option);
|
let groups = G::generate_groups(&field_rev.id, &configuration, &type_option);
|
||||||
|
@ -4,7 +4,6 @@ use crate::services::field::{
|
|||||||
MultiSelectTypeOptionPB, SelectOptionCellDataPB, SelectOptionCellDataParser, SingleSelectTypeOptionPB,
|
MultiSelectTypeOptionPB, SelectOptionCellDataPB, SelectOptionCellDataParser, SingleSelectTypeOptionPB,
|
||||||
};
|
};
|
||||||
use crate::services::group::{GenericGroupController, Group, GroupController, GroupGenerator, Groupable};
|
use crate::services::group::{GenericGroupController, Group, GroupController, GroupGenerator, Groupable};
|
||||||
|
|
||||||
use flowy_grid_data_model::revision::{FieldRevision, RowChangeset, RowRevision};
|
use flowy_grid_data_model::revision::{FieldRevision, RowChangeset, RowRevision};
|
||||||
|
|
||||||
// SingleSelect
|
// SingleSelect
|
||||||
|
@ -8,7 +8,9 @@ use crate::services::group::{
|
|||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
use flowy_grid_data_model::revision::{
|
use flowy_grid_data_model::revision::{
|
||||||
gen_grid_group_id, FieldRevision, GroupConfigurationRevision, RowChangeset, RowRevision,
|
gen_grid_group_id, CheckboxGroupConfigurationRevision, DateGroupConfigurationRevision, FieldRevision,
|
||||||
|
GroupConfigurationRevision, NumberGroupConfigurationRevision, RowChangeset, RowRevision,
|
||||||
|
SelectOptionGroupConfigurationRevision, TextGroupConfigurationRevision, UrlGroupConfigurationRevision,
|
||||||
};
|
};
|
||||||
use lib_infra::future::AFFuture;
|
use lib_infra::future::AFFuture;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
@ -208,20 +210,41 @@ fn find_group_field(field_revs: &[Arc<FieldRevision>]) -> Option<Arc<FieldRevisi
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_group_configuration(field_rev: &FieldRevision) -> GroupConfigurationRevision {
|
pub fn default_group_configuration(field_rev: &FieldRevision) -> GroupConfigurationRevision {
|
||||||
|
let field_id = field_rev.id.clone();
|
||||||
|
let field_type_rev = field_rev.ty.clone();
|
||||||
let field_type: FieldType = field_rev.ty.into();
|
let field_type: FieldType = field_rev.ty.into();
|
||||||
let bytes: Bytes = match field_type {
|
match field_type {
|
||||||
FieldType::RichText => TextGroupConfigurationPB::default().try_into().unwrap(),
|
FieldType::RichText => {
|
||||||
FieldType::Number => NumberGroupConfigurationPB::default().try_into().unwrap(),
|
GroupConfigurationRevision::new(field_id, field_type_rev, TextGroupConfigurationRevision::default())
|
||||||
FieldType::DateTime => DateGroupConfigurationPB::default().try_into().unwrap(),
|
.unwrap()
|
||||||
FieldType::SingleSelect => SelectOptionGroupConfigurationPB::default().try_into().unwrap(),
|
}
|
||||||
FieldType::MultiSelect => SelectOptionGroupConfigurationPB::default().try_into().unwrap(),
|
FieldType::Number => {
|
||||||
FieldType::Checkbox => CheckboxGroupConfigurationPB::default().try_into().unwrap(),
|
GroupConfigurationRevision::new(field_id, field_type_rev, NumberGroupConfigurationRevision::default())
|
||||||
FieldType::URL => UrlGroupConfigurationPB::default().try_into().unwrap(),
|
.unwrap()
|
||||||
};
|
}
|
||||||
GroupConfigurationRevision {
|
FieldType::DateTime => {
|
||||||
id: gen_grid_group_id(),
|
GroupConfigurationRevision::new(field_id, field_type_rev, DateGroupConfigurationRevision::default())
|
||||||
field_id: field_rev.id.clone(),
|
.unwrap()
|
||||||
field_type_rev: field_rev.ty,
|
}
|
||||||
content: Some(bytes.to_vec()),
|
|
||||||
|
FieldType::SingleSelect => GroupConfigurationRevision::new(
|
||||||
|
field_id,
|
||||||
|
field_type_rev,
|
||||||
|
SelectOptionGroupConfigurationRevision::default(),
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
FieldType::MultiSelect => GroupConfigurationRevision::new(
|
||||||
|
field_id,
|
||||||
|
field_type_rev,
|
||||||
|
SelectOptionGroupConfigurationRevision::default(),
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
FieldType::Checkbox => {
|
||||||
|
GroupConfigurationRevision::new(field_id, field_type_rev, CheckboxGroupConfigurationRevision::default())
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
FieldType::URL => {
|
||||||
|
GroupConfigurationRevision::new(field_id, field_type_rev, UrlGroupConfigurationRevision::default()).unwrap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use crate::entities::{
|
|||||||
RepeatedGridSortPB,
|
RepeatedGridSortPB,
|
||||||
};
|
};
|
||||||
use flowy_grid_data_model::revision::{FieldRevision, SettingRevision};
|
use flowy_grid_data_model::revision::{FieldRevision, SettingRevision};
|
||||||
use flowy_sync::entities::grid::{CreateGridFilterParams, DeleteFilterParams, GridSettingChangesetParams};
|
use flowy_sync::entities::grid::{CreateFilterParams, DeleteFilterParams, GridSettingChangesetParams};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ impl GridSettingChangesetBuilder {
|
|||||||
Self { params }
|
Self { params }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_filter(mut self, params: CreateGridFilterParams) -> Self {
|
pub fn insert_filter(mut self, params: CreateFilterParams) -> Self {
|
||||||
self.params.insert_filter = Some(params);
|
self.params.insert_filter = Some(params);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
use flowy_grid::entities::{CreateGridFilterPayloadPB, GridLayout, GridSettingPB};
|
use flowy_grid::entities::{CreateGridFilterPayloadPB, GridLayout, GridSettingPB};
|
||||||
use flowy_grid::services::setting::GridSettingChangesetBuilder;
|
use flowy_grid::services::setting::GridSettingChangesetBuilder;
|
||||||
use flowy_grid_data_model::revision::{FieldRevision, FieldTypeRevision};
|
use flowy_grid_data_model::revision::{FieldRevision, FieldTypeRevision};
|
||||||
use flowy_sync::entities::grid::{CreateGridFilterParams, DeleteFilterParams, GridSettingChangesetParams};
|
use flowy_sync::entities::grid::{CreateFilterParams, DeleteFilterParams, GridSettingChangesetParams};
|
||||||
use crate::grid::grid_editor::GridEditorTest;
|
use crate::grid::grid_editor::GridEditorTest;
|
||||||
|
|
||||||
pub enum FilterScript {
|
pub enum FilterScript {
|
||||||
@ -54,7 +54,7 @@ impl GridFilterTest {
|
|||||||
let _ = self.editor.update_grid_setting(params).await.unwrap();
|
let _ = self.editor.update_grid_setting(params).await.unwrap();
|
||||||
}
|
}
|
||||||
FilterScript::InsertGridTableFilter { payload } => {
|
FilterScript::InsertGridTableFilter { payload } => {
|
||||||
let params: CreateGridFilterParams = payload.try_into().unwrap();
|
let params: CreateFilterParams = payload.try_into().unwrap();
|
||||||
let layout_type = GridLayout::Table;
|
let layout_type = GridLayout::Table;
|
||||||
let params = GridSettingChangesetBuilder::new(&self.grid_id, &layout_type)
|
let params = GridSettingChangesetBuilder::new(&self.grid_id, &layout_type)
|
||||||
.insert_filter(params)
|
.insert_filter(params)
|
||||||
|
@ -13,7 +13,7 @@ use flowy_grid_data_model::revision::*;
|
|||||||
use flowy_revision::REVISION_WRITE_INTERVAL_IN_MILLIS;
|
use flowy_revision::REVISION_WRITE_INTERVAL_IN_MILLIS;
|
||||||
use flowy_sync::client_grid::GridBuilder;
|
use flowy_sync::client_grid::GridBuilder;
|
||||||
use flowy_sync::entities::grid::{
|
use flowy_sync::entities::grid::{
|
||||||
CreateGridFilterParams, DeleteFilterParams, FieldChangesetParams, GridSettingChangesetParams,
|
CreateFilterParams, DeleteFilterParams, FieldChangesetParams, GridSettingChangesetParams,
|
||||||
};
|
};
|
||||||
use flowy_test::helper::ViewTest;
|
use flowy_test::helper::ViewTest;
|
||||||
use flowy_test::FlowySDKTest;
|
use flowy_test::FlowySDKTest;
|
||||||
|
@ -240,12 +240,29 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait GroupConfigurationSerde {}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
|
||||||
pub struct GroupConfigurationRevision {
|
pub struct GroupConfigurationRevision {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub field_id: String,
|
pub field_id: String,
|
||||||
pub field_type_rev: FieldTypeRevision,
|
pub field_type_rev: FieldTypeRevision,
|
||||||
pub content: Option<Vec<u8>>,
|
pub content: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GroupConfigurationRevision {
|
||||||
|
pub fn new<T>(field_id: String, field_type: FieldTypeRevision, content: T) -> Result<Self, serde_json::Error>
|
||||||
|
where
|
||||||
|
T: serde::Serialize,
|
||||||
|
{
|
||||||
|
let content = serde_json::to_string(&content)?;
|
||||||
|
Ok(Self {
|
||||||
|
id: gen_grid_group_id(),
|
||||||
|
field_id,
|
||||||
|
field_type_rev: field_type,
|
||||||
|
content,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq, Hash)]
|
||||||
|
59
shared-lib/flowy-grid-data-model/src/revision/group_rev.rs
Normal file
59
shared-lib/flowy-grid-data-model/src/revision/group_rev.rs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_repr::*;
|
||||||
|
|
||||||
|
#[derive(Default, Serialize, Deserialize)]
|
||||||
|
pub struct TextGroupConfigurationRevision {
|
||||||
|
pub hide_empty: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Serialize, Deserialize)]
|
||||||
|
pub struct NumberGroupConfigurationRevision {
|
||||||
|
pub hide_empty: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Serialize, Deserialize)]
|
||||||
|
pub struct UrlGroupConfigurationRevision {
|
||||||
|
pub hide_empty: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Serialize, Deserialize)]
|
||||||
|
pub struct CheckboxGroupConfigurationRevision {
|
||||||
|
pub hide_empty: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Serialize, Deserialize)]
|
||||||
|
pub struct SelectOptionGroupConfigurationRevision {
|
||||||
|
pub hide_empty: bool,
|
||||||
|
pub groups: Vec<GroupRecordRevision>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Serialize, Deserialize)]
|
||||||
|
pub struct GroupRecordRevision {
|
||||||
|
pub group_id: String,
|
||||||
|
|
||||||
|
#[serde(default = "DEFAULT_GROUP_RECORD_VISIBILITY")]
|
||||||
|
pub visible: bool,
|
||||||
|
}
|
||||||
|
const DEFAULT_GROUP_RECORD_VISIBILITY: fn() -> bool = || true;
|
||||||
|
|
||||||
|
#[derive(Default, Serialize, Deserialize)]
|
||||||
|
pub struct DateGroupConfigurationRevision {
|
||||||
|
pub hide_empty: bool,
|
||||||
|
pub condition: DateCondition,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize_repr, Deserialize_repr)]
|
||||||
|
#[repr(u8)]
|
||||||
|
pub enum DateCondition {
|
||||||
|
Relative = 0,
|
||||||
|
Day = 1,
|
||||||
|
Week = 2,
|
||||||
|
Month = 3,
|
||||||
|
Year = 4,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::default::Default for DateCondition {
|
||||||
|
fn default() -> Self {
|
||||||
|
DateCondition::Relative
|
||||||
|
}
|
||||||
|
}
|
@ -2,8 +2,10 @@ mod grid_block;
|
|||||||
mod grid_rev;
|
mod grid_rev;
|
||||||
mod grid_setting_rev;
|
mod grid_setting_rev;
|
||||||
mod grid_view;
|
mod grid_view;
|
||||||
|
mod group_rev;
|
||||||
|
|
||||||
pub use grid_block::*;
|
pub use grid_block::*;
|
||||||
pub use grid_rev::*;
|
pub use grid_rev::*;
|
||||||
pub use grid_setting_rev::*;
|
pub use grid_setting_rev::*;
|
||||||
pub use grid_view::*;
|
pub use grid_view::*;
|
||||||
|
pub use group_rev::*;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::entities::grid::{CreateGridFilterParams, CreateGridGroupParams, GridSettingChangesetParams};
|
use crate::entities::grid::{CreatGroupParams, CreateFilterParams, GridSettingChangesetParams};
|
||||||
use crate::entities::revision::{md5, Revision};
|
use crate::entities::revision::{md5, Revision};
|
||||||
use crate::errors::{internal_error, CollaborateError, CollaborateResult};
|
use crate::errors::{internal_error, CollaborateError, CollaborateResult};
|
||||||
use crate::util::{cal_diff, make_text_delta_from_revisions};
|
use crate::util::{cal_diff, make_text_delta_from_revisions};
|
||||||
@ -54,55 +54,6 @@ impl GridViewRevisionPad {
|
|||||||
&self.view.setting
|
&self.view.setting
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_setting(
|
|
||||||
&mut self,
|
|
||||||
changeset: GridSettingChangesetParams,
|
|
||||||
) -> CollaborateResult<Option<GridViewRevisionChangeset>> {
|
|
||||||
self.modify(|view| {
|
|
||||||
let mut is_changed = None;
|
|
||||||
if let Some(params) = changeset.insert_filter {
|
|
||||||
view.setting.filters.insert_object(
|
|
||||||
¶ms.field_id,
|
|
||||||
¶ms.field_type_rev,
|
|
||||||
make_filter_revision(¶ms),
|
|
||||||
);
|
|
||||||
is_changed = Some(())
|
|
||||||
}
|
|
||||||
if let Some(params) = changeset.delete_filter {
|
|
||||||
if let Some(filters) = view
|
|
||||||
.setting
|
|
||||||
.filters
|
|
||||||
.get_mut_objects(¶ms.field_id, ¶ms.field_type_rev)
|
|
||||||
{
|
|
||||||
filters.retain(|filter| filter.id != params.filter_id);
|
|
||||||
is_changed = Some(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(params) = changeset.insert_group {
|
|
||||||
view.setting.groups.remove_all();
|
|
||||||
view.setting.groups.insert_object(
|
|
||||||
¶ms.field_id,
|
|
||||||
¶ms.field_type_rev,
|
|
||||||
make_group_revision(¶ms),
|
|
||||||
);
|
|
||||||
|
|
||||||
is_changed = Some(());
|
|
||||||
}
|
|
||||||
if let Some(params) = changeset.delete_group {
|
|
||||||
if let Some(groups) = view
|
|
||||||
.setting
|
|
||||||
.groups
|
|
||||||
.get_mut_objects(¶ms.field_id, ¶ms.field_type_rev)
|
|
||||||
{
|
|
||||||
groups.retain(|group| group.id != params.group_id);
|
|
||||||
is_changed = Some(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(is_changed)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_all_groups(&self, field_revs: &[Arc<FieldRevision>]) -> Option<GroupConfigurationsByFieldId> {
|
pub fn get_all_groups(&self, field_revs: &[Arc<FieldRevision>]) -> Option<GroupConfigurationsByFieldId> {
|
||||||
self.setting.groups.get_all_objects(field_revs)
|
self.setting.groups.get_all_objects(field_revs)
|
||||||
}
|
}
|
||||||
@ -216,7 +167,7 @@ impl GridViewRevisionPad {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_filter_revision(params: &CreateGridFilterParams) -> FilterConfigurationRevision {
|
fn make_filter_revision(params: &CreateFilterParams) -> FilterConfigurationRevision {
|
||||||
FilterConfigurationRevision {
|
FilterConfigurationRevision {
|
||||||
id: gen_grid_filter_id(),
|
id: gen_grid_filter_id(),
|
||||||
field_id: params.field_id.clone(),
|
field_id: params.field_id.clone(),
|
||||||
@ -225,7 +176,7 @@ fn make_filter_revision(params: &CreateGridFilterParams) -> FilterConfigurationR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_group_revision(params: &CreateGridGroupParams) -> GroupConfigurationRevision {
|
fn make_group_revision(params: &CreatGroupParams) -> GroupConfigurationRevision {
|
||||||
GroupConfigurationRevision {
|
GroupConfigurationRevision {
|
||||||
id: gen_grid_group_id(),
|
id: gen_grid_group_id(),
|
||||||
field_id: params.field_id.clone(),
|
field_id: params.field_id.clone(),
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
use flowy_grid_data_model::revision::{FieldTypeRevision, LayoutRevision};
|
|
||||||
|
|
||||||
pub struct GridSettingChangesetParams {
|
|
||||||
pub grid_id: String,
|
|
||||||
pub layout_type: LayoutRevision,
|
|
||||||
pub insert_filter: Option<CreateGridFilterParams>,
|
|
||||||
pub delete_filter: Option<DeleteFilterParams>,
|
|
||||||
pub insert_group: Option<CreateGridGroupParams>,
|
|
||||||
pub delete_group: Option<DeleteGroupParams>,
|
|
||||||
pub insert_sort: Option<CreateGridSortParams>,
|
|
||||||
pub delete_sort: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GridSettingChangesetParams {
|
|
||||||
pub fn is_filter_changed(&self) -> bool {
|
|
||||||
self.insert_filter.is_some() || self.delete_filter.is_some()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub struct CreateGridFilterParams {
|
|
||||||
pub field_id: String,
|
|
||||||
pub field_type_rev: FieldTypeRevision,
|
|
||||||
pub condition: u8,
|
|
||||||
pub content: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct DeleteFilterParams {
|
|
||||||
pub field_id: String,
|
|
||||||
pub filter_id: String,
|
|
||||||
pub field_type_rev: FieldTypeRevision,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct CreateGridGroupParams {
|
|
||||||
pub field_id: String,
|
|
||||||
pub field_type_rev: FieldTypeRevision,
|
|
||||||
pub content: Option<Vec<u8>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct DeleteGroupParams {
|
|
||||||
pub field_id: String,
|
|
||||||
pub group_id: String,
|
|
||||||
pub field_type_rev: FieldTypeRevision,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct CreateGridSortParams {
|
|
||||||
pub field_id: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
|
||||||
pub struct FieldChangesetParams {
|
|
||||||
pub field_id: String,
|
|
||||||
|
|
||||||
pub grid_id: String,
|
|
||||||
|
|
||||||
pub name: Option<String>,
|
|
||||||
|
|
||||||
pub desc: Option<String>,
|
|
||||||
|
|
||||||
pub field_type: Option<FieldTypeRevision>,
|
|
||||||
|
|
||||||
pub frozen: Option<bool>,
|
|
||||||
|
|
||||||
pub visibility: Option<bool>,
|
|
||||||
|
|
||||||
pub width: Option<i32>,
|
|
||||||
|
|
||||||
pub type_option_data: Option<Vec<u8>>,
|
|
||||||
}
|
|
@ -1,5 +1,4 @@
|
|||||||
pub mod folder;
|
pub mod folder;
|
||||||
pub mod grid;
|
|
||||||
pub mod parser;
|
pub mod parser;
|
||||||
pub mod revision;
|
pub mod revision;
|
||||||
pub mod text_block;
|
pub mod text_block;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user