From 1dbfd838ef80d85b39a0246938368337401b372a Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Fri, 17 Mar 2023 11:01:14 +0800 Subject: [PATCH] feat: update kanban demo (#2008) --- .../application/database_controller.dart | 7 +++-- .../application/database_view_service.dart | 10 +++--- .../board/application/board_bloc.dart | 4 +-- .../components/tests/TestGroup.tsx | 31 +++++++++++++++++++ .../effects/database/database_bd_svc.ts | 18 ++++++++--- .../effects/database/database_controller.ts | 2 +- .../select_option_controller/util.rs | 3 +- 7 files changed, 59 insertions(+), 16 deletions(-) diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/application/database_controller.dart b/frontend/appflowy_flutter/lib/plugins/database_view/application/database_controller.dart index e075cf5b92..dac75a6e52 100644 --- a/frontend/appflowy_flutter/lib/plugins/database_view/application/database_controller.dart +++ b/frontend/appflowy_flutter/lib/plugins/database_view/application/database_controller.dart @@ -159,8 +159,11 @@ class DatabaseController { ); } - Future> moveRow(RowPB fromRow, - {RowPB? toRow, String? groupId}) { + Future> moveRow({ + required RowPB fromRow, + required String groupId, + RowPB? toRow, + }) { return _databaseViewBackendSvc.moveRow( fromRowId: fromRow.id, toGroupId: groupId, diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/application/database_view_service.dart b/frontend/appflowy_flutter/lib/plugins/database_view/application/database_view_service.dart index 842eeac90c..5ecaad6ef3 100644 --- a/frontend/appflowy_flutter/lib/plugins/database_view/application/database_view_service.dart +++ b/frontend/appflowy_flutter/lib/plugins/database_view/application/database_view_service.dart @@ -46,15 +46,13 @@ class DatabaseViewBackendService { Future> moveRow({ required String fromRowId, - required String? toGroupId, - required String? toRowId, + required String toGroupId, + String? toRowId, }) { var payload = MoveGroupRowPayloadPB.create() ..viewId = viewId - ..fromRowId = fromRowId; - if (toGroupId != null) { - payload.toGroupId = toGroupId; - } + ..fromRowId = fromRowId + ..toGroupId = toGroupId; if (toRowId != null) { payload.toRowId = toRowId; diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/board/application/board_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database_view/board/application/board_bloc.dart index 1ee14a95d0..61911b5318 100644 --- a/frontend/appflowy_flutter/lib/plugins/database_view/board/application/board_bloc.dart +++ b/frontend/appflowy_flutter/lib/plugins/database_view/board/application/board_bloc.dart @@ -54,7 +54,7 @@ class BoardBloc extends Bloc { final toRow = groupControllers[groupId]?.rowAtIndex(toIndex); if (fromRow != null) { _databaseController.moveRow( - fromRow, + fromRow: fromRow, toRow: toRow, groupId: groupId, ); @@ -70,7 +70,7 @@ class BoardBloc extends Bloc { final toRow = groupControllers[toGroupId]?.rowAtIndex(toIndex); if (fromRow != null) { _databaseController.moveRow( - fromRow, + fromRow: fromRow, toRow: toRow, groupId: toGroupId, ); diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestGroup.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestGroup.tsx index a88065f253..bbcf7a860c 100644 --- a/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestGroup.tsx +++ b/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestGroup.tsx @@ -69,6 +69,37 @@ async function moveKanbanBoardRow() { // Create row in no status group const firstGroup = databaseController.groups.getValue()[1]; const secondGroup = databaseController.groups.getValue()[2]; + // subscribe the group changes + firstGroup.subscribe({ + onRemoveRow: (groupId, deleteRowId) => { + console.log(groupId + 'did remove:' + deleteRowId); + }, + onInsertRow: (groupId, rowPB) => { + console.log(groupId + 'did insert:' + rowPB.id); + }, + onUpdateRow: (groupId, rowPB) => { + console.log(groupId + 'did update:' + rowPB.id); + }, + onCreateRow: (groupId, rowPB) => { + console.log(groupId + 'did create:' + rowPB.id); + }, + }); + + secondGroup.subscribe({ + onRemoveRow: (groupId, deleteRowId) => { + console.log(groupId + 'did remove:' + deleteRowId); + }, + onInsertRow: (groupId, rowPB) => { + console.log(groupId + 'did insert:' + rowPB.id); + }, + onUpdateRow: (groupId, rowPB) => { + console.log(groupId + 'did update:' + rowPB.id); + }, + onCreateRow: (groupId, rowPB) => { + console.log(groupId + 'did create:' + rowPB.id); + }, + }); + const row = firstGroup.rowAtIndex(0).unwrap(); await databaseController.moveRow(row.id, secondGroup.groupId); diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/database_bd_svc.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/database_bd_svc.ts index 433c6acb17..f66f78ee15 100644 --- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/database_bd_svc.ts +++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/database_bd_svc.ts @@ -56,11 +56,19 @@ export class DatabaseBackendService { return DatabaseEventCreateRow(payload); }; - moveRow = (rowId: string, groupId?: string) => { - const payload = MoveGroupRowPayloadPB.fromObject({ view_id: this.viewId, from_row_id: rowId }); - if (groupId !== undefined) { - payload.to_group_id = groupId; + /// Move the row from one group to another group + /// [groupId] can be the moving row's group id or others. + /// [toRowId] is used to locate the moving row location. + moveGroupRow = (fromRowId: string, groupId: string, toRowId?: string) => { + const payload = MoveGroupRowPayloadPB.fromObject({ + view_id: this.viewId, + from_row_id: fromRowId, + to_group_id: groupId, + }); + if (toRowId !== undefined) { + payload.to_row_id = toRowId; } + return DatabaseEventMoveGroupRow(payload); }; @@ -88,6 +96,8 @@ export class DatabaseBackendService { return DatabaseEventGetGroup(payload); }; + /// Get all groups in database + /// It should only call once after the board open loadGroups = () => { const payload = DatabaseViewIdPB.fromObject({ value: this.viewId }); return DatabaseEventGetGroups(payload); diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/database_controller.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/database_controller.ts index e47119c49a..cdd3bd76aa 100644 --- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/database_controller.ts +++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/database_controller.ts @@ -76,7 +76,7 @@ export class DatabaseController { }; moveRow = (rowId: string, groupId: string) => { - return this.backendService.moveRow(rowId, groupId); + return this.backendService.moveGroupRow(rowId, groupId); }; moveGroup = (fromGroupId: string, toGroupId: string) => { diff --git a/frontend/rust-lib/flowy-database/src/services/group/controller_impls/select_option_controller/util.rs b/frontend/rust-lib/flowy-database/src/services/group/controller_impls/select_option_controller/util.rs index d630df5d13..b800cf988f 100644 --- a/frontend/rust-lib/flowy-database/src/services/group/controller_impls/select_option_controller/util.rs +++ b/frontend/rust-lib/flowy-database/src/services/group/controller_impls/select_option_controller/util.rs @@ -115,6 +115,8 @@ pub fn move_group_row( } // Update the corresponding row's cell content. + // If the from_index is none which means the row is not belong to this group before and + // it is moved from other groups. if from_index.is_none() { let cell_rev = make_inserted_cell_rev(&group.id, field_rev); if let Some(cell_rev) = cell_rev { @@ -126,7 +128,6 @@ pub fn move_group_row( row_changeset .cell_by_field_id .insert(field_rev.id.clone(), cell_rev); - changeset.updated_rows.push(RowPB::from(*row_rev)); } } }