浏览代码

feat: update kanban demo (#2008)

Nathan.fooo 2 年之前
父节点
当前提交
1dbfd838ef

+ 5 - 2
frontend/appflowy_flutter/lib/plugins/database_view/application/database_controller.dart

@@ -159,8 +159,11 @@ class DatabaseController {
     );
   }
 
-  Future<Either<Unit, FlowyError>> moveRow(RowPB fromRow,
-      {RowPB? toRow, String? groupId}) {
+  Future<Either<Unit, FlowyError>> moveRow({
+    required RowPB fromRow,
+    required String groupId,
+    RowPB? toRow,
+  }) {
     return _databaseViewBackendSvc.moveRow(
       fromRowId: fromRow.id,
       toGroupId: groupId,

+ 4 - 6
frontend/appflowy_flutter/lib/plugins/database_view/application/database_view_service.dart

@@ -46,15 +46,13 @@ class DatabaseViewBackendService {
 
   Future<Either<Unit, FlowyError>> 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;

+ 2 - 2
frontend/appflowy_flutter/lib/plugins/database_view/board/application/board_bloc.dart

@@ -54,7 +54,7 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
         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<BoardEvent, BoardState> {
         final toRow = groupControllers[toGroupId]?.rowAtIndex(toIndex);
         if (fromRow != null) {
           _databaseController.moveRow(
-            fromRow,
+            fromRow: fromRow,
             toRow: toRow,
             groupId: toGroupId,
           );

+ 31 - 0
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);
 

+ 14 - 4
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);

+ 1 - 1
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) => {

+ 2 - 1
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));
       }
     }
   }