mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: refactor grid setting
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
use crate::entities::FieldType;
|
||||
use flowy_derive::ProtoBuf;
|
||||
use flowy_error::ErrorCode;
|
||||
use flowy_grid_data_model::parser::NotEmptyStr;
|
||||
use flowy_grid_data_model::revision::GridGroupRevision;
|
||||
use flowy_sync::entities::grid::CreateGridGroupParams;
|
||||
use flowy_sync::entities::grid::{CreateGridGroupParams, DeleteGroupParams};
|
||||
use std::convert::TryInto;
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -11,8 +12,8 @@ pub struct GridGroupPB {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
#[pb(index = 2, one_of)]
|
||||
pub group_field_id: Option<String>,
|
||||
#[pb(index = 2)]
|
||||
pub group_field_id: String,
|
||||
|
||||
#[pb(index = 3, one_of)]
|
||||
pub sub_group_field_id: Option<String>,
|
||||
@ -50,27 +51,64 @@ impl std::convert::From<Vec<Arc<GridGroupRevision>>> for RepeatedGridGroupPB {
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct CreateGridGroupPayloadPB {
|
||||
#[pb(index = 1, one_of)]
|
||||
pub field_id: Option<String>,
|
||||
#[pb(index = 1)]
|
||||
pub field_id: String,
|
||||
|
||||
#[pb(index = 2, one_of)]
|
||||
pub sub_field_id: Option<String>,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub field_type: FieldType,
|
||||
}
|
||||
|
||||
impl TryInto<CreateGridGroupParams> for CreateGridGroupPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<CreateGridGroupParams, Self::Error> {
|
||||
let field_id = match self.field_id {
|
||||
None => None,
|
||||
Some(field_id) => Some(NotEmptyStr::parse(field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?.0),
|
||||
};
|
||||
let field_id = NotEmptyStr::parse(self.field_id)
|
||||
.map_err(|_| ErrorCode::FieldIdIsEmpty)?
|
||||
.0;
|
||||
|
||||
let sub_field_id = match self.sub_field_id {
|
||||
None => None,
|
||||
Some(field_id) => Some(NotEmptyStr::parse(field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?.0),
|
||||
};
|
||||
|
||||
Ok(CreateGridGroupParams { field_id, sub_field_id })
|
||||
Ok(CreateGridGroupParams {
|
||||
field_id,
|
||||
sub_field_id,
|
||||
field_type_rev: self.field_type.into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct DeleteGroupPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub field_id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub group_id: String,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub field_type: FieldType,
|
||||
}
|
||||
|
||||
impl TryInto<DeleteGroupParams> for DeleteGroupPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<DeleteGroupParams, Self::Error> {
|
||||
let field_id = NotEmptyStr::parse(self.field_id)
|
||||
.map_err(|_| ErrorCode::FieldIdIsEmpty)?
|
||||
.0;
|
||||
let group_id = NotEmptyStr::parse(self.group_id)
|
||||
.map_err(|_| ErrorCode::FieldIdIsEmpty)?
|
||||
.0;
|
||||
|
||||
Ok(DeleteGroupParams {
|
||||
field_id,
|
||||
field_type_rev: self.field_type.into(),
|
||||
group_id,
|
||||
})
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
mod group;
|
||||
|
||||
pub use group::*;
|
@ -1,12 +1,12 @@
|
||||
use crate::entities::{
|
||||
CreateGridFilterPayloadPB, CreateGridGroupPayloadPB, CreateGridSortPayloadPB, DeleteFilterPayloadPB,
|
||||
RepeatedGridFilterPB, RepeatedGridGroupPB, RepeatedGridSortPB,
|
||||
DeleteGroupPayloadPB, RepeatedGridFilterPB, RepeatedGridGroupPB, RepeatedGridSortPB,
|
||||
};
|
||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||
use flowy_error::ErrorCode;
|
||||
use flowy_grid_data_model::parser::NotEmptyStr;
|
||||
use flowy_grid_data_model::revision::GridLayoutRevision;
|
||||
use flowy_sync::entities::grid::GridSettingChangesetParams;
|
||||
use flowy_sync::entities::grid::{DeleteGroupParams, GridSettingChangesetParams};
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
use strum::IntoEnumIterator;
|
||||
@ -97,7 +97,7 @@ pub struct GridSettingChangesetPayloadPB {
|
||||
pub insert_group: Option<CreateGridGroupPayloadPB>,
|
||||
|
||||
#[pb(index = 6, one_of)]
|
||||
pub delete_group: Option<String>,
|
||||
pub delete_group: Option<DeleteGroupPayloadPB>,
|
||||
|
||||
#[pb(index = 7, one_of)]
|
||||
pub insert_sort: Option<CreateGridSortPayloadPB>,
|
||||
@ -130,8 +130,8 @@ impl TryInto<GridSettingChangesetParams> for GridSettingChangesetPayloadPB {
|
||||
};
|
||||
|
||||
let delete_group = match self.delete_group {
|
||||
Some(payload) => Some(payload.try_into()?),
|
||||
None => None,
|
||||
Some(filter_id) => Some(NotEmptyStr::parse(filter_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?.0),
|
||||
};
|
||||
|
||||
let insert_sort = match self.insert_sort {
|
||||
|
@ -6,6 +6,7 @@ use crate::services::block_manager::GridBlockManager;
|
||||
use crate::services::cell::{apply_cell_data_changeset, decode_any_cell_data, CellBytes};
|
||||
use crate::services::field::{default_type_option_builder_from_type, type_option_builder_from_bytes, FieldBuilder};
|
||||
use crate::services::filter::{GridFilterChangeset, GridFilterService};
|
||||
use crate::services::group::GridGroupService;
|
||||
use crate::services::persistence::block_index::BlockIndexCache;
|
||||
use crate::services::row::{
|
||||
make_grid_blocks, make_row_from_row_rev, make_rows_from_row_revs, GridBlockSnapshot, RowRevisionBuilder,
|
||||
@ -34,6 +35,7 @@ pub struct GridRevisionEditor {
|
||||
block_manager: Arc<GridBlockManager>,
|
||||
#[allow(dead_code)]
|
||||
pub(crate) filter_service: Arc<GridFilterService>,
|
||||
pub(crate) group_service: Arc<GridGroupService>,
|
||||
}
|
||||
|
||||
impl Drop for GridRevisionEditor {
|
||||
@ -59,6 +61,7 @@ impl GridRevisionEditor {
|
||||
let block_manager = Arc::new(GridBlockManager::new(grid_id, &user, block_meta_revs, persistence).await?);
|
||||
let filter_service =
|
||||
Arc::new(GridFilterService::new(grid_pad.clone(), block_manager.clone(), task_scheduler.clone()).await);
|
||||
let group_service = Arc::new(GridGroupService::new());
|
||||
let editor = Arc::new(Self {
|
||||
grid_id: grid_id.to_owned(),
|
||||
user,
|
||||
@ -66,6 +69,7 @@ impl GridRevisionEditor {
|
||||
rev_manager,
|
||||
block_manager,
|
||||
filter_service,
|
||||
group_service,
|
||||
});
|
||||
|
||||
Ok(editor)
|
||||
|
@ -19,6 +19,7 @@ impl GridTaskHandler for GridRevisionEditor {
|
||||
Box::pin(async move {
|
||||
match content {
|
||||
TaskContent::Snapshot => {}
|
||||
TaskContent::Group => {}
|
||||
TaskContent::Filter(context) => self.filter_service.process(context).await?,
|
||||
}
|
||||
Ok(())
|
||||
|
@ -0,0 +1,7 @@
|
||||
pub struct GridGroupService {}
|
||||
|
||||
impl GridGroupService {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
3
frontend/rust-lib/flowy-grid/src/services/group/mod.rs
Normal file
3
frontend/rust-lib/flowy-grid/src/services/group/mod.rs
Normal file
@ -0,0 +1,3 @@
|
||||
mod group_service;
|
||||
|
||||
pub use group_service::*;
|
@ -7,6 +7,7 @@ pub mod field;
|
||||
mod filter;
|
||||
pub mod grid_editor;
|
||||
mod grid_editor_task;
|
||||
pub mod group;
|
||||
pub mod persistence;
|
||||
pub mod row;
|
||||
pub mod setting;
|
||||
|
@ -27,6 +27,7 @@ impl GridTaskQueue {
|
||||
|
||||
let task_type = match task.content.as_ref().unwrap() {
|
||||
TaskContent::Snapshot => TaskType::Snapshot,
|
||||
TaskContent::Group => TaskType::Group,
|
||||
TaskContent::Filter { .. } => TaskType::Filter,
|
||||
};
|
||||
let pending_task = PendingTask {
|
||||
|
@ -10,6 +10,8 @@ pub enum TaskType {
|
||||
Filter,
|
||||
/// Generate snapshot for grid, unused by now.
|
||||
Snapshot,
|
||||
|
||||
Group,
|
||||
}
|
||||
|
||||
impl PartialEq for TaskType {
|
||||
@ -44,9 +46,15 @@ impl PartialOrd for PendingTask {
|
||||
impl Ord for PendingTask {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
match (self.ty, other.ty) {
|
||||
// Snapshot
|
||||
(TaskType::Snapshot, TaskType::Snapshot) => Ordering::Equal,
|
||||
(TaskType::Snapshot, _) => Ordering::Greater,
|
||||
(_, TaskType::Snapshot) => Ordering::Less,
|
||||
// Group
|
||||
(TaskType::Group, TaskType::Group) => self.id.cmp(&other.id).reverse(),
|
||||
(TaskType::Group, _) => Ordering::Greater,
|
||||
(_, TaskType::Group) => Ordering::Greater,
|
||||
// Filter
|
||||
(TaskType::Filter, TaskType::Filter) => self.id.cmp(&other.id).reverse(),
|
||||
}
|
||||
}
|
||||
@ -59,6 +67,7 @@ pub(crate) struct FilterTaskContext {
|
||||
pub(crate) enum TaskContent {
|
||||
#[allow(dead_code)]
|
||||
Snapshot,
|
||||
Group,
|
||||
Filter(FilterTaskContext),
|
||||
}
|
||||
|
||||
|
@ -54,24 +54,14 @@ pub fn make_default_board() -> BuildGridContext {
|
||||
let single_select_field_id = single_select_field.id.clone();
|
||||
grid_builder.add_field(single_select_field);
|
||||
|
||||
let field_revs = grid_builder.field_revs();
|
||||
let block_id = grid_builder.block_id();
|
||||
|
||||
// rows
|
||||
let row_1 = RowRevisionBuilder::new(block_id, field_revs)
|
||||
.insert_select_option_cell(&single_select_field_id, not_started_option.id.clone())
|
||||
.build();
|
||||
grid_builder.add_row(row_1);
|
||||
|
||||
let row_2 = RowRevisionBuilder::new(block_id, field_revs)
|
||||
.insert_select_option_cell(&single_select_field_id, not_started_option.id.clone())
|
||||
.build();
|
||||
grid_builder.add_row(row_2);
|
||||
|
||||
let row_3 = RowRevisionBuilder::new(block_id, field_revs)
|
||||
.insert_select_option_cell(&single_select_field_id, not_started_option.id.clone())
|
||||
.build();
|
||||
grid_builder.add_row(row_3);
|
||||
for _ in 0..3 {
|
||||
grid_builder.add_row(
|
||||
RowRevisionBuilder::new(grid_builder.block_id(), grid_builder.field_revs())
|
||||
.insert_select_option_cell(&single_select_field_id, not_started_option.id.clone())
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
grid_builder.build()
|
||||
}
|
||||
|
@ -97,6 +97,7 @@ async fn create_view(sdk: &FlowySDKTest, app_id: &str, data_type: ViewDataTypePB
|
||||
desc: "".to_string(),
|
||||
thumbnail: Some("http://1.png".to_string()),
|
||||
data_type,
|
||||
sub_data_type: None,
|
||||
plugin_type: 0,
|
||||
data,
|
||||
};
|
||||
|
Reference in New Issue
Block a user