mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
ci: fix unit test
This commit is contained in:
parent
6e6a812243
commit
23efbc00c1
@ -11,7 +11,8 @@ pub enum GridNotification {
|
||||
DidUpdateRow = 30,
|
||||
DidUpdateCell = 40,
|
||||
DidUpdateField = 50,
|
||||
DidUpdateGroup = 60,
|
||||
DidUpdateGroupView = 60,
|
||||
DidUpdateGroup = 61,
|
||||
}
|
||||
|
||||
impl std::default::Default for GridNotification {
|
||||
|
@ -104,7 +104,7 @@ impl TryInto<MoveGroupParams> for MoveGroupPayloadPB {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, ProtoBuf)]
|
||||
pub struct GroupsChangesetPB {
|
||||
pub struct GroupViewChangesetPB {
|
||||
#[pb(index = 1)]
|
||||
pub view_id: String,
|
||||
|
||||
@ -115,4 +115,4 @@ pub struct GroupsChangesetPB {
|
||||
pub deleted_groups: Vec<String>,
|
||||
}
|
||||
|
||||
impl GroupsChangesetPB {}
|
||||
impl GroupViewChangesetPB {}
|
||||
|
@ -35,17 +35,6 @@ pub(crate) async fn get_grid_setting_handler(
|
||||
data_result(grid_setting)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||
pub(crate) async fn update_grid_setting_handler(
|
||||
data: Data<GridSettingChangesetPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: GridSettingChangesetParams = data.into_inner().try_into()?;
|
||||
let editor = manager.open_grid(¶ms.grid_id).await?;
|
||||
let _ = editor.update_grid_setting(params).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
||||
pub(crate) async fn get_grid_blocks_handler(
|
||||
data: Data<QueryBlocksPayloadPB>,
|
||||
@ -441,9 +430,9 @@ pub(crate) async fn create_board_card_handler(
|
||||
pub(crate) async fn move_group_handler(
|
||||
data: Data<MoveGroupPayloadPB>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> DataResult<GroupsChangesetPB, FlowyError> {
|
||||
) -> FlowyResult<()> {
|
||||
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)
|
||||
let _ = editor.move_group(params).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ pub fn create(grid_manager: Arc<GridManager>) -> Module {
|
||||
.event(GridEvent::GetGrid, get_grid_handler)
|
||||
.event(GridEvent::GetGridBlocks, get_grid_blocks_handler)
|
||||
.event(GridEvent::GetGridSetting, get_grid_setting_handler)
|
||||
.event(GridEvent::UpdateGridSetting, update_grid_setting_handler)
|
||||
// .event(GridEvent::UpdateGridSetting, update_grid_setting_handler)
|
||||
// Field
|
||||
.event(GridEvent::GetFields, get_fields_handler)
|
||||
.event(GridEvent::UpdateField, update_field_handler)
|
||||
@ -219,6 +219,6 @@ pub enum GridEvent {
|
||||
#[event(input = "CreateBoardCardPayloadPB", output = "RowPB")]
|
||||
CreateBoardCard = 110,
|
||||
|
||||
#[event(input = "MoveGroupPayloadPB", output = "GroupsChangesetPB")]
|
||||
#[event(input = "MoveGroupPayloadPB")]
|
||||
MoveGroup = 111,
|
||||
}
|
||||
|
@ -343,9 +343,9 @@ impl GridRevisionEditor {
|
||||
Ok(row_pb)
|
||||
}
|
||||
|
||||
pub async fn move_group(&self, _params: MoveGroupParams) -> FlowyResult<GroupsChangesetPB> {
|
||||
//
|
||||
todo!()
|
||||
pub async fn move_group(&self, params: MoveGroupParams) -> FlowyResult<()> {
|
||||
let _ = self.view_manager.move_group(params).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn insert_rows(&self, row_revs: Vec<RowRevision>) -> FlowyResult<Vec<RowPB>> {
|
||||
@ -514,8 +514,13 @@ impl GridRevisionEditor {
|
||||
self.view_manager.get_filters().await
|
||||
}
|
||||
|
||||
pub async fn update_grid_setting(&self, params: GridSettingChangesetParams) -> FlowyResult<()> {
|
||||
let _ = self.view_manager.update_setting(params).await?;
|
||||
pub async fn update_filter(&self, params: CreateFilterParams) -> FlowyResult<()> {
|
||||
let _ = self.view_manager.update_filter(params).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn delete_filter(&self, params: DeleteFilterParams) -> FlowyResult<()> {
|
||||
let _ = self.view_manager.delete_filter(params).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::dart_notification::{send_dart_notification, GridNotification};
|
||||
use crate::entities::{
|
||||
CreateRowParams, GridFilterConfiguration, GridLayout, GridLayoutPB, GridSettingChangesetParams, GridSettingPB,
|
||||
GroupPB, GroupRowsChangesetPB, InsertedRowPB, RepeatedGridConfigurationFilterPB, RepeatedGridGroupConfigurationPB,
|
||||
RowPB,
|
||||
CreateFilterParams, CreateRowParams, DeleteFilterParams, GridFilterConfiguration, GridLayout, GridLayoutPB,
|
||||
GridSettingChangesetParams, GridSettingPB, GroupPB, GroupRowsChangesetPB, GroupViewChangesetPB, InsertedRowPB,
|
||||
MoveGroupParams, RepeatedGridConfigurationFilterPB, RepeatedGridGroupConfigurationPB, RowPB,
|
||||
};
|
||||
use crate::services::grid_editor_task::GridServiceTaskScheduler;
|
||||
use crate::services::grid_view_manager::{GridViewFieldDelegate, GridViewRowDelegate};
|
||||
@ -11,7 +11,8 @@ use crate::services::group::{
|
||||
};
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_grid_data_model::revision::{
|
||||
FieldRevision, FieldTypeRevision, GroupConfigurationRevision, RowChangeset, RowRevision,
|
||||
gen_grid_filter_id, FieldRevision, FieldTypeRevision, FilterConfigurationRevision, GroupConfigurationRevision,
|
||||
RowChangeset, RowRevision,
|
||||
};
|
||||
use flowy_revision::{RevisionCloudService, RevisionManager, RevisionObjectBuilder};
|
||||
use flowy_sync::client_grid::{GridViewRevisionChangeset, GridViewRevisionPad};
|
||||
@ -99,7 +100,7 @@ impl GridViewRevisionEditor {
|
||||
index: None,
|
||||
};
|
||||
let changeset = GroupRowsChangesetPB::insert(group_id.clone(), vec![inserted_row]);
|
||||
self.notify_did_update_group(changeset).await;
|
||||
self.notify_did_update_group_rows(changeset).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -114,7 +115,7 @@ impl GridViewRevisionEditor {
|
||||
.await
|
||||
{
|
||||
for changeset in changesets {
|
||||
self.notify_did_update_group(changeset).await;
|
||||
self.notify_did_update_group_rows(changeset).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -128,7 +129,7 @@ impl GridViewRevisionEditor {
|
||||
.await
|
||||
{
|
||||
for changeset in changesets {
|
||||
self.notify_did_update_group(changeset).await;
|
||||
self.notify_did_update_group_rows(changeset).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -150,7 +151,7 @@ impl GridViewRevisionEditor {
|
||||
{
|
||||
for changeset in changesets {
|
||||
tracing::trace!("Group: {} changeset: {}", changeset.group_id, changeset);
|
||||
self.notify_did_update_group(changeset).await;
|
||||
self.notify_did_update_group_rows(changeset).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -173,22 +174,19 @@ impl GridViewRevisionEditor {
|
||||
} else {
|
||||
self.group_service.read().await.groups().await
|
||||
};
|
||||
|
||||
Ok(groups.into_iter().map(GroupPB::from).collect())
|
||||
}
|
||||
|
||||
pub(crate) async fn move_group(&self, params: MoveGroupParams) -> FlowyResult<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub(crate) async fn get_setting(&self) -> GridSettingPB {
|
||||
let field_revs = self.field_delegate.get_field_revs().await;
|
||||
let grid_setting = make_grid_setting(&*self.pad.read().await, &field_revs);
|
||||
grid_setting
|
||||
}
|
||||
|
||||
pub(crate) async fn update_setting(&self, _changeset: GridSettingChangesetParams) -> FlowyResult<()> {
|
||||
// let _ = self.modify(|pad| Ok(pad.update_setting(changeset)?)).await;
|
||||
// Ok(())
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub(crate) async fn get_filters(&self) -> Vec<GridFilterConfiguration> {
|
||||
let field_revs = self.field_delegate.get_field_revs().await;
|
||||
match self.pad.read().await.get_all_filters(&field_revs) {
|
||||
@ -201,12 +199,44 @@ impl GridViewRevisionEditor {
|
||||
}
|
||||
}
|
||||
|
||||
async fn notify_did_update_group(&self, changeset: GroupRowsChangesetPB) {
|
||||
pub(crate) async fn insert_filter(&self, insert_filter: CreateFilterParams) -> FlowyResult<()> {
|
||||
self.modify(|pad| {
|
||||
let filter_rev = FilterConfigurationRevision {
|
||||
id: gen_grid_filter_id(),
|
||||
field_id: insert_filter.field_id.clone(),
|
||||
condition: insert_filter.condition,
|
||||
content: insert_filter.content,
|
||||
};
|
||||
let changeset = pad.insert_filter(&insert_filter.field_id, &insert_filter.field_type_rev, filter_rev)?;
|
||||
Ok(changeset)
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn delete_filter(&self, delete_filter: DeleteFilterParams) -> FlowyResult<()> {
|
||||
self.modify(|pad| {
|
||||
let changeset = pad.delete_filter(
|
||||
&delete_filter.field_id,
|
||||
&delete_filter.field_type_rev,
|
||||
&delete_filter.filter_id,
|
||||
)?;
|
||||
Ok(changeset)
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
async fn notify_did_update_group_rows(&self, changeset: GroupRowsChangesetPB) {
|
||||
send_dart_notification(&changeset.group_id, GridNotification::DidUpdateGroup)
|
||||
.payload(changeset)
|
||||
.send();
|
||||
}
|
||||
|
||||
async fn notify_did_update_view(&self, changeset: GroupViewChangesetPB) {
|
||||
send_dart_notification(&self.view_id, GridNotification::DidUpdateGroupView)
|
||||
.payload(changeset)
|
||||
.send();
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn modify<F>(&self, f: F) -> FlowyResult<()>
|
||||
where
|
||||
|
@ -1,5 +1,6 @@
|
||||
use crate::entities::{
|
||||
CreateRowParams, GridFilterConfiguration, GridSettingChangesetParams, GridSettingPB, RepeatedGridGroupPB, RowPB,
|
||||
CreateFilterParams, CreateRowParams, DeleteFilterParams, GridFilterConfiguration, GridSettingChangesetParams,
|
||||
GridSettingPB, MoveGroupParams, RepeatedGridGroupPB, RowPB,
|
||||
};
|
||||
use crate::manager::GridUser;
|
||||
use crate::services::grid_editor_task::GridServiceTaskScheduler;
|
||||
@ -98,23 +99,33 @@ impl GridViewManager {
|
||||
Ok(view_editor.get_setting().await)
|
||||
}
|
||||
|
||||
pub(crate) async fn update_setting(&self, params: GridSettingChangesetParams) -> FlowyResult<()> {
|
||||
let view_editor = self.get_default_view_editor().await?;
|
||||
let _ = view_editor.update_setting(params).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn get_filters(&self) -> FlowyResult<Vec<GridFilterConfiguration>> {
|
||||
let view_editor = self.get_default_view_editor().await?;
|
||||
Ok(view_editor.get_filters().await)
|
||||
}
|
||||
|
||||
pub(crate) async fn update_filter(&self, insert_filter: CreateFilterParams) -> FlowyResult<()> {
|
||||
let view_editor = self.get_default_view_editor().await?;
|
||||
view_editor.insert_filter(insert_filter).await
|
||||
}
|
||||
|
||||
pub(crate) async fn delete_filter(&self, delete_filter: DeleteFilterParams) -> FlowyResult<()> {
|
||||
let view_editor = self.get_default_view_editor().await?;
|
||||
view_editor.delete_filter(delete_filter).await
|
||||
}
|
||||
|
||||
pub(crate) async fn load_groups(&self) -> FlowyResult<RepeatedGridGroupPB> {
|
||||
let view_editor = self.get_default_view_editor().await?;
|
||||
let groups = view_editor.load_groups().await?;
|
||||
Ok(RepeatedGridGroupPB { items: groups })
|
||||
}
|
||||
|
||||
pub(crate) async fn move_group(&self, params: MoveGroupParams) -> FlowyResult<()> {
|
||||
let view_editor = self.get_default_view_editor().await?;
|
||||
let _s = view_editor.move_group(params).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// It may generate a RowChangeset when the Row was moved from one group to another.
|
||||
/// The return value, [RowChangeset], contains the changes made by the groups.
|
||||
///
|
||||
@ -131,9 +142,6 @@ impl GridViewManager {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn move_group(&self) {}
|
||||
|
||||
pub(crate) async fn get_view_editor(&self, view_id: &str) -> FlowyResult<Arc<GridViewRevisionEditor>> {
|
||||
debug_assert!(!view_id.is_empty());
|
||||
match self.view_editors.get(view_id) {
|
||||
|
@ -4,6 +4,7 @@ use flowy_grid_data_model::revision::{
|
||||
FieldRevision, FieldTypeRevision, GroupConfigurationContent, GroupConfigurationRevision, GroupRecordRevision,
|
||||
};
|
||||
|
||||
use indexmap::IndexMap;
|
||||
use lib_infra::future::AFFuture;
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -23,10 +24,9 @@ pub trait GroupConfigurationWriter: Send + Sync + 'static {
|
||||
|
||||
pub struct GenericGroupConfiguration<C> {
|
||||
pub configuration: C,
|
||||
// pub groups_map: IndexMap<String, Group>,
|
||||
configuration_id: String,
|
||||
field_rev: Arc<FieldRevision>,
|
||||
reader: Arc<dyn GroupConfigurationReader>,
|
||||
groups_map: IndexMap<String, Group>,
|
||||
writer: Arc<dyn GroupConfigurationWriter>,
|
||||
}
|
||||
|
||||
@ -45,30 +45,33 @@ where
|
||||
Ok(Self {
|
||||
configuration_id,
|
||||
field_rev,
|
||||
reader,
|
||||
groups_map: IndexMap::new(),
|
||||
writer,
|
||||
configuration,
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn group_records(&self) -> &[GroupRecordRevision] {
|
||||
todo!()
|
||||
pub(crate) fn groups(&self) -> Vec<&Group> {
|
||||
self.groups_map.values().collect()
|
||||
}
|
||||
pub(crate) async fn merge_groups(&mut self, groups: &[Group]) -> FlowyResult<()> {
|
||||
match merge_groups(self.configuration.get_groups(), groups) {
|
||||
None => Ok(()),
|
||||
Some(new_groups) => {
|
||||
self.configuration.set_groups(new_groups);
|
||||
let _ = self.save_configuration().await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn clone_groups(&self) -> Vec<Group> {
|
||||
self.groups_map.values().cloned().collect()
|
||||
}
|
||||
|
||||
pub(crate) async fn merge_groups(&mut self, groups: Vec<Group>) -> FlowyResult<()> {
|
||||
let (group_revs, groups) = merge_groups(self.configuration.get_groups(), groups);
|
||||
self.configuration.set_groups(group_revs);
|
||||
let _ = self.save_configuration().await?;
|
||||
groups.into_iter().for_each(|group| {
|
||||
self.groups_map.insert(group.id.clone(), group);
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn hide_group(&mut self, group_id: &str) -> FlowyResult<()> {
|
||||
self.configuration.mut_group(group_id, |group_rev| {
|
||||
self.configuration.with_mut_group(group_id, |group_rev| {
|
||||
group_rev.visible = false;
|
||||
});
|
||||
let _ = self.save_configuration().await?;
|
||||
@ -77,13 +80,27 @@ where
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn show_group(&mut self, group_id: &str) -> FlowyResult<()> {
|
||||
self.configuration.mut_group(group_id, |group_rev| {
|
||||
self.configuration.with_mut_group(group_id, |group_rev| {
|
||||
group_rev.visible = true;
|
||||
});
|
||||
let _ = self.save_configuration().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn with_mut_groups(&mut self, mut mut_groups_fn: impl FnMut(&mut Group)) {
|
||||
self.groups_map.iter_mut().for_each(|(_, group)| {
|
||||
mut_groups_fn(group);
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn get_mut_group(&mut self, group_id: &str) -> Option<&mut Group> {
|
||||
self.groups_map.get_mut(group_id)
|
||||
}
|
||||
|
||||
pub(crate) fn get_group(&mut self, group_id: &str) -> Option<&Group> {
|
||||
self.groups_map.get(group_id)
|
||||
}
|
||||
|
||||
pub async fn save_configuration(&self) -> FlowyResult<()> {
|
||||
let content = self.configuration.to_configuration_content()?;
|
||||
let _ = self
|
||||
@ -103,29 +120,32 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn merge_groups(old_group: &[GroupRecordRevision], groups: &[Group]) -> Option<Vec<GroupRecordRevision>> {
|
||||
fn merge_groups(old_group_revs: &[GroupRecordRevision], groups: Vec<Group>) -> (Vec<GroupRecordRevision>, Vec<Group>) {
|
||||
// tracing::trace!("Merge group: old: {}, new: {}", old_group.len(), groups.len());
|
||||
if old_group.is_empty() {
|
||||
if old_group_revs.is_empty() {
|
||||
let new_groups = groups
|
||||
.iter()
|
||||
.map(|group| GroupRecordRevision::new(group.id.clone()))
|
||||
.collect();
|
||||
return Some(new_groups);
|
||||
return (new_groups, groups);
|
||||
}
|
||||
|
||||
let new_groups = groups
|
||||
.iter()
|
||||
.filter(|group| !old_group.iter().any(|group_rev| group_rev.group_id == group.id))
|
||||
.collect::<Vec<&Group>>();
|
||||
let mut group_map: IndexMap<String, Group> = IndexMap::new();
|
||||
groups.into_iter().for_each(|group| {
|
||||
group_map.insert(group.id.clone(), group);
|
||||
});
|
||||
|
||||
if new_groups.is_empty() {
|
||||
return None;
|
||||
let mut sorted_groups: Vec<Group> = vec![];
|
||||
for group_rev in old_group_revs {
|
||||
if let Some(group) = group_map.remove(&group_rev.group_id) {
|
||||
sorted_groups.push(group);
|
||||
}
|
||||
}
|
||||
|
||||
let mut old_group = old_group.to_vec();
|
||||
let new_groups = new_groups
|
||||
sorted_groups.extend(group_map.into_values().collect::<Vec<Group>>());
|
||||
let new_group_revs = sorted_groups
|
||||
.iter()
|
||||
.map(|group| GroupRecordRevision::new(group.id.clone()));
|
||||
old_group.extend(new_groups);
|
||||
Some(old_group)
|
||||
.map(|group| GroupRecordRevision::new(group.id.clone()))
|
||||
.collect::<Vec<GroupRecordRevision>>();
|
||||
|
||||
(new_group_revs, sorted_groups)
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ use flowy_error::FlowyResult;
|
||||
use flowy_grid_data_model::revision::{
|
||||
FieldRevision, GroupConfigurationContent, RowChangeset, RowRevision, TypeOptionDataDeserializer,
|
||||
};
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
@ -36,7 +35,7 @@ pub trait GroupGenerator {
|
||||
pub trait GroupControllerSharedOperation: Send + Sync {
|
||||
// The field that is used for grouping the rows
|
||||
fn field_id(&self) -> &str;
|
||||
fn groups(&self) -> &[Group];
|
||||
fn groups(&self) -> Vec<Group>;
|
||||
fn fill_groups(&mut self, row_revs: &[Arc<RowRevision>], field_rev: &FieldRevision) -> FlowyResult<Vec<Group>>;
|
||||
fn did_update_row(
|
||||
&mut self,
|
||||
@ -65,7 +64,6 @@ pub trait GroupControllerSharedOperation: Send + Sync {
|
||||
/// P: the parser that impl [CellBytesParser] for the CellBytes
|
||||
pub struct GenericGroupController<C, T, G, P> {
|
||||
pub field_id: String,
|
||||
pub groups_map: IndexMap<String, Group>,
|
||||
pub type_option: Option<T>,
|
||||
pub configuration: GenericGroupConfiguration<C>,
|
||||
/// default_group is used to store the rows that don't belong to any groups.
|
||||
@ -87,7 +85,7 @@ where
|
||||
let field_type_rev = field_rev.ty;
|
||||
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 _ = configuration.merge_groups(&groups).await?;
|
||||
let _ = configuration.merge_groups(groups).await?;
|
||||
let default_group = Group::new(
|
||||
DEFAULT_GROUP_ID.to_owned(),
|
||||
field_rev.id.clone(),
|
||||
@ -97,7 +95,6 @@ where
|
||||
|
||||
Ok(Self {
|
||||
field_id: field_rev.id.clone(),
|
||||
groups_map: groups.into_iter().map(|group| (group.id.clone(), group)).collect(),
|
||||
default_group,
|
||||
type_option,
|
||||
configuration,
|
||||
@ -117,8 +114,8 @@ where
|
||||
&self.field_id
|
||||
}
|
||||
|
||||
fn groups(&self) -> &[Group] {
|
||||
todo!()
|
||||
fn groups(&self) -> Vec<Group> {
|
||||
self.configuration.clone_groups()
|
||||
}
|
||||
|
||||
fn fill_groups(&mut self, row_revs: &[Arc<RowRevision>], field_rev: &FieldRevision) -> FlowyResult<Vec<Group>> {
|
||||
@ -127,7 +124,7 @@ where
|
||||
let mut group_rows: Vec<GroupRow> = vec![];
|
||||
let cell_bytes = decode_any_cell_data(cell_rev.data.clone(), field_rev);
|
||||
let cell_data = cell_bytes.parser::<P>()?;
|
||||
for group in self.groups_map.values() {
|
||||
for group in self.configuration.groups() {
|
||||
if self.can_group(&group.content, &cell_data) {
|
||||
group_rows.push(GroupRow {
|
||||
row: row_rev.into(),
|
||||
@ -140,7 +137,7 @@ where
|
||||
self.default_group.add_row(row_rev.into());
|
||||
} else {
|
||||
for group_row in group_rows {
|
||||
if let Some(group) = self.groups_map.get_mut(&group_row.group_id) {
|
||||
if let Some(group) = self.configuration.get_mut_group(&group_row.group_id) {
|
||||
group.add_row(group_row.row);
|
||||
}
|
||||
}
|
||||
@ -151,7 +148,7 @@ where
|
||||
}
|
||||
|
||||
let default_group = self.default_group.clone();
|
||||
let mut groups: Vec<Group> = self.groups_map.values().cloned().collect();
|
||||
let mut groups: Vec<Group> = self.configuration.clone_groups();
|
||||
if !default_group.number_of_row() == 0 {
|
||||
groups.push(default_group);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ impl GroupAction for MultiSelectGroupController {
|
||||
|
||||
fn add_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec<GroupRowsChangesetPB> {
|
||||
let mut changesets = vec![];
|
||||
self.groups_map.iter_mut().for_each(|(_, group): (_, &mut Group)| {
|
||||
self.configuration.with_mut_groups(|group| {
|
||||
add_row(group, &mut changesets, cell_data, row_rev);
|
||||
});
|
||||
changesets
|
||||
@ -39,7 +39,7 @@ impl GroupAction for MultiSelectGroupController {
|
||||
cell_data: &Self::CellDataType,
|
||||
) -> Vec<GroupRowsChangesetPB> {
|
||||
let mut changesets = vec![];
|
||||
self.groups_map.iter_mut().for_each(|(_, group): (_, &mut Group)| {
|
||||
self.configuration.with_mut_groups(|group| {
|
||||
remove_row(group, &mut changesets, cell_data, row_rev);
|
||||
});
|
||||
changesets
|
||||
@ -54,7 +54,7 @@ impl GroupAction for MultiSelectGroupController {
|
||||
to_row_id: &str,
|
||||
) -> Vec<GroupRowsChangesetPB> {
|
||||
let mut group_changeset = vec![];
|
||||
self.groups_map.iter_mut().for_each(|(_, group): (_, &mut Group)| {
|
||||
self.configuration.with_mut_groups(|group| {
|
||||
move_row(
|
||||
group,
|
||||
&mut group_changeset,
|
||||
@ -71,7 +71,7 @@ impl GroupAction for MultiSelectGroupController {
|
||||
|
||||
impl GroupController for MultiSelectGroupController {
|
||||
fn will_create_row(&mut self, row_rev: &mut RowRevision, field_rev: &FieldRevision, group_id: &str) {
|
||||
let group: Option<&Group> = self.groups_map.get(group_id);
|
||||
let group: Option<&Group> = self.configuration.get_group(group_id);
|
||||
match group {
|
||||
None => tracing::warn!("Can not find the group: {}", group_id),
|
||||
Some(group) => {
|
||||
|
@ -27,7 +27,7 @@ impl GroupAction for SingleSelectGroupController {
|
||||
|
||||
fn add_row_if_match(&mut self, row_rev: &RowRevision, cell_data: &Self::CellDataType) -> Vec<GroupRowsChangesetPB> {
|
||||
let mut changesets = vec![];
|
||||
self.groups_map.iter_mut().for_each(|(_, group): (_, &mut Group)| {
|
||||
self.configuration.with_mut_groups(|group| {
|
||||
add_row(group, &mut changesets, cell_data, row_rev);
|
||||
});
|
||||
changesets
|
||||
@ -39,7 +39,7 @@ impl GroupAction for SingleSelectGroupController {
|
||||
cell_data: &Self::CellDataType,
|
||||
) -> Vec<GroupRowsChangesetPB> {
|
||||
let mut changesets = vec![];
|
||||
self.groups_map.iter_mut().for_each(|(_, group): (_, &mut Group)| {
|
||||
self.configuration.with_mut_groups(|group| {
|
||||
remove_row(group, &mut changesets, cell_data, row_rev);
|
||||
});
|
||||
changesets
|
||||
@ -54,7 +54,7 @@ impl GroupAction for SingleSelectGroupController {
|
||||
to_row_id: &str,
|
||||
) -> Vec<GroupRowsChangesetPB> {
|
||||
let mut group_changeset = vec![];
|
||||
self.groups_map.iter_mut().for_each(|(_, group): (_, &mut Group)| {
|
||||
self.configuration.with_mut_groups(|group| {
|
||||
move_row(
|
||||
group,
|
||||
&mut group_changeset,
|
||||
@ -71,7 +71,7 @@ impl GroupAction for SingleSelectGroupController {
|
||||
|
||||
impl GroupController for SingleSelectGroupController {
|
||||
fn will_create_row(&mut self, row_rev: &mut RowRevision, field_rev: &FieldRevision, group_id: &str) {
|
||||
let group: Option<&mut Group> = self.groups_map.get_mut(group_id);
|
||||
let group: Option<&mut Group> = self.configuration.get_mut_group(group_id);
|
||||
match group {
|
||||
None => {}
|
||||
Some(group) => {
|
||||
|
@ -36,12 +36,11 @@ impl GroupService {
|
||||
}
|
||||
|
||||
pub(crate) async fn groups(&self) -> Vec<Group> {
|
||||
// if let Some(group_controller) = self.group_controller.as_ref() {
|
||||
// group_controller.read().await.groups()
|
||||
// } else {
|
||||
// vec![]
|
||||
// }
|
||||
todo!()
|
||||
if let Some(group_controller) = self.group_controller.as_ref() {
|
||||
group_controller.read().await.groups()
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn load_groups(
|
||||
|
@ -9,10 +9,6 @@ use flowy_grid_data_model::revision::{FieldRevision, FieldTypeRevision};
|
||||
use crate::grid::grid_editor::GridEditorTest;
|
||||
|
||||
pub enum FilterScript {
|
||||
#[allow(dead_code)]
|
||||
UpdateGridSetting {
|
||||
params: GridSettingChangesetParams,
|
||||
},
|
||||
InsertGridTableFilter {
|
||||
payload: CreateGridFilterPayloadPB,
|
||||
},
|
||||
@ -49,27 +45,18 @@ impl GridFilterTest {
|
||||
|
||||
pub async fn run_script(&mut self, script: FilterScript) {
|
||||
match script {
|
||||
FilterScript::UpdateGridSetting { params } => {
|
||||
let _ = self.editor.update_grid_setting(params).await.unwrap();
|
||||
}
|
||||
|
||||
FilterScript::InsertGridTableFilter { payload } => {
|
||||
let params: CreateFilterParams = payload.try_into().unwrap();
|
||||
let layout_type = GridLayout::Table;
|
||||
let params = GridSettingChangesetBuilder::new(&self.grid_id, &layout_type)
|
||||
.insert_filter(params)
|
||||
.build();
|
||||
let _ = self.editor.update_grid_setting(params).await.unwrap();
|
||||
let _ = self.editor.update_filter(params).await.unwrap();
|
||||
}
|
||||
FilterScript::AssertTableFilterCount { count } => {
|
||||
let filters = self.editor.get_grid_filter().await.unwrap();
|
||||
assert_eq!(count as usize, filters.len());
|
||||
}
|
||||
FilterScript::DeleteGridTableFilter { filter_id, field_rev} => {
|
||||
let layout_type = GridLayout::Table;
|
||||
let params = GridSettingChangesetBuilder::new(&self.grid_id, &layout_type)
|
||||
.delete_filter(DeleteFilterParams { field_id: field_rev.id, filter_id, field_type_rev: field_rev.ty })
|
||||
.build();
|
||||
let _ = self.editor.update_grid_setting(params).await.unwrap();
|
||||
let params = DeleteFilterParams { field_id: field_rev.id, filter_id, field_type_rev: field_rev.ty };
|
||||
let _ = self.editor.delete_filter(params).await.unwrap();
|
||||
}
|
||||
FilterScript::AssertGridSetting { expected_setting } => {
|
||||
let setting = self.editor.get_grid_setting().await.unwrap();
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::grid::grid_editor::GridEditorTest;
|
||||
use flowy_grid::entities::{CreateRowParams, FieldType, GridLayout, GroupPB, MoveRowParams, RowPB};
|
||||
use flowy_grid::entities::{CreateRowParams, FieldType, GridLayout, GroupPB, MoveGroupParams, MoveRowParams, RowPB};
|
||||
use flowy_grid::services::cell::insert_select_option_cell;
|
||||
use flowy_grid_data_model::revision::RowChangeset;
|
||||
|
||||
@ -32,6 +32,10 @@ pub enum GroupScript {
|
||||
row_index: usize,
|
||||
to_group_index: usize,
|
||||
},
|
||||
MoveGroup {
|
||||
from_group_index: usize,
|
||||
to_group_index: usize,
|
||||
},
|
||||
}
|
||||
|
||||
pub struct GridGroupTest {
|
||||
@ -84,7 +88,6 @@ impl GridGroupTest {
|
||||
//
|
||||
let group = self.group_at_index(group_index).await;
|
||||
let compare_row = group.rows.get(row_index).unwrap().clone();
|
||||
|
||||
assert_eq!(row.id, compare_row.id);
|
||||
}
|
||||
GroupScript::CreateRow { group_index } => {
|
||||
@ -125,6 +128,20 @@ impl GridGroupTest {
|
||||
row_changeset.cell_by_field_id.insert(field_id, cell_rev);
|
||||
self.editor.update_row(row_changeset).await.unwrap();
|
||||
}
|
||||
GroupScript::MoveGroup {
|
||||
from_group_index,
|
||||
to_group_index,
|
||||
} => {
|
||||
let from_group = self.group_at_index(from_group_index).await;
|
||||
let to_group = self.group_at_index(to_group_index).await;
|
||||
let params = MoveGroupParams {
|
||||
view_id: self.editor.grid_id.clone(),
|
||||
from_group_id: from_group.group_id,
|
||||
to_group_id: to_group.group_id,
|
||||
};
|
||||
self.editor.move_group(params).await.unwrap();
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,19 +6,19 @@ use serde_repr::*;
|
||||
pub trait GroupConfigurationContent: Sized {
|
||||
fn from_configuration_content(s: &str) -> Result<Self, serde_json::Error>;
|
||||
|
||||
fn to_configuration_content(&self) -> Result<String, serde_json::Error>;
|
||||
|
||||
fn get_groups(&self) -> &[GroupRecordRevision] {
|
||||
&[]
|
||||
}
|
||||
|
||||
fn mut_group<F>(&mut self, _group_id: &str, _f: F)
|
||||
fn set_groups(&mut self, _new_groups: Vec<GroupRecordRevision>) {}
|
||||
|
||||
fn with_mut_group<F>(&mut self, _group_id: &str, _f: F)
|
||||
where
|
||||
F: FnOnce(&mut GroupRecordRevision),
|
||||
{
|
||||
}
|
||||
|
||||
fn set_groups(&mut self, _new_groups: Vec<GroupRecordRevision>) {}
|
||||
|
||||
fn to_configuration_content(&self) -> Result<String, serde_json::Error>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
|
||||
@ -112,11 +112,19 @@ impl GroupConfigurationContent for SelectOptionGroupConfigurationRevision {
|
||||
serde_json::from_str(s)
|
||||
}
|
||||
|
||||
fn to_configuration_content(&self) -> Result<String, Error> {
|
||||
serde_json::to_string(self)
|
||||
}
|
||||
|
||||
fn get_groups(&self) -> &[GroupRecordRevision] {
|
||||
&self.groups
|
||||
}
|
||||
|
||||
fn mut_group<F>(&mut self, group_id: &str, f: F)
|
||||
fn set_groups(&mut self, new_groups: Vec<GroupRecordRevision>) {
|
||||
self.groups = new_groups;
|
||||
}
|
||||
|
||||
fn with_mut_group<F>(&mut self, group_id: &str, f: F)
|
||||
where
|
||||
F: FnOnce(&mut GroupRecordRevision),
|
||||
{
|
||||
@ -125,14 +133,6 @@ impl GroupConfigurationContent for SelectOptionGroupConfigurationRevision {
|
||||
Some(group) => f(group),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_groups(&mut self, new_groups: Vec<GroupRecordRevision>) {
|
||||
self.groups = new_groups;
|
||||
}
|
||||
|
||||
fn to_configuration_content(&self) -> Result<String, Error> {
|
||||
serde_json::to_string(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize)]
|
||||
@ -142,6 +142,7 @@ pub struct GroupRecordRevision {
|
||||
#[serde(default = "DEFAULT_GROUP_RECORD_VISIBILITY")]
|
||||
pub visible: bool,
|
||||
}
|
||||
|
||||
const DEFAULT_GROUP_RECORD_VISIBILITY: fn() -> bool = || true;
|
||||
|
||||
impl GroupRecordRevision {
|
||||
|
@ -52,20 +52,6 @@ impl GridViewRevisionPad {
|
||||
self.groups.get_all_objects(field_revs)
|
||||
}
|
||||
|
||||
pub fn insert_group_configuration(
|
||||
&mut self,
|
||||
field_id: &str,
|
||||
field_type: &FieldTypeRevision,
|
||||
group_rev: GroupConfigurationRevision,
|
||||
) -> CollaborateResult<Option<GridViewRevisionChangeset>> {
|
||||
self.modify(|view| {
|
||||
// only one group can be set
|
||||
view.groups.remove_all();
|
||||
view.groups.insert_object(field_id, field_type, group_rev);
|
||||
Ok(Some(()))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_mut_group<F: FnOnce(&mut GroupConfigurationRevision)>(
|
||||
&mut self,
|
||||
field_id: &str,
|
||||
|
Loading…
Reference in New Issue
Block a user