@dxos/plugin-kanban 0.8.4-main.bc674ce → 0.8.4-main.bcb3aa67d6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/blueprints/index.mjs +23 -4
- package/dist/lib/browser/blueprints/index.mjs.map +4 -4
- package/dist/lib/browser/chunk-A3PBV3S5.mjs +105 -0
- package/dist/lib/browser/chunk-A3PBV3S5.mjs.map +7 -0
- package/dist/lib/browser/delete-card-VPNVIWOA.mjs +32 -0
- package/dist/lib/browser/delete-card-VPNVIWOA.mjs.map +7 -0
- package/dist/lib/browser/delete-card-field-4HHF2GYX.mjs +50 -0
- package/dist/lib/browser/delete-card-field-4HHF2GYX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +84 -61
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/operations/index.mjs +13 -0
- package/dist/lib/browser/operations/index.mjs.map +7 -0
- package/dist/lib/browser/restore-card-4GG2RYKR.mjs +29 -0
- package/dist/lib/browser/restore-card-4GG2RYKR.mjs.map +7 -0
- package/dist/lib/browser/restore-card-field-3T26ACYX.mjs +48 -0
- package/dist/lib/browser/restore-card-field-3T26ACYX.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +94 -8
- package/dist/lib/browser/types/index.mjs.map +4 -4
- package/dist/lib/node-esm/blueprints/index.mjs +23 -4
- package/dist/lib/node-esm/blueprints/index.mjs.map +4 -4
- package/dist/lib/node-esm/chunk-6LELYA2G.mjs +106 -0
- package/dist/lib/node-esm/chunk-6LELYA2G.mjs.map +7 -0
- package/dist/lib/node-esm/delete-card-5PW5OMFN.mjs +33 -0
- package/dist/lib/node-esm/delete-card-5PW5OMFN.mjs.map +7 -0
- package/dist/lib/node-esm/delete-card-field-KPJU2AQ3.mjs +51 -0
- package/dist/lib/node-esm/delete-card-field-KPJU2AQ3.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +84 -61
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/operations/index.mjs +14 -0
- package/dist/lib/node-esm/operations/index.mjs.map +7 -0
- package/dist/lib/node-esm/restore-card-X2TKMU5A.mjs +30 -0
- package/dist/lib/node-esm/restore-card-X2TKMU5A.mjs.map +7 -0
- package/dist/lib/node-esm/restore-card-field-IUTL4RTR.mjs +49 -0
- package/dist/lib/node-esm/restore-card-field-IUTL4RTR.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +94 -8
- package/dist/lib/node-esm/types/index.mjs.map +4 -4
- package/dist/types/src/KanbanPlugin.d.ts.map +1 -1
- package/dist/types/src/blueprints/index.d.ts +1 -1
- package/dist/types/src/blueprints/index.d.ts.map +1 -1
- package/dist/types/src/blueprints/kanban-blueprint.d.ts +3 -21
- package/dist/types/src/blueprints/kanban-blueprint.d.ts.map +1 -1
- package/dist/types/src/capabilities/{artifact-definition/artifact-definition.d.ts → artifact-definition.d.ts} +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/blueprint-definition.d.ts +6 -0
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +6 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
- package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +5 -0
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
- package/dist/types/src/capabilities/undo-mappings.d.ts +5 -0
- package/dist/types/src/capabilities/undo-mappings.d.ts.map +1 -0
- package/dist/types/src/components/KanbanBoard/KanbanBoard.d.ts +65 -0
- package/dist/types/src/components/KanbanBoard/KanbanBoard.d.ts.map +1 -0
- package/dist/types/src/components/KanbanBoard/KanbanBoard.stories.d.ts +72 -0
- package/dist/types/src/components/KanbanBoard/KanbanBoard.stories.d.ts.map +1 -0
- package/dist/types/src/components/KanbanBoard/KanbanCard.d.ts +10 -0
- package/dist/types/src/components/KanbanBoard/KanbanCard.d.ts.map +1 -0
- package/dist/types/src/components/KanbanBoard/KanbanColumn.d.ts +9 -0
- package/dist/types/src/components/KanbanBoard/KanbanColumn.d.ts.map +1 -0
- package/dist/types/src/components/KanbanBoard/index.d.ts +2 -0
- package/dist/types/src/components/KanbanBoard/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/containers/KanbanContainer/KanbanContainer.d.ts +6 -0
- package/dist/types/src/containers/KanbanContainer/KanbanContainer.d.ts.map +1 -0
- package/dist/types/src/containers/KanbanContainer/KanbanContainer.stories.d.ts +79 -0
- package/dist/types/src/containers/KanbanContainer/KanbanContainer.stories.d.ts.map +1 -0
- package/dist/types/src/containers/KanbanContainer/index.d.ts +3 -0
- package/dist/types/src/containers/KanbanContainer/index.d.ts.map +1 -0
- package/dist/types/src/containers/KanbanViewEditor/KanbanViewEditor.d.ts +6 -0
- package/dist/types/src/containers/KanbanViewEditor/KanbanViewEditor.d.ts.map +1 -0
- package/dist/types/src/containers/KanbanViewEditor/index.d.ts +3 -0
- package/dist/types/src/containers/KanbanViewEditor/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +4 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +6 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/useEchoChangeCallback.d.ts +13 -0
- package/dist/types/src/hooks/useEchoChangeCallback.d.ts.map +1 -0
- package/dist/types/src/hooks/useKanbanBoardModel.d.ts +16 -0
- package/dist/types/src/hooks/useKanbanBoardModel.d.ts.map +1 -0
- package/dist/types/src/hooks/useKanbanBoardModel.test.d.ts +2 -0
- package/dist/types/src/hooks/useKanbanBoardModel.test.d.ts.map +1 -0
- package/dist/types/src/hooks/useKanbanColumnEventHandler.d.ts +22 -0
- package/dist/types/src/hooks/useKanbanColumnEventHandler.d.ts.map +1 -0
- package/dist/types/src/hooks/useKanbanItemEventHandler.d.ts +19 -0
- package/dist/types/src/hooks/useKanbanItemEventHandler.d.ts.map +1 -0
- package/dist/types/src/hooks/useProjectionModel.d.ts +15 -0
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
- package/dist/types/src/operations/definitions.d.ts +52 -0
- package/dist/types/src/operations/definitions.d.ts.map +1 -0
- package/dist/types/src/operations/delete-card-field.d.ts +5 -0
- package/dist/types/src/operations/delete-card-field.d.ts.map +1 -0
- package/dist/types/src/operations/delete-card.d.ts +5 -0
- package/dist/types/src/operations/delete-card.d.ts.map +1 -0
- package/dist/types/src/operations/index.d.ts +4 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/src/operations/restore-card-field.d.ts +5 -0
- package/dist/types/src/operations/restore-card-field.d.ts.map +1 -0
- package/dist/types/src/operations/restore-card.d.ts +5 -0
- package/dist/types/src/operations/restore-card.d.ts.map +1 -0
- package/dist/types/src/playwright/board-manager.d.ts +5 -0
- package/dist/types/src/playwright/board-manager.d.ts.map +1 -0
- package/dist/types/src/playwright/playwright.config.d.ts +3 -0
- package/dist/types/src/playwright/playwright.config.d.ts.map +1 -0
- package/dist/types/src/playwright/smoke.spec.d.ts +2 -0
- package/dist/types/src/playwright/smoke.spec.d.ts.map +1 -0
- package/dist/types/src/testing/KanbanCardTileSimple.d.ts +7 -0
- package/dist/types/src/testing/KanbanCardTileSimple.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +48 -32
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Kanban.d.ts +37 -0
- package/dist/types/src/types/Kanban.d.ts.map +1 -0
- package/dist/types/src/types/constants.d.ts +6 -0
- package/dist/types/src/types/constants.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +2 -0
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +0 -103
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +28 -0
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/src/util/arrangement.d.ts +68 -0
- package/dist/types/src/util/arrangement.d.ts.map +1 -0
- package/dist/types/src/util/arrangement.test.d.ts +2 -0
- package/dist/types/src/util/arrangement.test.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +2 -0
- package/dist/types/src/util/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +64 -42
- package/src/KanbanPlugin.tsx +35 -23
- package/src/blueprints/index.ts +1 -1
- package/src/blueprints/kanban-blueprint.ts +12 -8
- package/src/capabilities/{artifact-definition/artifact-definition.ts → artifact-definition.ts} +10 -9
- package/src/capabilities/blueprint-definition.ts +17 -0
- package/src/capabilities/index.ts +10 -3
- package/src/capabilities/operation-handler.ts +14 -0
- package/src/capabilities/{react-surface/react-surface.tsx → react-surface.tsx} +15 -15
- package/src/capabilities/undo-mappings.ts +34 -0
- package/src/components/KanbanBoard/KanbanBoard.stories.tsx +142 -0
- package/src/components/KanbanBoard/KanbanBoard.tsx +193 -0
- package/src/components/KanbanBoard/KanbanCard.tsx +86 -0
- package/src/components/KanbanBoard/KanbanColumn.tsx +69 -0
- package/src/components/KanbanBoard/index.ts +5 -0
- package/src/components/index.ts +1 -2
- package/src/{components → containers/KanbanContainer}/KanbanContainer.stories.tsx +70 -87
- package/src/containers/KanbanContainer/KanbanContainer.tsx +96 -0
- package/src/containers/KanbanContainer/index.ts +7 -0
- package/src/{components → containers/KanbanViewEditor}/KanbanViewEditor.tsx +23 -19
- package/src/containers/KanbanViewEditor/index.ts +7 -0
- package/src/containers/index.ts +8 -0
- package/src/hooks/index.ts +9 -0
- package/src/hooks/useEchoChangeCallback.ts +30 -0
- package/src/hooks/useKanbanBoardModel.test.ts +235 -0
- package/src/hooks/useKanbanBoardModel.ts +143 -0
- package/src/hooks/useKanbanColumnEventHandler.ts +106 -0
- package/src/hooks/useKanbanItemEventHandler.ts +133 -0
- package/src/hooks/useProjectionModel.ts +58 -0
- package/src/meta.ts +1 -1
- package/src/operations/definitions.ts +63 -0
- package/src/operations/delete-card-field.ts +47 -0
- package/src/operations/delete-card.ts +23 -0
- package/src/operations/index.ts +12 -0
- package/src/operations/restore-card-field.ts +41 -0
- package/src/operations/restore-card.ts +21 -0
- package/src/playwright/board-manager.ts +13 -0
- package/src/playwright/playwright.config.ts +19 -0
- package/src/playwright/smoke.spec.ts +107 -0
- package/src/testing/KanbanCardTileSimple.tsx +82 -0
- package/src/testing/index.ts +5 -0
- package/src/translations.ts +26 -18
- package/src/types/Kanban.ts +71 -0
- package/src/types/constants.ts +9 -0
- package/src/types/index.ts +2 -0
- package/src/types/schema.ts +0 -76
- package/src/types/types.ts +35 -0
- package/src/util/arrangement.test.ts +208 -0
- package/src/util/arrangement.ts +167 -0
- package/src/util/index.ts +5 -0
- package/dist/lib/browser/blueprint-definition-T2544VMJ.mjs +0 -17
- package/dist/lib/browser/blueprint-definition-T2544VMJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-L6N4ZDZ7.mjs +0 -35
- package/dist/lib/browser/chunk-L6N4ZDZ7.mjs.map +0 -7
- package/dist/lib/browser/chunk-XYQO4VL7.mjs +0 -150
- package/dist/lib/browser/chunk-XYQO4VL7.mjs.map +0 -7
- package/dist/lib/browser/operation-resolver-UEJHX42A.mjs +0 -162
- package/dist/lib/browser/operation-resolver-UEJHX42A.mjs.map +0 -7
- package/dist/lib/browser/react-surface-LFUJAPRL.mjs +0 -236
- package/dist/lib/browser/react-surface-LFUJAPRL.mjs.map +0 -7
- package/dist/lib/node-esm/blueprint-definition-APJQFSHJ.mjs +0 -18
- package/dist/lib/node-esm/blueprint-definition-APJQFSHJ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NN6JMKIT.mjs +0 -152
- package/dist/lib/node-esm/chunk-NN6JMKIT.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZHRMUKTF.mjs +0 -36
- package/dist/lib/node-esm/chunk-ZHRMUKTF.mjs.map +0 -7
- package/dist/lib/node-esm/operation-resolver-5RPWHZCF.mjs +0 -163
- package/dist/lib/node-esm/operation-resolver-5RPWHZCF.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-7TSGBRJL.mjs +0 -237
- package/dist/lib/node-esm/react-surface-7TSGBRJL.mjs.map +0 -7
- package/dist/types/src/capabilities/artifact-definition/artifact-definition.d.ts.map +0 -1
- package/dist/types/src/capabilities/artifact-definition/index.d.ts +0 -3
- package/dist/types/src/capabilities/artifact-definition/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts +0 -9
- package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts.map +0 -1
- package/dist/types/src/capabilities/blueprint-definition/index.d.ts +0 -3
- package/dist/types/src/capabilities/blueprint-definition/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/operation-resolver/index.d.ts +0 -3
- package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +0 -5
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface/index.d.ts +0 -3
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +0 -5
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +0 -1
- package/dist/types/src/components/KanbanContainer.d.ts +0 -6
- package/dist/types/src/components/KanbanContainer.d.ts.map +0 -1
- package/dist/types/src/components/KanbanContainer.stories.d.ts +0 -75
- package/dist/types/src/components/KanbanContainer.stories.d.ts.map +0 -1
- package/dist/types/src/components/KanbanViewEditor.d.ts +0 -8
- package/dist/types/src/components/KanbanViewEditor.d.ts.map +0 -1
- package/src/capabilities/artifact-definition/index.ts +0 -7
- package/src/capabilities/blueprint-definition/blueprint-definition.ts +0 -23
- package/src/capabilities/blueprint-definition/index.ts +0 -7
- package/src/capabilities/operation-resolver/index.ts +0 -7
- package/src/capabilities/operation-resolver/operation-resolver.ts +0 -133
- package/src/capabilities/react-surface/index.ts +0 -7
- package/src/components/KanbanContainer.tsx +0 -86
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import type { BoardModel, MosaicEventHandler, MosaicTileData } from '@dxos/react-ui-mosaic';
|
|
8
|
+
import type { ProjectionModel } from '@dxos/schema';
|
|
9
|
+
import { arrayMove } from '@dxos/util';
|
|
10
|
+
|
|
11
|
+
import { type BaseKanbanItem, type ColumnStructure, type KanbanChangeCallback, UNCATEGORIZED_VALUE } from '#types';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Builds the column drag-and-drop handler for the kanban board (reorder columns).
|
|
15
|
+
*
|
|
16
|
+
* @template T - Item type (extends BaseKanbanItem).
|
|
17
|
+
* @param id - Handler id.
|
|
18
|
+
* @param model - Board model for getColumns / getColumnId.
|
|
19
|
+
* @param projection - ProjectionModel for pivot field options (column order).
|
|
20
|
+
* @param pivotFieldId - Pivot field id; undefined disables drop.
|
|
21
|
+
* @param change - Callback to persist kanban.arrangement.order.
|
|
22
|
+
* @returns MosaicEventHandler for column tiles.
|
|
23
|
+
*/
|
|
24
|
+
export function useKanbanColumnEventHandler<T extends BaseKanbanItem>({
|
|
25
|
+
id,
|
|
26
|
+
model,
|
|
27
|
+
projection,
|
|
28
|
+
pivotFieldId,
|
|
29
|
+
change,
|
|
30
|
+
}: {
|
|
31
|
+
id: string;
|
|
32
|
+
model: BoardModel<ColumnStructure, T>;
|
|
33
|
+
projection: ProjectionModel | undefined;
|
|
34
|
+
pivotFieldId: string | undefined;
|
|
35
|
+
change: KanbanChangeCallback<T>;
|
|
36
|
+
}): MosaicEventHandler<ColumnStructure> {
|
|
37
|
+
return useMemo<MosaicEventHandler<ColumnStructure>>(
|
|
38
|
+
() => ({
|
|
39
|
+
id,
|
|
40
|
+
canDrop: ({ source }) => {
|
|
41
|
+
if (!projection) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const data = source.data as ColumnStructure;
|
|
45
|
+
const columnValue = model.getColumnId(data);
|
|
46
|
+
return (
|
|
47
|
+
model.isColumn(source.data) &&
|
|
48
|
+
columnValue !== UNCATEGORIZED_VALUE &&
|
|
49
|
+
(source as MosaicTileData<ColumnStructure>).id !== UNCATEGORIZED_VALUE
|
|
50
|
+
);
|
|
51
|
+
},
|
|
52
|
+
onDrop: ({ source, target }) => {
|
|
53
|
+
if (!projection || pivotFieldId === undefined) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const sourceColumnData = source.data as ColumnStructure;
|
|
57
|
+
const sourceColumnId = model.getColumnId(sourceColumnData);
|
|
58
|
+
if (sourceColumnId === UNCATEGORIZED_VALUE) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 1. Current column order from model; find source index.
|
|
63
|
+
const currentColumns = model.getColumns();
|
|
64
|
+
const sourceIndex = currentColumns.findIndex((c) => model.getColumnId(c) === sourceColumnId);
|
|
65
|
+
if (sourceIndex === -1) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 2. Resolve drop target to an index in the column list.
|
|
70
|
+
let targetIndex: number;
|
|
71
|
+
if (target?.type === 'tile' || target?.type === 'placeholder') {
|
|
72
|
+
targetIndex = typeof target.location === 'number' ? Math.floor(target.location) : -1;
|
|
73
|
+
} else if (target?.type === 'container') {
|
|
74
|
+
targetIndex = currentColumns.length;
|
|
75
|
+
} else {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (targetIndex < 0) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 3. New column order after move.
|
|
83
|
+
const currentColumnIds = currentColumns.map((c) => model.getColumnId(c));
|
|
84
|
+
const reorderedColumnIds = arrayMove([...currentColumnIds], sourceIndex, targetIndex);
|
|
85
|
+
|
|
86
|
+
// 4. Persist reordered options to projection (pivot field options = column order).
|
|
87
|
+
const fieldProjection = projection.getFieldProjection(pivotFieldId);
|
|
88
|
+
const currentOptions = [...(fieldProjection.props.options ?? [])];
|
|
89
|
+
const optionsInNewOrder = reorderedColumnIds
|
|
90
|
+
.map((columnId) => currentOptions.find((o) => o.id === columnId))
|
|
91
|
+
.filter((o): o is NonNullable<typeof o> => o != null);
|
|
92
|
+
|
|
93
|
+
projection.setFieldProjection({
|
|
94
|
+
...fieldProjection,
|
|
95
|
+
props: { ...fieldProjection.props, options: optionsInNewOrder },
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Persist column order to kanban.arrangement so the board UI reflects the new order.
|
|
99
|
+
change.kanban((kanban) => {
|
|
100
|
+
kanban.arrangement.order = reorderedColumnIds.filter((columnId) => columnId !== UNCATEGORIZED_VALUE);
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
}),
|
|
104
|
+
[id, model, projection, pivotFieldId, change],
|
|
105
|
+
);
|
|
106
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import type { BoardModel, MosaicEventHandler, MosaicTileData } from '@dxos/react-ui-mosaic';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
type ArrangedCards,
|
|
11
|
+
type BaseKanbanItem,
|
|
12
|
+
type ColumnStructure,
|
|
13
|
+
type KanbanChangeCallback,
|
|
14
|
+
UNCATEGORIZED_VALUE,
|
|
15
|
+
} from '#types';
|
|
16
|
+
|
|
17
|
+
function findColumn<T extends BaseKanbanItem>(
|
|
18
|
+
id: string,
|
|
19
|
+
arrangement: ArrangedCards<T>,
|
|
20
|
+
): { columnValue: string; cards: T[] } | undefined {
|
|
21
|
+
return arrangement.find(({ columnValue, cards }) => columnValue === id || cards.some((card) => card.id === id));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Builds the item drag-and-drop handler for a single column (reorder and move between columns).
|
|
26
|
+
*
|
|
27
|
+
* @template T - Item type (extends BaseKanbanItem).
|
|
28
|
+
* @param column - Column structure for this tile.
|
|
29
|
+
* @param columnFieldPath - Item property path for the pivot field (used when moving to another column).
|
|
30
|
+
* @param model - Board model for getColumns / getItems.
|
|
31
|
+
* @param change - Callback to persist arrangement and item field updates.
|
|
32
|
+
* @returns MosaicEventHandler for item tiles in this column.
|
|
33
|
+
*/
|
|
34
|
+
export function useKanbanItemEventHandler<T extends BaseKanbanItem>({
|
|
35
|
+
column,
|
|
36
|
+
columnFieldPath,
|
|
37
|
+
model,
|
|
38
|
+
change,
|
|
39
|
+
}: {
|
|
40
|
+
column: ColumnStructure;
|
|
41
|
+
columnFieldPath: string | undefined;
|
|
42
|
+
model: BoardModel<ColumnStructure, T>;
|
|
43
|
+
change: KanbanChangeCallback<T>;
|
|
44
|
+
}): MosaicEventHandler<T> {
|
|
45
|
+
return useMemo<MosaicEventHandler<T>>(
|
|
46
|
+
() => ({
|
|
47
|
+
id: column.columnValue,
|
|
48
|
+
canDrop: ({ source }) => model.isItem(source.data),
|
|
49
|
+
onTake: ({ source }, cb) => {
|
|
50
|
+
void cb(source.data as T);
|
|
51
|
+
},
|
|
52
|
+
onDrop: ({ source, target }) => {
|
|
53
|
+
// 1. Snapshot current arrangement from model (read-only).
|
|
54
|
+
const columns = model.getColumns();
|
|
55
|
+
const currentArrangement: ArrangedCards<T> = columns.map((col) => ({
|
|
56
|
+
columnValue: col.columnValue,
|
|
57
|
+
cards: model.getItems(col) ?? [],
|
|
58
|
+
}));
|
|
59
|
+
const sourceColumnInSnapshot = findColumn(source.id, currentArrangement);
|
|
60
|
+
if (!sourceColumnInSnapshot) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 2. Working copy to mutate, then persist.
|
|
65
|
+
const workingArrangement = currentArrangement.map((col) => ({
|
|
66
|
+
columnValue: col.columnValue,
|
|
67
|
+
cards: [...col.cards],
|
|
68
|
+
}));
|
|
69
|
+
const sourceColumnInWorking = workingArrangement.find(
|
|
70
|
+
(c) => c.columnValue === sourceColumnInSnapshot.columnValue || c.cards.some((card) => card.id === source.id),
|
|
71
|
+
);
|
|
72
|
+
const targetColumnInWorking = workingArrangement.find((c) => c.columnValue === column.columnValue);
|
|
73
|
+
if (!sourceColumnInWorking || !targetColumnInWorking) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 3. Remove card from source column in working copy.
|
|
78
|
+
const sourceIndex = sourceColumnInWorking.cards.findIndex((card) => card.id === source.id);
|
|
79
|
+
if (sourceIndex === -1) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const [movedCard] = sourceColumnInWorking.cards.splice(sourceIndex, 1);
|
|
83
|
+
|
|
84
|
+
// 4. Update card's pivot field to target column value.
|
|
85
|
+
if (columnFieldPath !== undefined) {
|
|
86
|
+
const newValue =
|
|
87
|
+
targetColumnInWorking.columnValue === UNCATEGORIZED_VALUE ? undefined : targetColumnInWorking.columnValue;
|
|
88
|
+
change.setItemField(movedCard, columnFieldPath, newValue);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 5. Compute insert index in target column, then insert.
|
|
92
|
+
const existingTargetIndex =
|
|
93
|
+
target?.type === 'tile'
|
|
94
|
+
? targetColumnInWorking.cards.findIndex(
|
|
95
|
+
(card) => model.getItemId(card) === (target as MosaicTileData<T>).id,
|
|
96
|
+
)
|
|
97
|
+
: -1;
|
|
98
|
+
const closestEdge: 'top' | 'bottom' =
|
|
99
|
+
target?.type === 'placeholder' && typeof target.location === 'number'
|
|
100
|
+
? target.location <= targetColumnInWorking.cards.length / 2
|
|
101
|
+
? 'top'
|
|
102
|
+
: 'bottom'
|
|
103
|
+
: 'bottom';
|
|
104
|
+
|
|
105
|
+
let insertIndex: number;
|
|
106
|
+
if (target?.type === 'placeholder' && typeof target.location === 'number') {
|
|
107
|
+
insertIndex = Math.max(0, Math.min(targetColumnInWorking.cards.length, Math.floor(target.location)));
|
|
108
|
+
} else if (target?.type === 'container' || existingTargetIndex === -1) {
|
|
109
|
+
insertIndex = targetColumnInWorking.cards.length;
|
|
110
|
+
} else if (sourceColumnInWorking.columnValue === targetColumnInWorking.columnValue) {
|
|
111
|
+
insertIndex = closestEdge === 'bottom' ? existingTargetIndex + 1 : existingTargetIndex;
|
|
112
|
+
if (sourceIndex < existingTargetIndex) {
|
|
113
|
+
insertIndex -= 1;
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
insertIndex = closestEdge === 'bottom' ? existingTargetIndex + 1 : existingTargetIndex;
|
|
117
|
+
}
|
|
118
|
+
targetColumnInWorking.cards.splice(insertIndex, 0, movedCard);
|
|
119
|
+
|
|
120
|
+
// 6. Persist arrangement to kanban.
|
|
121
|
+
change.kanban((kanban) => {
|
|
122
|
+
kanban.arrangement = {
|
|
123
|
+
order: workingArrangement.map(({ columnValue }) => columnValue),
|
|
124
|
+
columns: Object.fromEntries(
|
|
125
|
+
workingArrangement.map(({ columnValue, cards }) => [columnValue, { ids: cards.map((c) => c.id) }]),
|
|
126
|
+
),
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
}),
|
|
131
|
+
[column, columnFieldPath, model, change],
|
|
132
|
+
);
|
|
133
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Registry } from '@effect-atom/atom-react';
|
|
6
|
+
import { useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import { JsonSchema, Type } from '@dxos/echo';
|
|
9
|
+
import { log } from '@dxos/log';
|
|
10
|
+
import { useAsyncEffect } from '@dxos/react-ui';
|
|
11
|
+
import { ProjectionModel, createEchoChangeCallback } from '@dxos/schema';
|
|
12
|
+
|
|
13
|
+
import { type Kanban } from '#types';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Loads the kanban view and builds a ProjectionModel for field projections and pivot.
|
|
17
|
+
*
|
|
18
|
+
* @template S - Entity schema type.
|
|
19
|
+
* @param schema - Echo schema for the viewed type (or undefined).
|
|
20
|
+
* @param kanban - Kanban object whose view to load (or undefined).
|
|
21
|
+
* @param registry - Atom registry for reactive state.
|
|
22
|
+
* @returns ProjectionModel when loaded, or undefined while loading or when schema/kanban are missing.
|
|
23
|
+
*/
|
|
24
|
+
export const useProjectionModel = <S extends Type.AnyEntity>(
|
|
25
|
+
schema: S | undefined,
|
|
26
|
+
kanban: Kanban.Kanban | undefined,
|
|
27
|
+
registry: Registry.Registry,
|
|
28
|
+
) => {
|
|
29
|
+
const [projection, setProjection] = useState<ProjectionModel | undefined>();
|
|
30
|
+
|
|
31
|
+
useAsyncEffect(
|
|
32
|
+
async (controller) => {
|
|
33
|
+
if (!schema || !kanban) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const view = await kanban.view.load();
|
|
38
|
+
if (controller.signal.aborted) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const jsonSchema = Type.isMutable(schema) ? schema.jsonSchema : JsonSchema.toJsonSchema(schema);
|
|
43
|
+
const change = createEchoChangeCallback(view, Type.isMutable(schema) ? schema : undefined);
|
|
44
|
+
|
|
45
|
+
const projection = new ProjectionModel({ registry, view, baseSchema: jsonSchema, change });
|
|
46
|
+
projection.normalizeView();
|
|
47
|
+
if (!controller.signal.aborted) {
|
|
48
|
+
setProjection(projection);
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
51
|
+
log.catch(err, { schema, kanban });
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
[schema, kanban, registry],
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
return projection;
|
|
58
|
+
};
|
package/src/meta.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { type Plugin } from '@dxos/app-framework';
|
|
|
6
6
|
import { trim } from '@dxos/util';
|
|
7
7
|
|
|
8
8
|
export const meta: Plugin.Meta = {
|
|
9
|
-
id: 'dxos.
|
|
9
|
+
id: 'org.dxos.plugin.kanban',
|
|
10
10
|
name: 'Kanban',
|
|
11
11
|
description: trim`
|
|
12
12
|
Visual project management using customizable kanban boards to track workflow progress.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Copyright 2025 DXOS.org
|
|
2
|
+
|
|
3
|
+
import * as Schema from 'effect/Schema';
|
|
4
|
+
|
|
5
|
+
import { Capability } from '@dxos/app-framework';
|
|
6
|
+
import { View } from '@dxos/echo';
|
|
7
|
+
import { Operation } from '@dxos/operation';
|
|
8
|
+
|
|
9
|
+
import { meta } from '#meta';
|
|
10
|
+
|
|
11
|
+
const KANBAN_OPERATION = `${meta.id}.operation`;
|
|
12
|
+
|
|
13
|
+
export const DeleteCardFieldOutput = Schema.Struct({
|
|
14
|
+
field: View.FieldSchema.annotations({ description: 'The deleted field schema.' }),
|
|
15
|
+
props: Schema.Any.annotations({ description: 'The deleted field properties.' }),
|
|
16
|
+
index: Schema.Number.annotations({ description: 'The index the field was at.' }),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export type DeleteCardFieldOutput = Schema.Schema.Type<typeof DeleteCardFieldOutput>;
|
|
20
|
+
|
|
21
|
+
export const DeleteCardField = Operation.make({
|
|
22
|
+
meta: { key: `${KANBAN_OPERATION}.delete-card-field`, name: 'Delete Card Field' },
|
|
23
|
+
services: [Capability.Service],
|
|
24
|
+
input: Schema.Struct({
|
|
25
|
+
view: View.View,
|
|
26
|
+
fieldId: Schema.String,
|
|
27
|
+
}),
|
|
28
|
+
output: DeleteCardFieldOutput,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const DeleteCardOutput = Schema.Struct({
|
|
32
|
+
card: Schema.Any.annotations({ description: 'The deleted card.' }),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export type DeleteCardOutput = Schema.Schema.Type<typeof DeleteCardOutput>;
|
|
36
|
+
|
|
37
|
+
export const DeleteCard = Operation.make({
|
|
38
|
+
meta: { key: `${KANBAN_OPERATION}.delete-card`, name: 'Delete Card' },
|
|
39
|
+
input: Schema.Struct({
|
|
40
|
+
card: Schema.Any,
|
|
41
|
+
}),
|
|
42
|
+
output: DeleteCardOutput,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export const RestoreCardField = Operation.make({
|
|
46
|
+
meta: { key: `${KANBAN_OPERATION}.restore-card-field`, name: 'Restore Card Field' },
|
|
47
|
+
services: [Capability.Service],
|
|
48
|
+
input: Schema.Struct({
|
|
49
|
+
view: View.View.annotations({ description: 'The view to restore the field to.' }),
|
|
50
|
+
field: View.FieldSchema.annotations({ description: 'The field schema to restore.' }),
|
|
51
|
+
props: Schema.Any.annotations({ description: 'The field properties to restore.' }),
|
|
52
|
+
index: Schema.Number.annotations({ description: 'The index to restore the field at.' }),
|
|
53
|
+
}),
|
|
54
|
+
output: Schema.Void,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export const RestoreCard = Operation.make({
|
|
58
|
+
meta: { key: `${KANBAN_OPERATION}.restore-card`, name: 'Restore Card' },
|
|
59
|
+
input: Schema.Struct({
|
|
60
|
+
card: Schema.Any.annotations({ description: 'The card to restore.' }),
|
|
61
|
+
}),
|
|
62
|
+
output: Schema.Void,
|
|
63
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Copyright 2025 DXOS.org
|
|
2
|
+
|
|
3
|
+
import * as Effect from 'effect/Effect';
|
|
4
|
+
|
|
5
|
+
import { Capabilities, Capability } from '@dxos/app-framework';
|
|
6
|
+
import { JsonSchema, Obj } from '@dxos/echo';
|
|
7
|
+
import { type EchoSchema } from '@dxos/echo/internal';
|
|
8
|
+
import { invariant } from '@dxos/invariant';
|
|
9
|
+
import { Operation } from '@dxos/operation';
|
|
10
|
+
import { ProjectionModel, createEchoChangeCallback, getTypenameFromQuery } from '@dxos/schema';
|
|
11
|
+
|
|
12
|
+
import { DeleteCardField } from './definitions';
|
|
13
|
+
|
|
14
|
+
const handler: Operation.WithHandler<typeof DeleteCardField> = DeleteCardField.pipe(
|
|
15
|
+
Operation.withHandler(
|
|
16
|
+
Effect.fnUntraced(function* ({ view, fieldId }) {
|
|
17
|
+
const registry = yield* Capability.get(Capabilities.AtomRegistry);
|
|
18
|
+
const db = Obj.getDatabase(view);
|
|
19
|
+
invariant(db, 'Database not found');
|
|
20
|
+
const schema = yield* Effect.promise(() =>
|
|
21
|
+
db.schemaRegistry
|
|
22
|
+
.query({
|
|
23
|
+
typename: getTypenameFromQuery(view.query.ast)!,
|
|
24
|
+
location: ['database', 'runtime'],
|
|
25
|
+
})
|
|
26
|
+
.first(),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const projection = new ProjectionModel({
|
|
30
|
+
registry,
|
|
31
|
+
view,
|
|
32
|
+
baseSchema: JsonSchema.toJsonSchema(schema),
|
|
33
|
+
change: createEchoChangeCallback(view, schema as EchoSchema),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const result = projection.deleteFieldProjection(fieldId);
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
field: result.deleted.field,
|
|
40
|
+
props: result.deleted.props,
|
|
41
|
+
index: result.index,
|
|
42
|
+
};
|
|
43
|
+
}),
|
|
44
|
+
),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
export default handler;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2025 DXOS.org
|
|
2
|
+
|
|
3
|
+
import * as Effect from 'effect/Effect';
|
|
4
|
+
|
|
5
|
+
import { Obj } from '@dxos/echo';
|
|
6
|
+
import { invariant } from '@dxos/invariant';
|
|
7
|
+
import { Operation } from '@dxos/operation';
|
|
8
|
+
|
|
9
|
+
import { DeleteCard } from './definitions';
|
|
10
|
+
|
|
11
|
+
const handler: Operation.WithHandler<typeof DeleteCard> = DeleteCard.pipe(
|
|
12
|
+
Operation.withHandler(({ card }) =>
|
|
13
|
+
Effect.sync(() => {
|
|
14
|
+
const db = Obj.getDatabase(card);
|
|
15
|
+
invariant(db);
|
|
16
|
+
db.remove(card);
|
|
17
|
+
|
|
18
|
+
return { card };
|
|
19
|
+
}),
|
|
20
|
+
),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export default handler;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright 2025 DXOS.org
|
|
2
|
+
|
|
3
|
+
import { OperationHandlerSet } from '@dxos/operation';
|
|
4
|
+
|
|
5
|
+
export * as KanbanOperation from './definitions';
|
|
6
|
+
|
|
7
|
+
export const KanbanOperationHandlerSet = OperationHandlerSet.lazy(
|
|
8
|
+
() => import('./delete-card'),
|
|
9
|
+
() => import('./delete-card-field'),
|
|
10
|
+
() => import('./restore-card'),
|
|
11
|
+
() => import('./restore-card-field'),
|
|
12
|
+
);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright 2025 DXOS.org
|
|
2
|
+
|
|
3
|
+
import * as Effect from 'effect/Effect';
|
|
4
|
+
|
|
5
|
+
import { Capabilities, Capability } from '@dxos/app-framework';
|
|
6
|
+
import { JsonSchema, Obj } from '@dxos/echo';
|
|
7
|
+
import { type EchoSchema } from '@dxos/echo/internal';
|
|
8
|
+
import { invariant } from '@dxos/invariant';
|
|
9
|
+
import { Operation } from '@dxos/operation';
|
|
10
|
+
import { ProjectionModel, createEchoChangeCallback, getTypenameFromQuery } from '@dxos/schema';
|
|
11
|
+
|
|
12
|
+
import { RestoreCardField } from './definitions';
|
|
13
|
+
|
|
14
|
+
const handler: Operation.WithHandler<typeof RestoreCardField> = RestoreCardField.pipe(
|
|
15
|
+
Operation.withHandler(
|
|
16
|
+
Effect.fnUntraced(function* ({ view, field, props, index }) {
|
|
17
|
+
const registry = yield* Capability.get(Capabilities.AtomRegistry);
|
|
18
|
+
const db = Obj.getDatabase(view);
|
|
19
|
+
invariant(db, 'Database not found');
|
|
20
|
+
const schema = yield* Effect.promise(() =>
|
|
21
|
+
db.schemaRegistry
|
|
22
|
+
.query({
|
|
23
|
+
typename: getTypenameFromQuery(view.query.ast)!,
|
|
24
|
+
location: ['database', 'runtime'],
|
|
25
|
+
})
|
|
26
|
+
.first(),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const projection = new ProjectionModel({
|
|
30
|
+
registry,
|
|
31
|
+
view,
|
|
32
|
+
baseSchema: JsonSchema.toJsonSchema(schema),
|
|
33
|
+
change: createEchoChangeCallback(view, schema as EchoSchema),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
projection.setFieldProjection({ field, props }, index);
|
|
37
|
+
}),
|
|
38
|
+
),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
export default handler;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright 2025 DXOS.org
|
|
2
|
+
|
|
3
|
+
import * as Effect from 'effect/Effect';
|
|
4
|
+
|
|
5
|
+
import { Obj } from '@dxos/echo';
|
|
6
|
+
import { invariant } from '@dxos/invariant';
|
|
7
|
+
import { Operation } from '@dxos/operation';
|
|
8
|
+
|
|
9
|
+
import { RestoreCard } from './definitions';
|
|
10
|
+
|
|
11
|
+
const handler: Operation.WithHandler<typeof RestoreCard> = RestoreCard.pipe(
|
|
12
|
+
Operation.withHandler(({ card }) =>
|
|
13
|
+
Effect.sync(() => {
|
|
14
|
+
const db = Obj.getDatabase(card);
|
|
15
|
+
invariant(db);
|
|
16
|
+
db.add(card);
|
|
17
|
+
}),
|
|
18
|
+
),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export default handler;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { BoardManager as MosaicBoardManager } from '@dxos/react-ui-mosaic/playwright';
|
|
6
|
+
|
|
7
|
+
export class BoardManager extends MosaicBoardManager {
|
|
8
|
+
async waitUntilReady(): Promise<void> {
|
|
9
|
+
await this.columns().first().waitFor({ state: 'visible' });
|
|
10
|
+
await this.columns().nth(2).waitFor({ state: 'visible' });
|
|
11
|
+
await this.column(1).items().first().waitFor({ state: 'visible' });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { defineConfig } from '@playwright/test';
|
|
6
|
+
|
|
7
|
+
import { e2ePreset } from '@dxos/test-utils/playwright';
|
|
8
|
+
|
|
9
|
+
export default defineConfig({
|
|
10
|
+
...e2ePreset(import.meta.dirname),
|
|
11
|
+
// TODO(wittjosiah): Stories are slow to start up.
|
|
12
|
+
timeout: 60_000,
|
|
13
|
+
// TODO(wittjosiah): Avoid hard-coding ports.
|
|
14
|
+
webServer: {
|
|
15
|
+
command: 'pnpm storybook dev --ci --quiet --port=9011 --config-dir=.storybook',
|
|
16
|
+
port: 9011,
|
|
17
|
+
reuseExistingServer: false,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Page, expect, test } from '@playwright/test';
|
|
6
|
+
|
|
7
|
+
import { setupPage, storybookUrl } from '@dxos/test-utils/playwright';
|
|
8
|
+
|
|
9
|
+
import { BoardManager } from './board-manager';
|
|
10
|
+
|
|
11
|
+
const PORT = 9011;
|
|
12
|
+
const STORY_URL = storybookUrl('plugins-plugin-kanban-containers-kanban--mutable-schema', PORT);
|
|
13
|
+
|
|
14
|
+
test.describe('Kanban MutableSchema', () => {
|
|
15
|
+
let page: Page;
|
|
16
|
+
let board: BoardManager;
|
|
17
|
+
|
|
18
|
+
test.beforeEach(async ({ browser }) => {
|
|
19
|
+
// Larger viewport to avoid triggering scroll-assist behaviour on simple drag operations.
|
|
20
|
+
({ page } = await setupPage(browser, { url: STORY_URL, viewportSize: { width: 1920, height: 1080 } }));
|
|
21
|
+
board = new BoardManager(page.locator('body'));
|
|
22
|
+
await board.waitUntilReady();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test.afterEach(async () => {
|
|
26
|
+
await page.close();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('rearrange columns', async () => {
|
|
30
|
+
const col1Label = await board.column(1).title().textContent();
|
|
31
|
+
const col2Label = await board.column(2).title().textContent();
|
|
32
|
+
expect(col1Label).not.toBeNull();
|
|
33
|
+
expect(col2Label).not.toBeNull();
|
|
34
|
+
|
|
35
|
+
await board.column(1).dragTo(board.column(2).header());
|
|
36
|
+
|
|
37
|
+
await expect(board.column(1).title()).toHaveText(col2Label!);
|
|
38
|
+
await expect(board.column(2).title()).toHaveText(col1Label!);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('rearrange within column', async () => {
|
|
42
|
+
// Column 0 is uncategorized (empty). Use column 1 (first status column).
|
|
43
|
+
const column = board.column(1);
|
|
44
|
+
const countBefore = await column.items().count();
|
|
45
|
+
|
|
46
|
+
const firstLabel = await column.item(0).title().textContent();
|
|
47
|
+
const secondLabel = await column.item(1).title().textContent();
|
|
48
|
+
expect(firstLabel).not.toBeNull();
|
|
49
|
+
expect(secondLabel).not.toBeNull();
|
|
50
|
+
|
|
51
|
+
// Drag first item below the second item.
|
|
52
|
+
await column.item(0).dragTo(column.item(1).locator, { x: 0, y: 200 });
|
|
53
|
+
|
|
54
|
+
// Item count should stay the same.
|
|
55
|
+
await expect(column.items()).toHaveCount(countBefore);
|
|
56
|
+
|
|
57
|
+
// The first item should now be what was previously the second item.
|
|
58
|
+
await expect(column.item(0).title()).toHaveText(secondLabel!);
|
|
59
|
+
|
|
60
|
+
// The original first item should now be at index 1.
|
|
61
|
+
await expect(column.item(1).title()).toHaveText(firstLabel!);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('drag to beginning of another column', async () => {
|
|
65
|
+
// Column 0 is uncategorized (empty). Use columns 1 and 2 (both have items).
|
|
66
|
+
const col1 = board.column(1);
|
|
67
|
+
const col2 = board.column(2);
|
|
68
|
+
|
|
69
|
+
const col1CountBefore = await col1.items().count();
|
|
70
|
+
const col2CountBefore = await col2.items().count();
|
|
71
|
+
const draggedLabel = await col1.item(0).title().textContent();
|
|
72
|
+
expect(draggedLabel).not.toBeNull();
|
|
73
|
+
|
|
74
|
+
// Drop above first item. Kanban cards are taller; use larger negative y so we land in top half.
|
|
75
|
+
await col1.item(0).dragTo(col2.item(0).locator, { x: 0, y: -30 });
|
|
76
|
+
|
|
77
|
+
await expect(col1.items()).toHaveCount(col1CountBefore - 1);
|
|
78
|
+
await expect(col2.items()).toHaveCount(col2CountBefore + 1);
|
|
79
|
+
await expect(col2.item(0).title()).toHaveText(draggedLabel!);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('drag into empty column', async () => {
|
|
83
|
+
// Uncategorized is column 0 (empty); first populated column is at index 1.
|
|
84
|
+
const emptyColumn = board.column(0);
|
|
85
|
+
const sourceColumn = board.column(1);
|
|
86
|
+
|
|
87
|
+
const sourceCountBefore = await sourceColumn.items().count();
|
|
88
|
+
const draggedLabel = await sourceColumn.item(0).title().textContent();
|
|
89
|
+
expect(draggedLabel).not.toBeNull();
|
|
90
|
+
|
|
91
|
+
await sourceColumn.item(0).dragTo(emptyColumn.header(), { x: 0, y: 40 });
|
|
92
|
+
|
|
93
|
+
await expect(sourceColumn.items()).toHaveCount(sourceCountBefore - 1);
|
|
94
|
+
await expect(emptyColumn.items()).toHaveCount(1);
|
|
95
|
+
await expect(emptyColumn.item(0).title()).toHaveText(draggedLabel!);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('create new item', async () => {
|
|
99
|
+
// Use first populated column.
|
|
100
|
+
const column = board.column(1);
|
|
101
|
+
const countBefore = await column.items().count();
|
|
102
|
+
|
|
103
|
+
await column.addItem();
|
|
104
|
+
|
|
105
|
+
await expect(column.items()).toHaveCount(countBefore + 1);
|
|
106
|
+
});
|
|
107
|
+
});
|