@dxos/plugin-kanban 0.8.3 → 0.8.4-main.1068cf700f
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/blueprint-definition-GGL6Y5GN.mjs +18 -0
- package/dist/lib/browser/blueprint-definition-GGL6Y5GN.mjs.map +7 -0
- package/dist/lib/browser/blueprints/index.mjs +8 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/chunk-L6N4ZDZ7.mjs +35 -0
- package/dist/lib/browser/chunk-L6N4ZDZ7.mjs.map +7 -0
- package/dist/lib/browser/chunk-XYQO4VL7.mjs +150 -0
- package/dist/lib/browser/chunk-XYQO4VL7.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +66 -72
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/operation-resolver-RFQU4VAB.mjs +162 -0
- package/dist/lib/browser/operation-resolver-RFQU4VAB.mjs.map +7 -0
- package/dist/lib/browser/react-surface-FZQDOE3J.mjs +237 -0
- package/dist/lib/browser/react-surface-FZQDOE3J.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +14 -0
- package/dist/lib/browser/types/index.mjs.map +7 -0
- package/dist/lib/node-esm/blueprint-definition-AMIOYZSF.mjs +19 -0
- package/dist/lib/node-esm/blueprint-definition-AMIOYZSF.mjs.map +7 -0
- package/dist/lib/node-esm/blueprints/index.mjs +9 -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-NN6JMKIT.mjs +152 -0
- package/dist/lib/node-esm/chunk-NN6JMKIT.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-ZHRMUKTF.mjs +36 -0
- package/dist/lib/node-esm/chunk-ZHRMUKTF.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +66 -72
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/operation-resolver-J4JUSY74.mjs +163 -0
- package/dist/lib/node-esm/operation-resolver-J4JUSY74.mjs.map +7 -0
- package/dist/lib/node-esm/react-surface-KOQ56TL6.mjs +238 -0
- package/dist/lib/node-esm/react-surface-KOQ56TL6.mjs.map +7 -0
- package/dist/lib/node-esm/{types.mjs → types/index.mjs} +7 -6
- package/dist/lib/node-esm/types/index.mjs.map +7 -0
- 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 +22 -0
- package/dist/types/src/blueprints/kanban-blueprint.d.ts.map +1 -0
- package/dist/types/src/capabilities/artifact-definition/artifact-definition.d.ts +12 -0
- package/dist/types/src/capabilities/artifact-definition/artifact-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/artifact-definition/index.d.ts +3 -0
- package/dist/types/src/capabilities/artifact-definition/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts +10 -0
- package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/blueprint-definition/index.d.ts +3 -0
- package/dist/types/src/capabilities/blueprint-definition/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +3 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-resolver/index.d.ts +3 -0
- package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +5 -0
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
- package/dist/types/src/components/KanbanContainer.d.ts +4 -5
- package/dist/types/src/components/KanbanContainer.d.ts.map +1 -1
- package/dist/types/src/components/KanbanContainer.stories.d.ts +71 -6
- package/dist/types/src/components/KanbanContainer.stories.d.ts.map +1 -1
- package/dist/types/src/components/KanbanViewEditor.d.ts +3 -3
- package/dist/types/src/components/KanbanViewEditor.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -3
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +36 -53
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +3 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/src/types/schema.d.ts +122 -0
- package/dist/types/src/types/schema.d.ts.map +1 -0
- package/dist/types/src/types/types.d.ts +4 -0
- package/dist/types/src/types/types.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +65 -44
- package/src/KanbanPlugin.tsx +39 -55
- package/src/blueprints/index.ts +5 -0
- package/src/blueprints/kanban-blueprint.ts +24 -0
- package/src/capabilities/artifact-definition/artifact-definition.ts +150 -0
- package/src/capabilities/artifact-definition/index.ts +7 -0
- package/src/capabilities/blueprint-definition/blueprint-definition.ts +24 -0
- package/src/capabilities/blueprint-definition/index.ts +7 -0
- package/src/capabilities/index.ts +3 -5
- package/src/capabilities/operation-resolver/index.ts +7 -0
- package/src/capabilities/operation-resolver/operation-resolver.ts +133 -0
- package/src/capabilities/react-surface/index.ts +7 -0
- package/src/capabilities/react-surface/react-surface.tsx +87 -0
- package/src/components/KanbanContainer.stories.tsx +212 -118
- package/src/components/KanbanContainer.tsx +38 -46
- package/src/components/KanbanViewEditor.tsx +34 -79
- package/src/index.ts +2 -1
- package/src/meta.ts +9 -7
- package/src/translations.ts +10 -10
- package/src/types/index.ts +6 -0
- package/src/types/schema.ts +120 -0
- package/src/types/types.ts +7 -0
- package/dist/lib/browser/artifact-definition-6HNQFL2M.mjs +0 -178
- package/dist/lib/browser/artifact-definition-6HNQFL2M.mjs.map +0 -7
- package/dist/lib/browser/chunk-6JEDX6HA.mjs +0 -85
- package/dist/lib/browser/chunk-6JEDX6HA.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-QQOH5EV2.mjs +0 -297
- package/dist/lib/browser/intent-resolver-QQOH5EV2.mjs.map +0 -7
- package/dist/lib/browser/react-surface-HJL2JRJP.mjs +0 -305
- package/dist/lib/browser/react-surface-HJL2JRJP.mjs.map +0 -7
- package/dist/lib/browser/types.mjs +0 -13
- package/dist/lib/node/artifact-definition-GRCAYCVG.cjs +0 -193
- package/dist/lib/node/artifact-definition-GRCAYCVG.cjs.map +0 -7
- package/dist/lib/node/chunk-ATDUVDIE.cjs +0 -108
- package/dist/lib/node/chunk-ATDUVDIE.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -128
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/intent-resolver-6ZNOIHKY.cjs +0 -308
- package/dist/lib/node/intent-resolver-6ZNOIHKY.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/react-surface-G2J6F7U5.cjs +0 -322
- package/dist/lib/node/react-surface-G2J6F7U5.cjs.map +0 -7
- package/dist/lib/node/types.cjs +0 -35
- package/dist/lib/node/types.cjs.map +0 -7
- package/dist/lib/node-esm/artifact-definition-FA2IAAUQ.mjs +0 -179
- package/dist/lib/node-esm/artifact-definition-FA2IAAUQ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-7DHZSNGQ.mjs +0 -87
- package/dist/lib/node-esm/chunk-7DHZSNGQ.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-4TYFDM4E.mjs +0 -298
- package/dist/lib/node-esm/intent-resolver-4TYFDM4E.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-257WTPQZ.mjs +0 -306
- package/dist/lib/node-esm/react-surface-257WTPQZ.mjs.map +0 -7
- package/dist/types/src/capabilities/artifact-definition.d.ts +0 -11
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +0 -1
- 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/capabilities/react-surface.d.ts +0 -4
- package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -3
- package/dist/types/src/testing/index.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/dist/types/src/testing/playwright/smoke.spec.d.ts +0 -2
- package/dist/types/src/testing/playwright/smoke.spec.d.ts.map +0 -1
- package/dist/types/src/types.d.ts +0 -76
- package/dist/types/src/types.d.ts.map +0 -1
- package/src/capabilities/artifact-definition.ts +0 -136
- package/src/capabilities/intent-resolver.ts +0 -71
- package/src/capabilities/react-surface.tsx +0 -81
- package/src/testing/index.ts +0 -6
- package/src/testing/initialize-kanban.ts +0 -128
- package/src/testing/kanban-manager.ts +0 -13
- package/src/testing/playwright/playwright.config.cts +0 -18
- package/src/testing/playwright/smoke.spec.ts +0 -7
- package/src/types.ts +0 -95
- /package/dist/lib/browser/{types.mjs.map → blueprints/index.mjs.map} +0 -0
- /package/dist/lib/{node-esm/types.mjs.map → browser/chunk-J5LGTIGS.mjs.map} +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import type * as Schema from 'effect/Schema';
|
|
7
|
+
import React, { useMemo } from 'react';
|
|
8
|
+
|
|
9
|
+
import { Capabilities, Capability } from '@dxos/app-framework';
|
|
10
|
+
import { Surface } from '@dxos/app-framework/ui';
|
|
11
|
+
import { Database, Obj, Type } from '@dxos/echo';
|
|
12
|
+
import { findAnnotation } from '@dxos/effect';
|
|
13
|
+
import { type FormFieldComponentProps, SelectField, useFormValues } from '@dxos/react-ui-form';
|
|
14
|
+
import { Kanban } from '@dxos/react-ui-kanban/types';
|
|
15
|
+
import { type Collection } from '@dxos/schema';
|
|
16
|
+
|
|
17
|
+
import { KanbanContainer, KanbanViewEditor } from '../../components';
|
|
18
|
+
import { meta } from '../../meta';
|
|
19
|
+
import { PivotColumnAnnotationId } from '../../types';
|
|
20
|
+
|
|
21
|
+
export default Capability.makeModule(() =>
|
|
22
|
+
Effect.succeed(
|
|
23
|
+
Capability.contributes(Capabilities.ReactSurface, [
|
|
24
|
+
Surface.create({
|
|
25
|
+
id: meta.id,
|
|
26
|
+
role: ['article', 'section'],
|
|
27
|
+
filter: (data): data is { subject: Kanban.Kanban } => Obj.instanceOf(Kanban.Kanban, data.subject),
|
|
28
|
+
component: ({ data, role }) => <KanbanContainer role={role} subject={data.subject} />,
|
|
29
|
+
}),
|
|
30
|
+
Surface.create({
|
|
31
|
+
id: `${meta.id}/object-settings`,
|
|
32
|
+
role: 'object-settings',
|
|
33
|
+
position: 'hoist',
|
|
34
|
+
filter: (data): data is { subject: Kanban.Kanban } => Obj.instanceOf(Kanban.Kanban, data.subject),
|
|
35
|
+
component: ({ data }) => <KanbanViewEditor object={data.subject} />,
|
|
36
|
+
}),
|
|
37
|
+
Surface.create({
|
|
38
|
+
id: `${meta.id}/create-initial-schema-form-[pivot-column]`,
|
|
39
|
+
role: 'form-input',
|
|
40
|
+
filter: (
|
|
41
|
+
data,
|
|
42
|
+
): data is {
|
|
43
|
+
prop: string;
|
|
44
|
+
schema: Schema.Schema<any>;
|
|
45
|
+
target: Database.Database | Collection.Collection | undefined;
|
|
46
|
+
} => {
|
|
47
|
+
const annotation = findAnnotation<boolean>((data.schema as Schema.Schema.All).ast, PivotColumnAnnotationId);
|
|
48
|
+
return !!annotation;
|
|
49
|
+
},
|
|
50
|
+
component: ({ data: { target }, ...inputProps }) => {
|
|
51
|
+
const props = inputProps as any as FormFieldComponentProps;
|
|
52
|
+
const db = Database.isDatabase(target) ? target : target && Obj.getDatabase(target);
|
|
53
|
+
if (!db) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const { typename } = useFormValues('KanbanForm');
|
|
58
|
+
const [selectedSchema] = useMemo(
|
|
59
|
+
() => db.schemaRegistry.query({ location: ['database', 'runtime'], typename }).runSync(),
|
|
60
|
+
[db, typename],
|
|
61
|
+
);
|
|
62
|
+
const singleSelectColumns = useMemo(() => {
|
|
63
|
+
const properties = Type.toJsonSchema(selectedSchema).properties;
|
|
64
|
+
if (!properties) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const columns = Object.entries(properties).reduce<string[]>((acc, [key, value]) => {
|
|
69
|
+
if (typeof value === 'object' && value?.format === 'single-select') {
|
|
70
|
+
acc.push(key);
|
|
71
|
+
}
|
|
72
|
+
return acc;
|
|
73
|
+
}, []);
|
|
74
|
+
|
|
75
|
+
return columns;
|
|
76
|
+
}, [selectedSchema]);
|
|
77
|
+
|
|
78
|
+
if (!typename) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return <SelectField {...props} options={singleSelectColumns.map((column) => ({ value: column }))} />;
|
|
83
|
+
},
|
|
84
|
+
}),
|
|
85
|
+
]),
|
|
86
|
+
),
|
|
87
|
+
);
|
|
@@ -2,78 +2,98 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
6
|
-
import { type
|
|
7
|
-
import
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
|
+
import { type Decorator, type Meta, type StoryObj } from '@storybook/react-vite';
|
|
7
|
+
import * as Effect from 'effect/Effect';
|
|
8
|
+
import React, { useCallback, useContext } from 'react';
|
|
9
|
+
import { expect, waitFor, within } from 'storybook/test';
|
|
8
10
|
|
|
9
|
-
import { IntentPlugin, SettingsPlugin } from '@dxos/app-framework';
|
|
10
11
|
import { withPluginManager } from '@dxos/app-framework/testing';
|
|
11
|
-
import { Obj, Type } from '@dxos/echo';
|
|
12
|
+
import { Obj, type QueryAST, Type } from '@dxos/echo';
|
|
13
|
+
import { type Mutable } from '@dxos/echo/internal';
|
|
12
14
|
import { invariant } from '@dxos/invariant';
|
|
13
15
|
import { ClientPlugin } from '@dxos/plugin-client';
|
|
14
16
|
import { PreviewPlugin } from '@dxos/plugin-preview';
|
|
15
17
|
import { useGlobalFilteredObjects } from '@dxos/plugin-search';
|
|
16
18
|
import { SpacePlugin } from '@dxos/plugin-space';
|
|
17
|
-
import {
|
|
18
|
-
import { ThemePlugin } from '@dxos/plugin-theme';
|
|
19
|
+
import { StorybookPlugin, corePlugins } from '@dxos/plugin-testing';
|
|
19
20
|
import { faker } from '@dxos/random';
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
21
|
+
import { Filter, type Space, useQuery, useSchema, useSpaces } from '@dxos/react-client/echo';
|
|
22
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
22
23
|
import { ViewEditor } from '@dxos/react-ui-form';
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
import {
|
|
25
|
+
Kanban as KanbanComponent,
|
|
26
|
+
translations as kanbanTranslations,
|
|
27
|
+
useKanbanModel,
|
|
28
|
+
useProjectionModel,
|
|
29
|
+
} from '@dxos/react-ui-kanban';
|
|
30
|
+
import { Kanban } from '@dxos/react-ui-kanban/types';
|
|
31
|
+
import { JsonFilter } from '@dxos/react-ui-syntax-highlighter';
|
|
32
|
+
import { View, getTypenameFromQuery } from '@dxos/schema';
|
|
33
|
+
import { Organization, Person } from '@dxos/types';
|
|
28
34
|
|
|
29
|
-
import {
|
|
30
|
-
import translations from '../translations';
|
|
35
|
+
import { translations } from '../translations';
|
|
31
36
|
|
|
32
37
|
faker.seed(0);
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
// Story components.
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
const rollOrg = () => ({
|
|
39
|
+
const createOrg = () => ({
|
|
39
40
|
name: faker.commerce.productName(),
|
|
40
41
|
description: faker.lorem.paragraph(),
|
|
41
42
|
image: faker.image.url(),
|
|
42
43
|
website: faker.internet.url(),
|
|
43
|
-
status: faker.helpers.arrayElement(
|
|
44
|
+
status: faker.helpers.arrayElement(Organization.StatusOptions).id as Organization.Organization['status'],
|
|
44
45
|
});
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
//
|
|
48
|
+
// Story setup helpers.
|
|
49
|
+
//
|
|
50
|
+
|
|
51
|
+
type ClientSetupOptions = {
|
|
52
|
+
types?: Type.Entity.Any[];
|
|
53
|
+
onSpaceCreated?: (space: Space) => Promise<void>;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creates the standard plugin manager decorator with client configuration.
|
|
58
|
+
*/
|
|
59
|
+
const withKanbanPlugins = ({ types = [], onSpaceCreated }: ClientSetupOptions): Decorator =>
|
|
60
|
+
withPluginManager({
|
|
61
|
+
plugins: [
|
|
62
|
+
...corePlugins(),
|
|
63
|
+
ClientPlugin({
|
|
64
|
+
types: [...types, View.View, Kanban.Kanban],
|
|
65
|
+
onClientInitialized: ({ client }) =>
|
|
66
|
+
Effect.gen(function* () {
|
|
67
|
+
yield* Effect.promise(() => client.halo.createIdentity());
|
|
68
|
+
const space = yield* Effect.promise(() => client.spaces.create());
|
|
69
|
+
yield* Effect.promise(() => space.waitUntilReady());
|
|
70
|
+
yield* Effect.promise(() => onSpaceCreated?.(space) ?? Promise.resolve());
|
|
71
|
+
}),
|
|
72
|
+
}),
|
|
73
|
+
PreviewPlugin(),
|
|
74
|
+
SpacePlugin({}),
|
|
75
|
+
StorybookPlugin({}),
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
//
|
|
80
|
+
// Story components.
|
|
81
|
+
//
|
|
82
|
+
|
|
83
|
+
const DefaultComponent = () => {
|
|
84
|
+
const registry = useContext(RegistryContext);
|
|
48
85
|
const spaces = useSpaces();
|
|
49
86
|
const space = spaces[spaces.length - 1];
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
if (kanbans.length && !kanban) {
|
|
57
|
-
const kanban = kanbans[0];
|
|
58
|
-
setKanban(kanban);
|
|
59
|
-
}
|
|
60
|
-
}, [kanbans]);
|
|
61
|
-
|
|
62
|
-
useEffect(() => {
|
|
63
|
-
if (kanban?.cardView?.target && schema) {
|
|
64
|
-
const jsonSchema = Type.toJsonSchema(schema);
|
|
65
|
-
setProjection(new ViewProjection(jsonSchema, kanban.cardView.target));
|
|
66
|
-
}
|
|
67
|
-
// TODO(ZaymonFC): Is there a better way to get notified about deep changes in the json schema?
|
|
68
|
-
// @dmaretskyi? Once resolved, update in multiple places (e.g., storybooks).
|
|
69
|
-
}, [kanban?.cardView?.target, schema, JSON.stringify(schema ? Type.toJsonSchema(schema) : {})]);
|
|
70
|
-
|
|
71
|
-
const objects = useQuery(space, schema ? Filter.type(schema) : Filter.nothing());
|
|
87
|
+
const [object] = useQuery(space?.db, Filter.type(Kanban.Kanban));
|
|
88
|
+
const typename = object?.view.target?.query ? getTypenameFromQuery(object.view.target.query.ast) : undefined;
|
|
89
|
+
const schema = useSchema(space?.db, typename);
|
|
90
|
+
|
|
91
|
+
const objects = useQuery(space?.db, schema ? Filter.type(schema) : Filter.nothing());
|
|
72
92
|
const filteredObjects = useGlobalFilteredObjects(objects);
|
|
73
93
|
|
|
94
|
+
const projection = useProjectionModel(schema, object, registry);
|
|
74
95
|
const model = useKanbanModel({
|
|
75
|
-
|
|
76
|
-
schema,
|
|
96
|
+
object,
|
|
77
97
|
projection,
|
|
78
98
|
items: filteredObjects,
|
|
79
99
|
});
|
|
@@ -81,9 +101,9 @@ const StorybookKanban = () => {
|
|
|
81
101
|
const handleAddCard = useCallback(
|
|
82
102
|
(columnValue: string | undefined) => {
|
|
83
103
|
const path = model?.columnFieldPath;
|
|
84
|
-
if (space && schema && path) {
|
|
104
|
+
if (space && schema && Type.isObjectSchema(schema) && path) {
|
|
85
105
|
const card = Obj.make(schema, {
|
|
86
|
-
...
|
|
106
|
+
...createOrg(),
|
|
87
107
|
[path]: columnValue,
|
|
88
108
|
});
|
|
89
109
|
|
|
@@ -94,99 +114,173 @@ const StorybookKanban = () => {
|
|
|
94
114
|
[space, schema, model],
|
|
95
115
|
);
|
|
96
116
|
|
|
97
|
-
const handleRemoveCard = useCallback((card: { id: string }) => space
|
|
117
|
+
const handleRemoveCard = useCallback((card: { id: string }) => Obj.isObject(card) && space?.db.remove(card), [space]);
|
|
98
118
|
|
|
99
|
-
const
|
|
100
|
-
(
|
|
119
|
+
const handleUpdateQuery = useCallback(
|
|
120
|
+
(newQuery: QueryAST.Query) => {
|
|
101
121
|
invariant(schema);
|
|
102
122
|
invariant(Type.isMutable(schema));
|
|
103
|
-
invariant(
|
|
123
|
+
invariant(object.view.target);
|
|
104
124
|
|
|
105
|
-
schema.updateTypename(
|
|
106
|
-
|
|
125
|
+
schema.updateTypename(getTypenameFromQuery(newQuery));
|
|
126
|
+
Obj.change(object.view.target, (v) => {
|
|
127
|
+
v.query.ast = newQuery as Mutable<typeof newQuery>;
|
|
128
|
+
});
|
|
107
129
|
},
|
|
108
|
-
[
|
|
130
|
+
[object, schema],
|
|
109
131
|
);
|
|
110
132
|
|
|
111
|
-
|
|
133
|
+
const handleDeleteField = useCallback(
|
|
134
|
+
(fieldId: string) => {
|
|
135
|
+
if (schema && Type.isMutable(schema) && projection) {
|
|
136
|
+
projection.deleteFieldProjection(fieldId);
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
[schema, projection],
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
if (!schema || !object.view.target) {
|
|
112
143
|
return null;
|
|
113
144
|
}
|
|
114
145
|
|
|
115
146
|
return (
|
|
116
|
-
<div className='grow grid grid-cols-[1fr_350px]'>
|
|
117
|
-
{model ? <
|
|
118
|
-
<div className='flex flex-col bs-full border-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
/>
|
|
129
|
-
)}
|
|
130
|
-
<SyntaxHighlighter language='json' className='w-full text-xs'>
|
|
131
|
-
{JSON.stringify({ cardView: kanban.cardView?.target, cardSchema: schema }, null, 2)}
|
|
132
|
-
</SyntaxHighlighter>
|
|
147
|
+
<div className='grow grid grid-cols-[1fr_350px] overflow-hidden'>
|
|
148
|
+
{model ? <KanbanComponent model={model} onAddCard={handleAddCard} onRemoveCard={handleRemoveCard} /> : <div />}
|
|
149
|
+
<div className='flex flex-col bs-full overflow-hidden border-l border-separator'>
|
|
150
|
+
<ViewEditor
|
|
151
|
+
classNames='p-2'
|
|
152
|
+
registry={space?.db.schemaRegistry}
|
|
153
|
+
schema={schema}
|
|
154
|
+
view={object.view.target}
|
|
155
|
+
onQueryChanged={handleUpdateQuery}
|
|
156
|
+
onDelete={Type.isMutable(schema) ? handleDeleteField : undefined}
|
|
157
|
+
/>
|
|
158
|
+
<JsonFilter data={{ view: object.view.target, schema }} classNames='text-xs' />
|
|
133
159
|
</div>
|
|
134
160
|
</div>
|
|
135
161
|
);
|
|
136
162
|
};
|
|
137
163
|
|
|
138
|
-
type StoryProps = {
|
|
139
|
-
rows?: number;
|
|
140
|
-
};
|
|
141
|
-
|
|
142
164
|
//
|
|
143
165
|
// Story definitions.
|
|
144
166
|
//
|
|
145
167
|
|
|
146
|
-
const meta
|
|
168
|
+
const meta = {
|
|
147
169
|
title: 'plugins/plugin-kanban/Kanban',
|
|
148
|
-
component:
|
|
149
|
-
render: () => <
|
|
150
|
-
|
|
170
|
+
component: DefaultComponent,
|
|
171
|
+
render: () => <DefaultComponent />,
|
|
172
|
+
decorators: [withTheme()],
|
|
173
|
+
parameters: {
|
|
174
|
+
layout: 'fullscreen',
|
|
175
|
+
translations: [...translations, ...kanbanTranslations],
|
|
176
|
+
},
|
|
177
|
+
} satisfies Meta<typeof DefaultComponent>;
|
|
178
|
+
|
|
179
|
+
export default meta;
|
|
180
|
+
|
|
181
|
+
type Story = StoryObj<typeof meta>;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Default story using static runtime schema (immutable).
|
|
185
|
+
* Schema mutations are not allowed.
|
|
186
|
+
*/
|
|
187
|
+
export const Default: Story = {
|
|
151
188
|
decorators: [
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
space.db.add(kanban);
|
|
169
|
-
|
|
170
|
-
if (schema) {
|
|
171
|
-
// TODO(burdon): Replace with sdk/schema/testing.
|
|
172
|
-
Array.from({ length: 80 }).map(() => {
|
|
173
|
-
return space.db.add(Obj.make(schema, rollOrg()));
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
}),
|
|
178
|
-
StorybookLayoutPlugin(),
|
|
179
|
-
PreviewPlugin(),
|
|
180
|
-
SpacePlugin(),
|
|
181
|
-
IntentPlugin(),
|
|
182
|
-
SettingsPlugin(),
|
|
183
|
-
],
|
|
189
|
+
withKanbanPlugins({
|
|
190
|
+
types: [Organization.Organization, Person.Person],
|
|
191
|
+
onSpaceCreated: async (space) => {
|
|
192
|
+
const { view } = await View.makeFromDatabase({
|
|
193
|
+
db: space.db,
|
|
194
|
+
typename: Organization.Organization.typename,
|
|
195
|
+
pivotFieldName: 'status',
|
|
196
|
+
});
|
|
197
|
+
const kanban = Kanban.make({ view });
|
|
198
|
+
space.db.add(kanban);
|
|
199
|
+
|
|
200
|
+
// TODO(burdon): Replace with sdk/schema/testing.
|
|
201
|
+
Array.from({ length: 80 }).map(() => {
|
|
202
|
+
return space.db.add(Obj.make(Organization.Organization, createOrg()));
|
|
203
|
+
});
|
|
204
|
+
},
|
|
184
205
|
}),
|
|
185
206
|
],
|
|
207
|
+
play: async ({ canvasElement }) => {
|
|
208
|
+
const canvas = within(canvasElement);
|
|
209
|
+
|
|
210
|
+
// Wait for the kanban columns to render by finding the status tags.
|
|
211
|
+
// Organization.StatusOptions: prospect, qualified, active, commit, reject.
|
|
212
|
+
const activeTag = await canvas.findByText('Active', undefined, { timeout: 30_000 });
|
|
213
|
+
const prospectTag = await canvas.findByText('Prospect', undefined, { timeout: 10_000 });
|
|
214
|
+
const commitTag = await canvas.findByText('Commit', undefined, { timeout: 10_000 });
|
|
215
|
+
|
|
216
|
+
// Verify all expected columns are rendered.
|
|
217
|
+
await expect(activeTag).toBeTruthy();
|
|
218
|
+
await expect(prospectTag).toBeTruthy();
|
|
219
|
+
await expect(commitTag).toBeTruthy();
|
|
220
|
+
|
|
221
|
+
// Find the column containers.
|
|
222
|
+
const activeColumn = activeTag.closest('[data-dx-stack-item]') as HTMLElement;
|
|
223
|
+
const prospectColumn = prospectTag.closest('[data-dx-stack-item]') as HTMLElement;
|
|
224
|
+
await expect(activeColumn).toBeTruthy();
|
|
225
|
+
await expect(prospectColumn).toBeTruthy();
|
|
226
|
+
|
|
227
|
+
// Wait for cards to render in the columns.
|
|
228
|
+
// Cards have data-dx-item-id attribute from StackItem.Root.
|
|
229
|
+
const getColumnCards = (column: HTMLElement) =>
|
|
230
|
+
Array.from(column.querySelectorAll('[data-dx-item-id]')) as HTMLElement[];
|
|
231
|
+
|
|
232
|
+
await waitFor(() => expect(getColumnCards(activeColumn).length).toBeGreaterThan(0));
|
|
233
|
+
|
|
234
|
+
// Verify cards are distributed across columns.
|
|
235
|
+
const activeCards = getColumnCards(activeColumn);
|
|
236
|
+
const prospectCards = getColumnCards(prospectColumn);
|
|
237
|
+
await expect(activeCards.length).toBeGreaterThan(0);
|
|
238
|
+
await expect(prospectCards.length).toBeGreaterThan(0);
|
|
239
|
+
|
|
240
|
+
// Verify cards have drag handles (first button in toolbar).
|
|
241
|
+
const firstActiveCard = activeCards[0];
|
|
242
|
+
const buttons = firstActiveCard.querySelectorAll('button');
|
|
243
|
+
await expect(buttons.length).toBeGreaterThan(0);
|
|
244
|
+
|
|
245
|
+
// Verify the drop zone exists in each column.
|
|
246
|
+
const activeDropZone = activeColumn.querySelector('.kanban-drop');
|
|
247
|
+
const prospectDropZone = prospectColumn.querySelector('.kanban-drop');
|
|
248
|
+
await expect(activeDropZone).toBeTruthy();
|
|
249
|
+
await expect(prospectDropZone).toBeTruthy();
|
|
250
|
+
|
|
251
|
+
// TODO(wittjosiah): Get drag & drop tests working.
|
|
252
|
+
// See packages/apps/composer-app/src/playwright/stack.spec.ts for reference.
|
|
253
|
+
},
|
|
186
254
|
};
|
|
187
255
|
|
|
188
|
-
|
|
256
|
+
/**
|
|
257
|
+
* Story variant that uses a mutable database schema (EchoSchema).
|
|
258
|
+
* This allows testing schema mutations like adding/removing fields.
|
|
259
|
+
*/
|
|
260
|
+
// TODO(wittjosiah): Card previews (e.g., OrganizationCard) are type-specific and hard-coded.
|
|
261
|
+
// They don't use the projection to determine which fields to display, so deleting a field
|
|
262
|
+
// from the schema won't remove it from the card preview. To fix this, the type-specific
|
|
263
|
+
// cards in PreviewPlugin would need to accept and respect the projection prop.
|
|
264
|
+
export const MutableSchema: Story = {
|
|
265
|
+
decorators: [
|
|
266
|
+
withKanbanPlugins({
|
|
267
|
+
onSpaceCreated: async (space) => {
|
|
268
|
+
// Register schema in the database to make it mutable (EchoSchema).
|
|
269
|
+
const [schema] = await space.db.schemaRegistry.register([Organization.Organization]);
|
|
189
270
|
|
|
190
|
-
|
|
271
|
+
const { view } = await View.makeFromDatabase({
|
|
272
|
+
db: space.db,
|
|
273
|
+
typename: schema.typename,
|
|
274
|
+
pivotFieldName: 'status',
|
|
275
|
+
});
|
|
276
|
+
const kanban = Kanban.make({ view });
|
|
277
|
+
space.db.add(kanban);
|
|
191
278
|
|
|
192
|
-
|
|
279
|
+
// Create test data using the registered schema.
|
|
280
|
+
Array.from({ length: 80 }).map(() => {
|
|
281
|
+
return space.db.add(Obj.make(schema, createOrg()));
|
|
282
|
+
});
|
|
283
|
+
},
|
|
284
|
+
}),
|
|
285
|
+
],
|
|
286
|
+
};
|
|
@@ -2,68 +2,60 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
|
+
import React, { useCallback, useContext, useEffect, useState } from 'react';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
+
import { useCapabilities, useOperationInvoker } from '@dxos/app-framework/ui';
|
|
9
|
+
import { AppCapabilities } from '@dxos/app-toolkit';
|
|
10
|
+
import { type SurfaceComponentProps } from '@dxos/app-toolkit/ui';
|
|
8
11
|
import { Filter, Obj, Type } from '@dxos/echo';
|
|
9
|
-
import { EchoSchema, type TypedObject } from '@dxos/echo-schema';
|
|
10
12
|
import { useGlobalFilteredObjects } from '@dxos/plugin-search';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
13
|
+
import { useQuery } from '@dxos/react-client/echo';
|
|
14
|
+
import { Layout } from '@dxos/react-ui';
|
|
15
|
+
import { Kanban as KanbanComponent, useKanbanModel, useProjectionModel } from '@dxos/react-ui-kanban';
|
|
16
|
+
import { type Kanban } from '@dxos/react-ui-kanban/types';
|
|
17
|
+
import { getTypenameFromQuery } from '@dxos/schema';
|
|
16
18
|
|
|
17
|
-
import {
|
|
19
|
+
import { KanbanOperation } from '../types';
|
|
18
20
|
|
|
19
|
-
export
|
|
20
|
-
const client = useClient();
|
|
21
|
-
const [cardSchema, setCardSchema] = useState<TypedObject<any, any>>();
|
|
22
|
-
const [projection, setProjection] = useState<ViewProjection>();
|
|
23
|
-
const space = getSpace(kanban);
|
|
24
|
-
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
21
|
+
export type KanbanContainerProps = SurfaceComponentProps<Kanban.Kanban>;
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
23
|
+
export const KanbanContainer = ({ role, subject: object }: KanbanContainerProps) => {
|
|
24
|
+
const registry = useContext(RegistryContext);
|
|
25
|
+
const schemas = useCapabilities(AppCapabilities.Schema);
|
|
26
|
+
const [cardSchema, setCardSchema] = useState<Type.Obj.Any>();
|
|
27
|
+
const db = Obj.getDatabase(object);
|
|
28
|
+
const { invokePromise } = useOperationInvoker();
|
|
29
|
+
const typename = object.view.target?.query ? getTypenameFromQuery(object.view.target.query.ast) : undefined;
|
|
32
30
|
|
|
33
31
|
useEffect(() => {
|
|
34
|
-
const
|
|
35
|
-
const staticSchema = client.graph.schemaRegistry.schemas.find((schema) => Type.getTypename(schema) === typename);
|
|
32
|
+
const staticSchema = schemas.flat().find((schema) => Type.getTypename(schema) === typename);
|
|
36
33
|
if (staticSchema) {
|
|
37
|
-
|
|
34
|
+
// NOTE: Use functional update to prevent React from calling the schema as a function.
|
|
35
|
+
setCardSchema(() => staticSchema);
|
|
38
36
|
}
|
|
39
|
-
if (!staticSchema && typename &&
|
|
40
|
-
const query =
|
|
37
|
+
if (!staticSchema && typename && db) {
|
|
38
|
+
const query = db.schemaRegistry.query({ typename });
|
|
41
39
|
const unsubscribe = query.subscribe(
|
|
42
40
|
() => {
|
|
43
41
|
const [schema] = query.results;
|
|
44
42
|
if (schema) {
|
|
45
|
-
|
|
43
|
+
// NOTE: Use functional update to prevent React from calling the schema as a function.
|
|
44
|
+
setCardSchema(() => schema);
|
|
46
45
|
}
|
|
47
46
|
},
|
|
48
47
|
{ fire: true },
|
|
49
48
|
);
|
|
50
49
|
return unsubscribe;
|
|
51
50
|
}
|
|
52
|
-
}, [
|
|
53
|
-
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
if (kanban.cardView?.target && jsonSchema) {
|
|
56
|
-
setProjection(new ViewProjection(jsonSchema, kanban.cardView.target));
|
|
57
|
-
}
|
|
58
|
-
// TODO(ZaymonFC): Is there a better way to get notified about deep changes in the json schema?
|
|
59
|
-
}, [kanban.cardView?.target, JSON.stringify(jsonSchema)]);
|
|
51
|
+
}, [schemas, db, typename]);
|
|
60
52
|
|
|
61
|
-
const objects = useQuery(
|
|
53
|
+
const objects = useQuery(db, cardSchema ? Filter.type(cardSchema) : Filter.nothing());
|
|
62
54
|
const filteredObjects = useGlobalFilteredObjects(objects);
|
|
63
55
|
|
|
56
|
+
const projection = useProjectionModel(cardSchema, object, registry);
|
|
64
57
|
const model = useKanbanModel({
|
|
65
|
-
|
|
66
|
-
schema: cardSchema,
|
|
58
|
+
object,
|
|
67
59
|
projection,
|
|
68
60
|
items: filteredObjects,
|
|
69
61
|
});
|
|
@@ -71,25 +63,25 @@ export const KanbanContainer = ({ kanban }: { kanban: KanbanType; role: string }
|
|
|
71
63
|
const handleAddCard = useCallback(
|
|
72
64
|
(columnValue: string | undefined) => {
|
|
73
65
|
const path = model?.columnFieldPath;
|
|
74
|
-
if (
|
|
66
|
+
if (db && cardSchema && path) {
|
|
75
67
|
const card = Obj.make(cardSchema, { [path]: columnValue });
|
|
76
|
-
|
|
68
|
+
db.add(card);
|
|
77
69
|
return card.id;
|
|
78
70
|
}
|
|
79
71
|
},
|
|
80
|
-
[
|
|
72
|
+
[db, cardSchema, model],
|
|
81
73
|
);
|
|
82
74
|
|
|
83
75
|
const handleRemoveCard = useCallback(
|
|
84
76
|
(card: { id: string }) => {
|
|
85
|
-
void
|
|
77
|
+
void invokePromise(KanbanOperation.DeleteCard, { card });
|
|
86
78
|
},
|
|
87
|
-
[
|
|
79
|
+
[invokePromise],
|
|
88
80
|
);
|
|
89
81
|
|
|
90
82
|
return (
|
|
91
|
-
<
|
|
92
|
-
{model && <
|
|
93
|
-
</
|
|
83
|
+
<Layout.Main role={role}>
|
|
84
|
+
{model && <KanbanComponent model={model} onAddCard={handleAddCard} onRemoveCard={handleRemoveCard} />}
|
|
85
|
+
</Layout.Main>
|
|
94
86
|
);
|
|
95
87
|
};
|