@dxos/plugin-kanban 0.8.4-main.f9ba587 → 0.8.4-main.fcc0d83b33
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 +27 -0
- package/dist/lib/browser/blueprints/index.mjs.map +7 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/browser/chunk-T32TEM55.mjs +105 -0
- package/dist/lib/browser/chunk-T32TEM55.mjs.map +7 -0
- package/dist/lib/browser/delete-card-7OSCNCW2.mjs +24 -0
- package/dist/lib/browser/delete-card-7OSCNCW2.mjs.map +7 -0
- package/dist/lib/browser/delete-card-field-NSB2RE3Z.mjs +42 -0
- package/dist/lib/browser/delete-card-field-NSB2RE3Z.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +76 -95
- 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-FO3WERIE.mjs +21 -0
- package/dist/lib/browser/restore-card-FO3WERIE.mjs.map +7 -0
- package/dist/lib/browser/restore-card-field-U5XYEEOW.mjs +40 -0
- package/dist/lib/browser/restore-card-field-U5XYEEOW.mjs.map +7 -0
- package/dist/lib/browser/translations.mjs +44 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +154 -7
- package/dist/lib/browser/types/index.mjs.map +4 -4
- package/dist/lib/node-esm/blueprints/index.mjs +28 -0
- package/dist/lib/node-esm/blueprints/index.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-W2RNFBMZ.mjs +106 -0
- package/dist/lib/node-esm/chunk-W2RNFBMZ.mjs.map +7 -0
- package/dist/lib/node-esm/delete-card-ZIREL6HN.mjs +25 -0
- package/dist/lib/node-esm/delete-card-ZIREL6HN.mjs.map +7 -0
- package/dist/lib/node-esm/delete-card-field-IPTEGVPP.mjs +43 -0
- package/dist/lib/node-esm/delete-card-field-IPTEGVPP.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +76 -95
- 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-WJJ4YB7K.mjs +22 -0
- package/dist/lib/node-esm/restore-card-WJJ4YB7K.mjs.map +7 -0
- package/dist/lib/node-esm/restore-card-field-L24WJXAW.mjs +41 -0
- package/dist/lib/node-esm/restore-card-field-L24WJXAW.mjs.map +7 -0
- package/dist/lib/node-esm/translations.mjs +45 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +154 -7
- package/dist/lib/node-esm/types/index.mjs.map +4 -4
- package/dist/types/src/KanbanPlugin.d.ts +2 -1
- package/dist/types/src/KanbanPlugin.d.ts.map +1 -1
- package/dist/types/src/blueprints/index.d.ts +2 -0
- package/dist/types/src/blueprints/index.d.ts.map +1 -0
- package/dist/types/src/blueprints/kanban-blueprint.d.ts +4 -0
- package/dist/types/src/blueprints/kanban-blueprint.d.ts.map +1 -0
- package/dist/types/src/capabilities/artifact-definition.d.ts +3 -2
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -1
- package/dist/types/src/capabilities/blueprint-definition.d.ts +5 -0
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +7 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/migrations.d.ts +5 -0
- package/dist/types/src/capabilities/migrations.d.ts.map +1 -0
- 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 +3 -2
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- 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 +57 -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 +2 -0
- package/dist/types/src/containers/KanbanContainer/index.d.ts.map +1 -0
- package/dist/types/src/containers/KanbanSettings/KanbanSettings.d.ts +13 -0
- package/dist/types/src/containers/KanbanSettings/KanbanSettings.d.ts.map +1 -0
- package/dist/types/src/containers/KanbanSettings/index.d.ts +2 -0
- package/dist/types/src/containers/KanbanSettings/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 +7 -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/useItemsProjection.d.ts +10 -0
- package/dist/types/src/hooks/useItemsProjection.d.ts.map +1 -0
- package/dist/types/src/hooks/useKanbanBoardModel.browser.test.d.ts +2 -0
- package/dist/types/src/hooks/useKanbanBoardModel.browser.test.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/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/meta.d.ts +2 -3
- package/dist/types/src/meta.d.ts.map +1 -1
- 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 +1 -2
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +50 -22
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Kanban.d.ts +109 -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 +3 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/migrations.test.d.ts +2 -0
- package/dist/types/src/types/migrations.test.d.ts.map +1 -0
- package/dist/types/src/types/schema.d.ts +18 -53
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +26 -9
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/src/util/arrangement.d.ts +72 -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 +89 -54
- package/src/KanbanPlugin.tsx +55 -56
- package/src/blueprints/index.ts +5 -0
- package/src/blueprints/kanban-blueprint.ts +27 -0
- package/src/capabilities/artifact-definition.ts +123 -108
- package/src/capabilities/blueprint-definition.ts +17 -0
- package/src/capabilities/index.ts +10 -4
- package/src/capabilities/migrations.ts +35 -0
- package/src/capabilities/operation-handler.ts +14 -0
- package/src/capabilities/react-surface.tsx +79 -65
- package/src/capabilities/undo-mappings.ts +34 -0
- package/src/components/KanbanBoard/KanbanBoard.stories.tsx +146 -0
- package/src/components/KanbanBoard/KanbanBoard.tsx +198 -0
- package/src/components/KanbanBoard/KanbanCard.tsx +98 -0
- package/src/components/KanbanBoard/KanbanColumn.tsx +71 -0
- package/src/components/KanbanBoard/index.ts +5 -0
- package/src/components/index.ts +1 -2
- package/src/containers/KanbanContainer/KanbanContainer.stories.tsx +275 -0
- package/src/containers/KanbanContainer/KanbanContainer.tsx +178 -0
- package/src/containers/KanbanContainer/index.ts +5 -0
- package/src/containers/KanbanSettings/KanbanSettings.tsx +94 -0
- package/src/containers/KanbanSettings/index.ts +5 -0
- package/src/containers/index.ts +8 -0
- package/src/hooks/index.ts +10 -0
- package/src/hooks/useEchoChangeCallback.ts +30 -0
- package/src/hooks/useItemsProjection.ts +44 -0
- package/src/hooks/useKanbanBoardModel.browser.test.ts +235 -0
- package/src/hooks/useKanbanBoardModel.ts +157 -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 +9 -7
- 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 +2 -3
- package/src/translations.ts +28 -20
- package/src/types/Kanban.ts +151 -0
- package/src/types/constants.ts +9 -0
- package/src/types/index.ts +3 -1
- package/src/types/migrations.test.ts +83 -0
- package/src/types/schema.ts +33 -46
- package/src/types/types.ts +30 -10
- package/src/util/arrangement.test.ts +218 -0
- package/src/util/arrangement.ts +177 -0
- package/src/util/index.ts +5 -0
- package/dist/lib/browser/artifact-definition-H5MOHOV5.mjs +0 -178
- package/dist/lib/browser/artifact-definition-H5MOHOV5.mjs.map +0 -7
- package/dist/lib/browser/chunk-76UNDUHS.mjs +0 -88
- package/dist/lib/browser/chunk-76UNDUHS.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-VJSWAUZD.mjs +0 -297
- package/dist/lib/browser/intent-resolver-VJSWAUZD.mjs.map +0 -7
- package/dist/lib/browser/react-surface-WMVUSDVR.mjs +0 -305
- package/dist/lib/browser/react-surface-WMVUSDVR.mjs.map +0 -7
- package/dist/lib/node-esm/artifact-definition-FDRLWGY5.mjs +0 -179
- package/dist/lib/node-esm/artifact-definition-FDRLWGY5.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-B3AVV7SF.mjs +0 -90
- package/dist/lib/node-esm/chunk-B3AVV7SF.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-3ZSJN2NS.mjs +0 -298
- package/dist/lib/node-esm/intent-resolver-3ZSJN2NS.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-JKYB6SAC.mjs +0 -306
- package/dist/lib/node-esm/react-surface-JKYB6SAC.mjs.map +0 -7
- package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/components/KanbanContainer.d.ts +0 -7
- package/dist/types/src/components/KanbanContainer.d.ts.map +0 -1
- package/dist/types/src/components/KanbanContainer.stories.d.ts +0 -10
- 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/dist/types/src/testing/initialize-kanban.d.ts +0 -17
- package/dist/types/src/testing/initialize-kanban.d.ts.map +0 -1
- package/dist/types/src/testing/kanban-manager.d.ts +0 -7
- package/dist/types/src/testing/kanban-manager.d.ts.map +0 -1
- package/src/capabilities/intent-resolver.ts +0 -71
- package/src/components/KanbanContainer.stories.tsx +0 -191
- package/src/components/KanbanContainer.tsx +0 -95
- package/src/components/KanbanViewEditor.tsx +0 -104
- package/src/testing/initialize-kanban.ts +0 -128
- package/src/testing/kanban-manager.ts +0 -13
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
|
+
import React, { useCallback, useContext, useMemo } from 'react';
|
|
7
|
+
|
|
8
|
+
import { type AppSurface } from '@dxos/app-toolkit/ui';
|
|
9
|
+
import { Obj } from '@dxos/echo';
|
|
10
|
+
import { Format } from '@dxos/echo/internal';
|
|
11
|
+
import { useObject, useSchema } from '@dxos/react-client/echo';
|
|
12
|
+
import { Form, type FormFieldMap, SelectField } from '@dxos/react-ui-form';
|
|
13
|
+
import { getTypenameFromQuery } from '@dxos/schema';
|
|
14
|
+
|
|
15
|
+
import { useProjectionModel } from '#hooks';
|
|
16
|
+
import { type Kanban, KanbanSettingsSchema, KanbanViewSettingsSchema, UNCATEGORIZED_VALUE } from '#types';
|
|
17
|
+
|
|
18
|
+
export type KanbanSettingsProps = AppSurface.ObjectPropertiesProps<Kanban.Kanban>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Settings panel for a Kanban. Renders fields common to every kanban
|
|
22
|
+
* (currently the "Hide uncategorized column" toggle); for view-variant
|
|
23
|
+
* kanbans an additional "Column field" picker drives the View's pivot
|
|
24
|
+
* field. Items-variant kanbans use a hardcoded `spec.pivotField`, so that
|
|
25
|
+
* field is omitted there.
|
|
26
|
+
*/
|
|
27
|
+
export const KanbanSettings = ({ subject: object }: KanbanSettingsProps) => {
|
|
28
|
+
const registry = useContext(RegistryContext);
|
|
29
|
+
const db = Obj.getDatabase(object);
|
|
30
|
+
const isView = object.spec.kind === 'view';
|
|
31
|
+
const [view, updateView] = useObject(object.spec.kind === 'view' ? object.spec.view : undefined);
|
|
32
|
+
const [, updateKanban] = useObject(object);
|
|
33
|
+
const currentTypename = view?.query ? getTypenameFromQuery(view.query.ast) : undefined;
|
|
34
|
+
const schema = useSchema(db, currentTypename);
|
|
35
|
+
const projection = useProjectionModel(schema, object, registry);
|
|
36
|
+
|
|
37
|
+
const fieldProjections = projection?.getFieldProjections() ?? [];
|
|
38
|
+
const selectFields = useMemo(
|
|
39
|
+
() =>
|
|
40
|
+
fieldProjections
|
|
41
|
+
.filter((field) => field.props.format === Format.TypeFormat.SingleSelect)
|
|
42
|
+
.map(({ field }) => ({ value: field.id, label: field.path })),
|
|
43
|
+
[fieldProjections],
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const hideUncategorized = object.arrangement.columns[UNCATEGORIZED_VALUE]?.hidden ?? false;
|
|
47
|
+
|
|
48
|
+
const handleValuesChanged = useCallback(
|
|
49
|
+
(values: Partial<{ columnFieldId: string; hideUncategorized: boolean }>) => {
|
|
50
|
+
if (isView && values.columnFieldId != null) {
|
|
51
|
+
updateView((view) => {
|
|
52
|
+
view.projection.pivotFieldId = values.columnFieldId!;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (values.hideUncategorized !== undefined) {
|
|
56
|
+
updateKanban((kanban) => {
|
|
57
|
+
const existing = kanban.arrangement.columns[UNCATEGORIZED_VALUE];
|
|
58
|
+
if (existing) {
|
|
59
|
+
existing.hidden = values.hideUncategorized;
|
|
60
|
+
} else {
|
|
61
|
+
kanban.arrangement.columns[UNCATEGORIZED_VALUE] = {
|
|
62
|
+
ids: [],
|
|
63
|
+
hidden: values.hideUncategorized,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
[isView, updateView, updateKanban],
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const initialValues = useMemo(
|
|
73
|
+
() => ({
|
|
74
|
+
...(isView ? { columnFieldId: view?.projection.pivotFieldId } : {}),
|
|
75
|
+
hideUncategorized,
|
|
76
|
+
}),
|
|
77
|
+
[isView, view?.projection.pivotFieldId, hideUncategorized],
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const fieldMap: FormFieldMap = useMemo(
|
|
81
|
+
() => ({ columnFieldId: (props) => <SelectField {...props} options={selectFields} /> }),
|
|
82
|
+
[selectFields],
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// Schema is picked by `kanban.spec.kind` — they have different shapes,
|
|
86
|
+
// so cast for `Form.Root`'s single-schema prop.
|
|
87
|
+
const settingsSchema = (isView ? KanbanViewSettingsSchema : KanbanSettingsSchema) as any;
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<Form.Root schema={settingsSchema} values={initialValues} fieldMap={fieldMap} onValuesChanged={handleValuesChanged}>
|
|
91
|
+
<Form.FieldSet />
|
|
92
|
+
</Form.Root>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type ComponentType, lazy } from 'react';
|
|
6
|
+
|
|
7
|
+
export const KanbanContainer: ComponentType<any> = lazy(() => import('./KanbanContainer'));
|
|
8
|
+
export const KanbanSettings: ComponentType<any> = lazy(() => import('./KanbanSettings'));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
export * from './useEchoChangeCallback';
|
|
6
|
+
export * from './useItemsProjection';
|
|
7
|
+
export * from './useKanbanBoardModel';
|
|
8
|
+
export * from './useKanbanColumnEventHandler';
|
|
9
|
+
export * from './useKanbanItemEventHandler';
|
|
10
|
+
export * from './useProjectionModel';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import { Obj } from '@dxos/echo';
|
|
8
|
+
|
|
9
|
+
import { type Kanban, type KanbanChangeCallback } from '#types';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates a change callback for ECHO-backed kanban and items (plain function, no hooks).
|
|
13
|
+
* Use this when the kanban and items are stored in the ECHO database.
|
|
14
|
+
*/
|
|
15
|
+
export const createEchoChangeCallback = <T extends Obj.Unknown>(kanban: Kanban.Kanban): KanbanChangeCallback<T> => ({
|
|
16
|
+
kanban: (mutate) => Obj.update(kanban, (kanban) => mutate(kanban)),
|
|
17
|
+
setItemField: (item, field, value) => {
|
|
18
|
+
Obj.update(item, (item: any) => {
|
|
19
|
+
item[field] = value;
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Returns a memoized ECHO change callback for the given kanban.
|
|
26
|
+
* Returns null when kanban is undefined.
|
|
27
|
+
*/
|
|
28
|
+
export const useEchoChangeCallback = <T extends Obj.Unknown = Obj.Unknown>(
|
|
29
|
+
kanban: Kanban.Kanban | undefined,
|
|
30
|
+
): KanbanChangeCallback<T> | null => useMemo(() => (kanban ? createEchoChangeCallback<T>(kanban) : null), [kanban]);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Atom } from '@effect-atom/atom-react';
|
|
6
|
+
import { useMemo } from 'react';
|
|
7
|
+
|
|
8
|
+
import type { ProjectionModel } from '@dxos/schema';
|
|
9
|
+
|
|
10
|
+
import { type Kanban } from '#types';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Minimal `ProjectionModel` for `spec.kind === 'items'` (no View). Supplies `pivotField`
|
|
14
|
+
* and column options from `arrangement.columns` keys—written by sync so columns exist
|
|
15
|
+
* before refs hydrate. Stubs `getFieldProjections` / `getHiddenProperties` for shared
|
|
16
|
+
* board/card UI; hides the pivot on the card body (column shows it); Expando cards render title only.
|
|
17
|
+
*/
|
|
18
|
+
export const useItemsProjection = (kanban: Kanban.KanbanItems): ProjectionModel => {
|
|
19
|
+
return useMemo(() => {
|
|
20
|
+
const pivotField = kanban.spec.pivotField;
|
|
21
|
+
|
|
22
|
+
const optionIds = Object.keys(kanban.arrangement?.columns ?? {});
|
|
23
|
+
const options = optionIds.map((id) => ({ id, title: id, color: 'neutral' as const }));
|
|
24
|
+
|
|
25
|
+
const fieldProjection: any = {
|
|
26
|
+
field: { id: pivotField, path: pivotField },
|
|
27
|
+
props: { property: pivotField, options },
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const fields = Atom.make(() => [fieldProjection.field]);
|
|
31
|
+
|
|
32
|
+
const stub: Pick<ProjectionModel, 'tryGetFieldProjection' | 'getFieldProjections' | 'getHiddenProperties'> & {
|
|
33
|
+
fields: typeof fields;
|
|
34
|
+
} = {
|
|
35
|
+
fields,
|
|
36
|
+
tryGetFieldProjection: (id: string) => (id === pivotField ? fieldProjection : undefined),
|
|
37
|
+
getFieldProjections: () => [],
|
|
38
|
+
getHiddenProperties: () => [pivotField],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// TODO(wittjosiah): Refactor ProjectionModel to be an interface that we can fulfill.
|
|
42
|
+
return stub as unknown as ProjectionModel;
|
|
43
|
+
}, [kanban.arrangement?.columns, kanban.spec.pivotField]);
|
|
44
|
+
};
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Atom, Registry } from '@effect-atom/atom-react';
|
|
6
|
+
import { act, renderHook } from '@testing-library/react';
|
|
7
|
+
import * as Schema from 'effect/Schema';
|
|
8
|
+
import { beforeEach, describe, test } from 'vitest';
|
|
9
|
+
|
|
10
|
+
import { Filter, JsonSchema, Obj, Query, Type } from '@dxos/echo';
|
|
11
|
+
import { type View } from '@dxos/echo';
|
|
12
|
+
import { Format, FormatAnnotation, PropertyMetaAnnotationId } from '@dxos/echo/internal';
|
|
13
|
+
import { ObjectId } from '@dxos/keys';
|
|
14
|
+
import { ProjectionModel, ViewModel, createDirectChangeCallback } from '@dxos/schema';
|
|
15
|
+
|
|
16
|
+
import { Kanban } from '#types';
|
|
17
|
+
|
|
18
|
+
import { useKanbanBoardModel } from './useKanbanBoardModel';
|
|
19
|
+
|
|
20
|
+
// TODO(wittjosiah): Consider adding single-select to TestSchema.Task and using that instead.
|
|
21
|
+
const KanbanTaskSchema = Schema.Struct({
|
|
22
|
+
title: Schema.optional(Schema.String),
|
|
23
|
+
status: Schema.Literal('__uncategorized__', 'a', 'b').pipe(
|
|
24
|
+
FormatAnnotation.set(Format.TypeFormat.SingleSelect),
|
|
25
|
+
Schema.annotations({
|
|
26
|
+
title: 'Status',
|
|
27
|
+
[PropertyMetaAnnotationId]: {
|
|
28
|
+
singleSelect: {
|
|
29
|
+
options: [
|
|
30
|
+
{ id: '__uncategorized__', title: 'Uncategorized', color: 'neutral' },
|
|
31
|
+
{ id: 'a', title: 'A', color: 'blue' },
|
|
32
|
+
{ id: 'b', title: 'B', color: 'green' },
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
Schema.optional,
|
|
38
|
+
),
|
|
39
|
+
}).pipe(
|
|
40
|
+
Type.object({
|
|
41
|
+
typename: 'com.example.type.kanban-task',
|
|
42
|
+
version: '0.1.0',
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
type KanbanTask = Schema.Schema.Type<typeof KanbanTaskSchema>;
|
|
47
|
+
|
|
48
|
+
describe('useKanbanBoardModel', () => {
|
|
49
|
+
let registry: Registry.Registry;
|
|
50
|
+
let view: View.View;
|
|
51
|
+
let kanban: Kanban.Kanban;
|
|
52
|
+
let projection: ProjectionModel;
|
|
53
|
+
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
registry = Registry.make();
|
|
56
|
+
const jsonSchema = JsonSchema.toJsonSchema(KanbanTaskSchema) as Parameters<typeof createDirectChangeCallback>[1];
|
|
57
|
+
view = ViewModel.make({
|
|
58
|
+
query: Query.select(Filter.type(KanbanTaskSchema)),
|
|
59
|
+
jsonSchema,
|
|
60
|
+
pivotFieldName: 'status',
|
|
61
|
+
});
|
|
62
|
+
kanban = Kanban.make({
|
|
63
|
+
view: view,
|
|
64
|
+
arrangement: {
|
|
65
|
+
order: ['a', 'b'],
|
|
66
|
+
columns: { a: { ids: [] }, b: { ids: [] } },
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
projection = new ProjectionModel({
|
|
70
|
+
registry,
|
|
71
|
+
view,
|
|
72
|
+
baseSchema: jsonSchema,
|
|
73
|
+
change: createDirectChangeCallback(view.projection, jsonSchema),
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('returns model with getColumns and getItems', ({ expect }) => {
|
|
78
|
+
const itemA = Obj.make(KanbanTaskSchema, { status: 'a' });
|
|
79
|
+
const itemB = Obj.make(KanbanTaskSchema, { status: 'b' });
|
|
80
|
+
const initialItems: KanbanTask[] = [itemA, itemB];
|
|
81
|
+
const itemsAtom = Atom.make<KanbanTask[]>(() => initialItems);
|
|
82
|
+
|
|
83
|
+
const { result } = renderHook(() => useKanbanBoardModel(kanban, projection, itemsAtom, registry));
|
|
84
|
+
|
|
85
|
+
const model = result.current;
|
|
86
|
+
expect(model.getColumnId).toBeDefined();
|
|
87
|
+
expect(model.getItemId).toBeDefined();
|
|
88
|
+
expect(model.isColumn).toBeDefined();
|
|
89
|
+
expect(model.isItem).toBeDefined();
|
|
90
|
+
|
|
91
|
+
const columns = model.getColumns();
|
|
92
|
+
expect(columns.length).toBeGreaterThanOrEqual(1);
|
|
93
|
+
const columnValues = columns.map((col) => col.columnValue);
|
|
94
|
+
expect(columnValues).toContain('a');
|
|
95
|
+
expect(columnValues).toContain('b');
|
|
96
|
+
|
|
97
|
+
const colA = columns.find((c) => c.columnValue === 'a');
|
|
98
|
+
const colB = columns.find((c) => c.columnValue === 'b');
|
|
99
|
+
expect(colA).toBeDefined();
|
|
100
|
+
expect(colB).toBeDefined();
|
|
101
|
+
|
|
102
|
+
const itemsA = model.getItems(colA!);
|
|
103
|
+
const itemsB = model.getItems(colB!);
|
|
104
|
+
expect(itemsA.map((i) => i.id)).toContain(itemA.id);
|
|
105
|
+
expect(itemsB.map((i) => i.id)).toContain(itemB.id);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('getItems updates when itemsAtom source changes', ({ expect }) => {
|
|
109
|
+
const initialItem = Obj.make(KanbanTaskSchema, { status: 'a' });
|
|
110
|
+
const initialItems: KanbanTask[] = [initialItem];
|
|
111
|
+
const initialItemsAtom = Atom.make<KanbanTask[]>(() => initialItems);
|
|
112
|
+
|
|
113
|
+
const { result, rerender } = renderHook(
|
|
114
|
+
({ itemsAtom }) => useKanbanBoardModel(kanban, projection, itemsAtom, registry),
|
|
115
|
+
{ initialProps: { itemsAtom: initialItemsAtom } },
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const columns = result.current.getColumns();
|
|
119
|
+
const colA = columns.find((c) => c.columnValue === 'a');
|
|
120
|
+
expect(colA).toBeDefined();
|
|
121
|
+
expect(result.current.getItems(colA!).length).toBe(1);
|
|
122
|
+
expect(result.current.getItems(colA!).map((i) => i.id)).toEqual([initialItem.id]);
|
|
123
|
+
|
|
124
|
+
const secondItem = Obj.make(KanbanTaskSchema, { status: 'a' });
|
|
125
|
+
const newItems: KanbanTask[] = [initialItem, secondItem];
|
|
126
|
+
const newItemsAtom = Atom.make<KanbanTask[]>(() => newItems);
|
|
127
|
+
act(() => {
|
|
128
|
+
rerender({ itemsAtom: newItemsAtom });
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
expect(result.current.getItems(colA!).length).toBe(2);
|
|
132
|
+
expect(result.current.getItems(colA!).map((i) => i.id)).toEqual([initialItem.id, secondItem.id]);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('columns atom updates when kanban arrangement changes', ({ expect }) => {
|
|
136
|
+
const itemsAtom = Atom.make<KanbanTask[]>(() => []);
|
|
137
|
+
const { result } = renderHook(() => useKanbanBoardModel(kanban, projection, itemsAtom, registry));
|
|
138
|
+
|
|
139
|
+
let columnsUpdateCount = 0;
|
|
140
|
+
registry.subscribe(result.current.columns, () => {
|
|
141
|
+
columnsUpdateCount++;
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const columnsBefore = result.current.getColumns();
|
|
145
|
+
const orderBefore = columnsBefore.map((c) => c.columnValue);
|
|
146
|
+
expect(orderBefore).toEqual(['__uncategorized__', 'a', 'b']);
|
|
147
|
+
|
|
148
|
+
act(() => {
|
|
149
|
+
Obj.update(kanban, (kanban) => {
|
|
150
|
+
kanban.arrangement.order = ['b', 'a'];
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const columnsAfter = registry.get(result.current.columns) ?? [];
|
|
155
|
+
const orderAfter = columnsAfter.map((c) => c.columnValue);
|
|
156
|
+
expect(orderAfter).toEqual(['__uncategorized__', 'b', 'a']);
|
|
157
|
+
// TODO(wittjosiah): Try to reduce to 1.
|
|
158
|
+
expect(columnsUpdateCount).toBe(2);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('getItems returns items in column ordered by arrangement ids', ({ expect }) => {
|
|
162
|
+
const item1 = Obj.make(KanbanTaskSchema, {
|
|
163
|
+
id: ObjectId.random(),
|
|
164
|
+
status: 'a',
|
|
165
|
+
});
|
|
166
|
+
const item2 = Obj.make(KanbanTaskSchema, {
|
|
167
|
+
id: ObjectId.random(),
|
|
168
|
+
status: 'a',
|
|
169
|
+
});
|
|
170
|
+
const item3 = Obj.make(KanbanTaskSchema, {
|
|
171
|
+
id: ObjectId.random(),
|
|
172
|
+
status: 'a',
|
|
173
|
+
});
|
|
174
|
+
const items: KanbanTask[] = [item1, item2, item3];
|
|
175
|
+
const itemsAtom = Atom.make<KanbanTask[]>(() => items);
|
|
176
|
+
|
|
177
|
+
const { result } = renderHook(() => useKanbanBoardModel(kanban, projection, itemsAtom, registry));
|
|
178
|
+
|
|
179
|
+
const columns = result.current.getColumns();
|
|
180
|
+
const colA = columns.find((c) => c.columnValue === 'a');
|
|
181
|
+
expect(colA).toBeDefined();
|
|
182
|
+
expect(result.current.getItems(colA!).length).toBe(3);
|
|
183
|
+
|
|
184
|
+
let itemsColAUpdateCount = 0;
|
|
185
|
+
registry.subscribe(result.current.items(colA!), () => {
|
|
186
|
+
itemsColAUpdateCount++;
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
act(() => {
|
|
190
|
+
Obj.update(kanban, (kanban) => {
|
|
191
|
+
kanban.arrangement.columns['a'] = {
|
|
192
|
+
ids: [item3.id, item1.id, item2.id],
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const itemsAfter = result.current.getItems(colA!);
|
|
198
|
+
expect(itemsAfter.map((i) => i.id)).toEqual([item3.id, item1.id, item2.id]);
|
|
199
|
+
expect(itemsColAUpdateCount).toBe(1);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('subscribing to one column items atom does not fire when another column changes', ({ expect }) => {
|
|
203
|
+
const itemA = Obj.make(KanbanTaskSchema, {
|
|
204
|
+
id: ObjectId.random(),
|
|
205
|
+
status: 'a',
|
|
206
|
+
});
|
|
207
|
+
const itemB = Obj.make(KanbanTaskSchema, {
|
|
208
|
+
id: ObjectId.random(),
|
|
209
|
+
status: 'b',
|
|
210
|
+
});
|
|
211
|
+
const items: KanbanTask[] = [itemA, itemB];
|
|
212
|
+
const itemsAtom = Atom.make<KanbanTask[]>(() => items);
|
|
213
|
+
|
|
214
|
+
const { result } = renderHook(() => useKanbanBoardModel(kanban, projection, itemsAtom, registry));
|
|
215
|
+
|
|
216
|
+
const columns = result.current.getColumns();
|
|
217
|
+
const colA = columns.find((c) => c.columnValue === 'a');
|
|
218
|
+
const colB = columns.find((c) => c.columnValue === 'b');
|
|
219
|
+
expect(colA).toBeDefined();
|
|
220
|
+
expect(colB).toBeDefined();
|
|
221
|
+
|
|
222
|
+
let itemsColAUpdateCount = 0;
|
|
223
|
+
registry.subscribe(result.current.items(colA!), () => {
|
|
224
|
+
itemsColAUpdateCount++;
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
act(() => {
|
|
228
|
+
Obj.update(kanban, (kanban) => {
|
|
229
|
+
kanban.arrangement.columns['b'] = { ids: [itemB.id] };
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
expect(itemsColAUpdateCount).toBe(0);
|
|
234
|
+
});
|
|
235
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Atom, type Registry } from '@effect-atom/atom-react';
|
|
6
|
+
import { useMemo } from 'react';
|
|
7
|
+
|
|
8
|
+
import { Obj } from '@dxos/echo';
|
|
9
|
+
import { AtomObj } from '@dxos/echo-atom';
|
|
10
|
+
import type { BoardModel } from '@dxos/react-ui-mosaic';
|
|
11
|
+
import type { ProjectionModel } from '@dxos/schema';
|
|
12
|
+
|
|
13
|
+
import { type BaseKanbanItem, type ColumnStructure, type Kanban } from '#types';
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
computeColumnStructure,
|
|
17
|
+
getOrderByColumnFromArrangement,
|
|
18
|
+
getOrderFromArrangement,
|
|
19
|
+
orderItemsInColumn,
|
|
20
|
+
} from '../util';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Builds a board model that maps kanban arrangement and projection onto columns and per-column items.
|
|
24
|
+
*
|
|
25
|
+
* @template T - Item type (must have id; defaults to BaseKanbanItem).
|
|
26
|
+
* @param kanban - Kanban object (arrangement, view).
|
|
27
|
+
* @param projection - ProjectionModel for pivot field and options.
|
|
28
|
+
* @param itemsAtom - Atom holding the full item list.
|
|
29
|
+
* @param registry - Registry for reading atom values.
|
|
30
|
+
* @returns BoardModel with columns atom, items family, and getColumns/getItems.
|
|
31
|
+
*/
|
|
32
|
+
export function useKanbanBoardModel<T extends BaseKanbanItem = BaseKanbanItem>(
|
|
33
|
+
kanban: Kanban.Kanban,
|
|
34
|
+
projection: ProjectionModel,
|
|
35
|
+
itemsAtom: Atom.Atom<T[]>,
|
|
36
|
+
registry: Registry.Registry,
|
|
37
|
+
): BoardModel<ColumnStructure, T> {
|
|
38
|
+
// Source atoms: reactive reads from the kanban object; items come from the passed-in atom (e.g. AtomQuery or in-memory).
|
|
39
|
+
const arrangementAtom = useMemo(() => AtomObj.makeProperty(kanban, 'arrangement'), [kanban]);
|
|
40
|
+
const viewSnapshotAtom = useMemo(
|
|
41
|
+
() =>
|
|
42
|
+
kanban?.spec?.kind === 'view' && kanban.spec.view
|
|
43
|
+
? AtomObj.make(kanban.spec.view)
|
|
44
|
+
: Atom.make<undefined>(() => undefined),
|
|
45
|
+
[kanban?.spec],
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Only changes when the discriminator-relevant pivot input changes.
|
|
50
|
+
* View-variant: derived from `view.projection.pivotFieldId`.
|
|
51
|
+
* Items-variant: the kanban's `spec.pivotField` (the property name itself acts as the field id).
|
|
52
|
+
*/
|
|
53
|
+
const pivotFieldIdAtom = useMemo(
|
|
54
|
+
() =>
|
|
55
|
+
Atom.make((get) => {
|
|
56
|
+
if (kanban?.spec.kind === 'items') {
|
|
57
|
+
return kanban.spec.pivotField;
|
|
58
|
+
}
|
|
59
|
+
return get(viewSnapshotAtom)?.projection?.pivotFieldId as string | undefined;
|
|
60
|
+
}),
|
|
61
|
+
[kanban?.spec, viewSnapshotAtom],
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
// Effective per-column ids: from kanban.arrangement.columns; empty when arrangement has no columns.
|
|
65
|
+
const effectiveByColumnAtom = useMemo(
|
|
66
|
+
() => Atom.make((get) => getOrderByColumnFromArrangement(get(arrangementAtom))),
|
|
67
|
+
[arrangementAtom],
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
// Column structure: depends on pivotFieldId (not full view), arrangement, and projection so columns only fire when pivot or arrangement changes.
|
|
71
|
+
const columnsAtom = useMemo(
|
|
72
|
+
() =>
|
|
73
|
+
Atom.make((get) => {
|
|
74
|
+
const pivotFieldId = get(pivotFieldIdAtom);
|
|
75
|
+
if (pivotFieldId === undefined) {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get(projection.fields);
|
|
80
|
+
const fieldProj = projection.tryGetFieldProjection(pivotFieldId);
|
|
81
|
+
if (!fieldProj) {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const selectOptions = fieldProj.props.options ?? [];
|
|
86
|
+
if (selectOptions.length === 0) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const arrangement = get(arrangementAtom);
|
|
91
|
+
const order = getOrderFromArrangement(arrangement);
|
|
92
|
+
const byColumn = getOrderByColumnFromArrangement(arrangement);
|
|
93
|
+
return computeColumnStructure(order, byColumn, selectOptions);
|
|
94
|
+
}),
|
|
95
|
+
[pivotFieldIdAtom, arrangementAtom, projection],
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
// Per-column slice of arrangement so each column’s items atom only depends on that column’s ids.
|
|
99
|
+
const columnArrangementAtomFamily = useMemo(
|
|
100
|
+
() =>
|
|
101
|
+
Atom.family<string, Atom.Atom<ColumnStructure>>((columnValue: string) =>
|
|
102
|
+
Atom.make((get) => {
|
|
103
|
+
const byColumn = get(effectiveByColumnAtom);
|
|
104
|
+
return {
|
|
105
|
+
columnValue,
|
|
106
|
+
ids: [...(byColumn[columnValue]?.ids ?? [])],
|
|
107
|
+
};
|
|
108
|
+
}),
|
|
109
|
+
),
|
|
110
|
+
[effectiveByColumnAtom],
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
// Items for a single column: filter all items by pivot field, sort by this column’s ids, then append new items.
|
|
114
|
+
const itemsAtomFamily = useMemo(
|
|
115
|
+
() =>
|
|
116
|
+
Atom.family<string, Atom.Atom<T[]>>((columnValue: string) =>
|
|
117
|
+
Atom.make((get) => {
|
|
118
|
+
const columnArr = get(columnArrangementAtomFamily(columnValue));
|
|
119
|
+
const allItems = get(itemsAtom);
|
|
120
|
+
const pivotFieldId = get(pivotFieldIdAtom);
|
|
121
|
+
|
|
122
|
+
if (pivotFieldId === undefined) {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// TODO(wittjosiah): Try to narrow this down further.
|
|
127
|
+
get(projection.fields);
|
|
128
|
+
const fieldProj = projection.tryGetFieldProjection(pivotFieldId);
|
|
129
|
+
if (!fieldProj) {
|
|
130
|
+
return [];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const selectOptions = fieldProj.props.options ?? [];
|
|
134
|
+
const pivotPath = fieldProj.props.property;
|
|
135
|
+
const validColumnValues = new Set(selectOptions.map((opt) => opt.id));
|
|
136
|
+
return orderItemsInColumn(allItems, columnArr.ids, columnValue, pivotPath, validColumnValues);
|
|
137
|
+
}),
|
|
138
|
+
),
|
|
139
|
+
[columnArrangementAtomFamily, itemsAtom, pivotFieldIdAtom, projection],
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
return useMemo(
|
|
143
|
+
() => ({
|
|
144
|
+
getColumnId: (data) => data.columnValue,
|
|
145
|
+
getItemId: (data) => (data as T).id,
|
|
146
|
+
isColumn: (obj): obj is ColumnStructure =>
|
|
147
|
+
typeof obj === 'object' && obj !== null && 'columnValue' in obj && 'ids' in obj,
|
|
148
|
+
// TODO(wittjosiah): This should be restricted to objects of the type of the kanban view.
|
|
149
|
+
isItem: (obj): obj is T => Obj.isObject(obj),
|
|
150
|
+
columns: columnsAtom,
|
|
151
|
+
items: (column) => itemsAtomFamily(column.columnValue),
|
|
152
|
+
getColumns: () => registry.get(columnsAtom) ?? [],
|
|
153
|
+
getItems: (column) => registry.get(itemsAtomFamily(column.columnValue)) ?? [],
|
|
154
|
+
}),
|
|
155
|
+
[columnsAtom, itemsAtomFamily, registry],
|
|
156
|
+
);
|
|
157
|
+
}
|