Skip to content

Commit 23efbc0

Browse files
committed
ci: fix unit test
1 parent 6e6a812 commit 23efbc0

File tree

16 files changed

+192
-152
lines changed

16 files changed

+192
-152
lines changed

frontend/rust-lib/flowy-grid/src/dart_notification.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ pub enum GridNotification {
1111
DidUpdateRow = 30,
1212
DidUpdateCell = 40,
1313
DidUpdateField = 50,
14-
DidUpdateGroup = 60,
14+
DidUpdateGroupView = 60,
15+
DidUpdateGroup = 61,
1516
}
1617

1718
impl std::default::Default for GridNotification {

frontend/rust-lib/flowy-grid/src/entities/group_entities/group_changeset.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl TryInto<MoveGroupParams> for MoveGroupPayloadPB {
104104
}
105105

106106
#[derive(Debug, Default, ProtoBuf)]
107-
pub struct GroupsChangesetPB {
107+
pub struct GroupViewChangesetPB {
108108
#[pb(index = 1)]
109109
pub view_id: String,
110110

@@ -115,4 +115,4 @@ pub struct GroupsChangesetPB {
115115
pub deleted_groups: Vec<String>,
116116
}
117117

118-
impl GroupsChangesetPB {}
118+
impl GroupViewChangesetPB {}

frontend/rust-lib/flowy-grid/src/event_handler.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@ pub(crate) async fn get_grid_setting_handler(
3535
data_result(grid_setting)
3636
}
3737

38-
#[tracing::instrument(level = "trace", skip(data, manager), err)]
39-
pub(crate) async fn update_grid_setting_handler(
40-
data: Data<GridSettingChangesetPayloadPB>,
41-
manager: AppData<Arc<GridManager>>,
42-
) -> Result<(), FlowyError> {
43-
let params: GridSettingChangesetParams = data.into_inner().try_into()?;
44-
let editor = manager.open_grid(&params.grid_id).await?;
45-
let _ = editor.update_grid_setting(params).await?;
46-
Ok(())
47-
}
48-
4938
#[tracing::instrument(level = "debug", skip(data, manager), err)]
5039
pub(crate) async fn get_grid_blocks_handler(
5140
data: Data<QueryBlocksPayloadPB>,
@@ -441,9 +430,9 @@ pub(crate) async fn create_board_card_handler(
441430
pub(crate) async fn move_group_handler(
442431
data: Data<MoveGroupPayloadPB>,
443432
manager: AppData<Arc<GridManager>>,
444-
) -> DataResult<GroupsChangesetPB, FlowyError> {
433+
) -> FlowyResult<()> {
445434
let params: MoveGroupParams = data.into_inner().try_into()?;
446435
let editor = manager.get_grid_editor(params.view_id.as_ref())?;
447-
let changeset = editor.move_group(params).await?;
448-
data_result(changeset)
436+
let _ = editor.move_group(params).await?;
437+
Ok(())
449438
}

frontend/rust-lib/flowy-grid/src/event_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn create(grid_manager: Arc<GridManager>) -> Module {
1111
.event(GridEvent::GetGrid, get_grid_handler)
1212
.event(GridEvent::GetGridBlocks, get_grid_blocks_handler)
1313
.event(GridEvent::GetGridSetting, get_grid_setting_handler)
14-
.event(GridEvent::UpdateGridSetting, update_grid_setting_handler)
14+
// .event(GridEvent::UpdateGridSetting, update_grid_setting_handler)
1515
// Field
1616
.event(GridEvent::GetFields, get_fields_handler)
1717
.event(GridEvent::UpdateField, update_field_handler)
@@ -219,6 +219,6 @@ pub enum GridEvent {
219219
#[event(input = "CreateBoardCardPayloadPB", output = "RowPB")]
220220
CreateBoardCard = 110,
221221

222-
#[event(input = "MoveGroupPayloadPB", output = "GroupsChangesetPB")]
222+
#[event(input = "MoveGroupPayloadPB")]
223223
MoveGroup = 111,
224224
}

frontend/rust-lib/flowy-grid/src/services/grid_editor.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ impl GridRevisionEditor {
343343
Ok(row_pb)
344344
}
345345

346-
pub async fn move_group(&self, _params: MoveGroupParams) -> FlowyResult<GroupsChangesetPB> {
347-
//
348-
todo!()
346+
pub async fn move_group(&self, params: MoveGroupParams) -> FlowyResult<()> {
347+
let _ = self.view_manager.move_group(params).await?;
348+
Ok(())
349349
}
350350

351351
pub async fn insert_rows(&self, row_revs: Vec<RowRevision>) -> FlowyResult<Vec<RowPB>> {
@@ -514,8 +514,13 @@ impl GridRevisionEditor {
514514
self.view_manager.get_filters().await
515515
}
516516

517-
pub async fn update_grid_setting(&self, params: GridSettingChangesetParams) -> FlowyResult<()> {
518-
let _ = self.view_manager.update_setting(params).await?;
517+
pub async fn update_filter(&self, params: CreateFilterParams) -> FlowyResult<()> {
518+
let _ = self.view_manager.update_filter(params).await?;
519+
Ok(())
520+
}
521+
522+
pub async fn delete_filter(&self, params: DeleteFilterParams) -> FlowyResult<()> {
523+
let _ = self.view_manager.delete_filter(params).await?;
519524
Ok(())
520525
}
521526

frontend/rust-lib/flowy-grid/src/services/grid_view_editor.rs

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::dart_notification::{send_dart_notification, GridNotification};
22
use crate::entities::{
3-
CreateRowParams, GridFilterConfiguration, GridLayout, GridLayoutPB, GridSettingChangesetParams, GridSettingPB,
4-
GroupPB, GroupRowsChangesetPB, InsertedRowPB, RepeatedGridConfigurationFilterPB, RepeatedGridGroupConfigurationPB,
5-
RowPB,
3+
CreateFilterParams, CreateRowParams, DeleteFilterParams, GridFilterConfiguration, GridLayout, GridLayoutPB,
4+
GridSettingChangesetParams, GridSettingPB, GroupPB, GroupRowsChangesetPB, GroupViewChangesetPB, InsertedRowPB,
5+
MoveGroupParams, RepeatedGridConfigurationFilterPB, RepeatedGridGroupConfigurationPB, RowPB,
66
};
77
use crate::services::grid_editor_task::GridServiceTaskScheduler;
88
use crate::services::grid_view_manager::{GridViewFieldDelegate, GridViewRowDelegate};
@@ -11,7 +11,8 @@ use crate::services::group::{
1111
};
1212
use flowy_error::{FlowyError, FlowyResult};
1313
use flowy_grid_data_model::revision::{
14-
FieldRevision, FieldTypeRevision, GroupConfigurationRevision, RowChangeset, RowRevision,
14+
gen_grid_filter_id, FieldRevision, FieldTypeRevision, FilterConfigurationRevision, GroupConfigurationRevision,
15+
RowChangeset, RowRevision,
1516
};
1617
use flowy_revision::{RevisionCloudService, RevisionManager, RevisionObjectBuilder};
1718
use flowy_sync::client_grid::{GridViewRevisionChangeset, GridViewRevisionPad};
@@ -99,7 +100,7 @@ impl GridViewRevisionEditor {
99100
index: None,
100101
};
101102
let changeset = GroupRowsChangesetPB::insert(group_id.clone(), vec![inserted_row]);
102-
self.notify_did_update_group(changeset).await;
103+
self.notify_did_update_group_rows(changeset).await;
103104
}
104105
}
105106
}
@@ -114,7 +115,7 @@ impl GridViewRevisionEditor {
114115
.await
115116
{
116117
for changeset in changesets {
117-
self.notify_did_update_group(changeset).await;
118+
self.notify_did_update_group_rows(changeset).await;
118119
}
119120
}
120121
}
@@ -128,7 +129,7 @@ impl GridViewRevisionEditor {
128129
.await
129130
{
130131
for changeset in changesets {
131-
self.notify_did_update_group(changeset).await;
132+
self.notify_did_update_group_rows(changeset).await;
132133
}
133134
}
134135
}
@@ -150,7 +151,7 @@ impl GridViewRevisionEditor {
150151
{
151152
for changeset in changesets {
152153
tracing::trace!("Group: {} changeset: {}", changeset.group_id, changeset);
153-
self.notify_did_update_group(changeset).await;
154+
self.notify_did_update_group_rows(changeset).await;
154155
}
155156
}
156157
}
@@ -173,22 +174,19 @@ impl GridViewRevisionEditor {
173174
} else {
174175
self.group_service.read().await.groups().await
175176
};
176-
177177
Ok(groups.into_iter().map(GroupPB::from).collect())
178178
}
179179

180+
pub(crate) async fn move_group(&self, params: MoveGroupParams) -> FlowyResult<()> {
181+
todo!()
182+
}
183+
180184
pub(crate) async fn get_setting(&self) -> GridSettingPB {
181185
let field_revs = self.field_delegate.get_field_revs().await;
182186
let grid_setting = make_grid_setting(&*self.pad.read().await, &field_revs);
183187
grid_setting
184188
}
185189

186-
pub(crate) async fn update_setting(&self, _changeset: GridSettingChangesetParams) -> FlowyResult<()> {
187-
// let _ = self.modify(|pad| Ok(pad.update_setting(changeset)?)).await;
188-
// Ok(())
189-
todo!()
190-
}
191-
192190
pub(crate) async fn get_filters(&self) -> Vec<GridFilterConfiguration> {
193191
let field_revs = self.field_delegate.get_field_revs().await;
194192
match self.pad.read().await.get_all_filters(&field_revs) {
@@ -201,12 +199,44 @@ impl GridViewRevisionEditor {
201199
}
202200
}
203201

204-
async fn notify_did_update_group(&self, changeset: GroupRowsChangesetPB) {
202+
pub(crate) async fn insert_filter(&self, insert_filter: CreateFilterParams) -> FlowyResult<()> {
203+
self.modify(|pad| {
204+
let filter_rev = FilterConfigurationRevision {
205+
id: gen_grid_filter_id(),
206+
field_id: insert_filter.field_id.clone(),
207+
condition: insert_filter.condition,
208+
content: insert_filter.content,
209+
};
210+
let changeset = pad.insert_filter(&insert_filter.field_id, &insert_filter.field_type_rev, filter_rev)?;
211+
Ok(changeset)
212+
})
213+
.await
214+
}
215+
216+
pub(crate) async fn delete_filter(&self, delete_filter: DeleteFilterParams) -> FlowyResult<()> {
217+
self.modify(|pad| {
218+
let changeset = pad.delete_filter(
219+
&delete_filter.field_id,
220+
&delete_filter.field_type_rev,
221+
&delete_filter.filter_id,
222+
)?;
223+
Ok(changeset)
224+
})
225+
.await
226+
}
227+
228+
async fn notify_did_update_group_rows(&self, changeset: GroupRowsChangesetPB) {
205229
send_dart_notification(&changeset.group_id, GridNotification::DidUpdateGroup)
206230
.payload(changeset)
207231
.send();
208232
}
209233

234+
async fn notify_did_update_view(&self, changeset: GroupViewChangesetPB) {
235+
send_dart_notification(&self.view_id, GridNotification::DidUpdateGroupView)
236+
.payload(changeset)
237+
.send();
238+
}
239+
210240
#[allow(dead_code)]
211241
async fn modify<F>(&self, f: F) -> FlowyResult<()>
212242
where

frontend/rust-lib/flowy-grid/src/services/grid_view_manager.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::entities::{
2-
CreateRowParams, GridFilterConfiguration, GridSettingChangesetParams, GridSettingPB, RepeatedGridGroupPB, RowPB,
2+
CreateFilterParams, CreateRowParams, DeleteFilterParams, GridFilterConfiguration, GridSettingChangesetParams,
3+
GridSettingPB, MoveGroupParams, RepeatedGridGroupPB, RowPB,
34
};
45
use crate::manager::GridUser;
56
use crate::services::grid_editor_task::GridServiceTaskScheduler;
@@ -98,15 +99,19 @@ impl GridViewManager {
9899
Ok(view_editor.get_setting().await)
99100
}
100101

101-
pub(crate) async fn update_setting(&self, params: GridSettingChangesetParams) -> FlowyResult<()> {
102+
pub(crate) async fn get_filters(&self) -> FlowyResult<Vec<GridFilterConfiguration>> {
102103
let view_editor = self.get_default_view_editor().await?;
103-
let _ = view_editor.update_setting(params).await?;
104-
Ok(())
104+
Ok(view_editor.get_filters().await)
105105
}
106106

107-
pub(crate) async fn get_filters(&self) -> FlowyResult<Vec<GridFilterConfiguration>> {
107+
pub(crate) async fn update_filter(&self, insert_filter: CreateFilterParams) -> FlowyResult<()> {
108108
let view_editor = self.get_default_view_editor().await?;
109-
Ok(view_editor.get_filters().await)
109+
view_editor.insert_filter(insert_filter).await
110+
}
111+
112+
pub(crate) async fn delete_filter(&self, delete_filter: DeleteFilterParams) -> FlowyResult<()> {
113+
let view_editor = self.get_default_view_editor().await?;
114+
view_editor.delete_filter(delete_filter).await
110115
}
111116

112117
pub(crate) async fn load_groups(&self) -> FlowyResult<RepeatedGridGroupPB> {
@@ -115,6 +120,12 @@ impl GridViewManager {
115120
Ok(RepeatedGridGroupPB { items: groups })
116121
}
117122

123+
pub(crate) async fn move_group(&self, params: MoveGroupParams) -> FlowyResult<()> {
124+
let view_editor = self.get_default_view_editor().await?;
125+
let _s = view_editor.move_group(params).await?;
126+
Ok(())
127+
}
128+
118129
/// It may generate a RowChangeset when the Row was moved from one group to another.
119130
/// The return value, [RowChangeset], contains the changes made by the groups.
120131
///
@@ -131,9 +142,6 @@ impl GridViewManager {
131142
}
132143
}
133144

134-
#[allow(dead_code)]
135-
pub(crate) async fn move_group(&self) {}
136-
137145
pub(crate) async fn get_view_editor(&self, view_id: &str) -> FlowyResult<Arc<GridViewRevisionEditor>> {
138146
debug_assert!(!view_id.is_empty());
139147
match self.view_editors.get(view_id) {

0 commit comments

Comments
 (0)