mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: update kanban demo (#2008)
This commit is contained in:
parent
0630dc10b7
commit
1dbfd838ef
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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) => {
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user