@dxos/plugin-automation 0.8.4-main.fd6878d → 0.8.4-main.fffef41
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/AutomationPanel-7OECLR5N.mjs +11 -0
- package/dist/lib/browser/AutomationSettings-KCZISXI6.mjs +68 -0
- package/dist/lib/browser/AutomationSettings-KCZISXI6.mjs.map +7 -0
- package/dist/lib/browser/FunctionsContainer-MIWEISRR.mjs +151 -0
- package/dist/lib/browser/FunctionsContainer-MIWEISRR.mjs.map +7 -0
- package/dist/lib/browser/{FunctionsPanel-I443Y6KB.mjs → FunctionsPanel-CRW6SJUN.mjs} +3 -3
- package/dist/lib/browser/{app-graph-builder-4OFKIRAI.mjs → app-graph-builder-W7LLC6XW.mjs} +12 -11
- package/dist/lib/browser/app-graph-builder-W7LLC6XW.mjs.map +7 -0
- package/dist/lib/browser/chunk-EPEXQP45.mjs +14 -0
- package/dist/lib/browser/chunk-EPEXQP45.mjs.map +7 -0
- package/dist/lib/browser/{chunk-7EE4SA6M.mjs → chunk-JW7XSPYW.mjs} +69 -32
- package/dist/lib/browser/chunk-JW7XSPYW.mjs.map +7 -0
- package/dist/lib/browser/chunk-LZQFZO3B.mjs +17 -0
- package/dist/lib/browser/chunk-LZQFZO3B.mjs.map +7 -0
- package/dist/lib/browser/chunk-NAPXRXTY.mjs +100 -0
- package/dist/lib/browser/chunk-NAPXRXTY.mjs.map +7 -0
- package/dist/lib/browser/{chunk-OX6OW6XP.mjs → chunk-QKFBHAGN.mjs} +71 -34
- package/dist/lib/browser/chunk-QKFBHAGN.mjs.map +7 -0
- package/dist/lib/browser/{chunk-Z5DT4MHW.mjs → chunk-TWWFNOIR.mjs} +30 -15
- package/dist/lib/browser/chunk-TWWFNOIR.mjs.map +7 -0
- package/dist/lib/browser/chunk-XAKZ4ANY.mjs +15 -0
- package/dist/lib/browser/chunk-XAKZ4ANY.mjs.map +7 -0
- package/dist/lib/browser/{chunk-HN7OHFCB.mjs → chunk-YBPJCY3F.mjs} +3 -3
- package/dist/lib/browser/chunk-YBPJCY3F.mjs.map +7 -0
- package/dist/lib/browser/compute-runtime-EIQTHJFZ.mjs +113 -0
- package/dist/lib/browser/compute-runtime-EIQTHJFZ.mjs.map +7 -0
- package/dist/lib/browser/hooks/index.mjs +13 -0
- package/dist/lib/browser/index.mjs +47 -18
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/{intent-resolver-YZP6RKTR.mjs → intent-resolver-5HR7M7T6.mjs} +14 -13
- package/dist/lib/browser/intent-resolver-5HR7M7T6.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-WNOIIT4O.mjs → react-surface-YQW7WCFW.mjs} +20 -20
- package/dist/lib/browser/react-surface-YQW7WCFW.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +2 -2
- package/dist/lib/node-esm/{AutomationPanel-5EQQF5S2.mjs → AutomationPanel-HCVFNHGQ.mjs} +4 -4
- package/dist/lib/node-esm/AutomationSettings-UUUPVNUJ.mjs +69 -0
- package/dist/lib/node-esm/AutomationSettings-UUUPVNUJ.mjs.map +7 -0
- package/dist/lib/node-esm/FunctionsContainer-6OB3JN5O.mjs +152 -0
- package/dist/lib/node-esm/FunctionsContainer-6OB3JN5O.mjs.map +7 -0
- package/dist/lib/node-esm/{FunctionsPanel-ELINCXPW.mjs → FunctionsPanel-RVVCS6VH.mjs} +3 -3
- package/dist/lib/node-esm/FunctionsPanel-RVVCS6VH.mjs.map +7 -0
- package/dist/lib/node-esm/{app-graph-builder-555IHYOB.mjs → app-graph-builder-SLQOO7GH.mjs} +12 -11
- package/dist/lib/node-esm/app-graph-builder-SLQOO7GH.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-GHRG4NQV.mjs → chunk-6YRKST6M.mjs} +71 -34
- package/dist/lib/node-esm/chunk-6YRKST6M.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-CEVIVRTY.mjs +19 -0
- package/dist/lib/node-esm/chunk-CEVIVRTY.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-CPP35BE6.mjs +16 -0
- package/dist/lib/node-esm/chunk-CPP35BE6.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-OEZNHUL2.mjs → chunk-ECJKIUBO.mjs} +3 -3
- package/dist/lib/node-esm/chunk-ECJKIUBO.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-KB7NFEYY.mjs +16 -0
- package/dist/lib/node-esm/chunk-KB7NFEYY.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-PICJ2REN.mjs +101 -0
- package/dist/lib/node-esm/chunk-PICJ2REN.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-CX2AILIS.mjs → chunk-RVK52XGK.mjs} +30 -15
- package/dist/lib/node-esm/chunk-RVK52XGK.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-YPUO4IVX.mjs → chunk-W76WUTZY.mjs} +69 -32
- package/dist/lib/node-esm/chunk-W76WUTZY.mjs.map +7 -0
- package/dist/lib/node-esm/compute-runtime-URROOC34.mjs +114 -0
- package/dist/lib/node-esm/compute-runtime-URROOC34.mjs.map +7 -0
- package/dist/lib/node-esm/hooks/index.mjs +14 -0
- package/dist/lib/node-esm/hooks/index.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +47 -18
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/{intent-resolver-TSLQE27W.mjs → intent-resolver-KDRYB5BC.mjs} +14 -13
- package/dist/lib/node-esm/intent-resolver-KDRYB5BC.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-K6MQFIAS.mjs → react-surface-NNHYNBO6.mjs} +20 -20
- package/dist/lib/node-esm/react-surface-NNHYNBO6.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +2 -2
- package/dist/types/src/AutomationPlugin.d.ts +1 -1
- package/dist/types/src/AutomationPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/capabilities.d.ts +20 -0
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -0
- package/dist/types/src/capabilities/compute-runtime.d.ts +5 -0
- package/dist/types/src/capabilities/compute-runtime.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +5 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +6 -5
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -1
- package/dist/types/src/components/AutomationPanel/AutomationPanel.stories.d.ts +48 -4
- package/dist/types/src/components/AutomationPanel/AutomationPanel.stories.d.ts.map +1 -1
- package/dist/types/src/components/AutomationSettings.d.ts +5 -0
- package/dist/types/src/components/AutomationSettings.d.ts.map +1 -0
- package/dist/types/src/components/FunctionsContainer.d.ts.map +1 -1
- package/dist/types/src/components/FunctionsPanel/FunctionsPanel.d.ts.map +1 -1
- package/dist/types/src/components/FunctionsRegistry/FunctionsRegistry.d.ts +8 -0
- package/dist/types/src/components/FunctionsRegistry/FunctionsRegistry.d.ts.map +1 -0
- package/dist/types/src/components/FunctionsRegistry/index.d.ts +2 -0
- package/dist/types/src/components/FunctionsRegistry/index.d.ts.map +1 -0
- package/dist/types/src/components/TriggerEditor/FunctionInputEditor.d.ts +2 -2
- package/dist/types/src/components/TriggerEditor/FunctionInputEditor.d.ts.map +1 -1
- package/dist/types/src/components/TriggerEditor/SpecSelector.d.ts.map +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts +7 -5
- package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts.map +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts +49 -4
- package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TriggerSettings.d.ts +6 -0
- package/dist/types/src/components/TriggerSettings.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +2 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/events.d.ts +4 -0
- package/dist/types/src/events.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +3 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/useComputeRuntimeCallback.d.ts +12 -0
- package/dist/types/src/hooks/useComputeRuntimeCallback.d.ts.map +1 -0
- package/dist/types/src/hooks/useTriggerRuntimeControls.d.ts +11 -0
- package/dist/types/src/hooks/useTriggerRuntimeControls.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +0 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +5 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +1 -1
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +61 -38
- package/src/AutomationPlugin.tsx +36 -30
- package/src/capabilities/app-graph-builder.ts +14 -13
- package/src/capabilities/capabilities.ts +41 -0
- package/src/capabilities/compute-runtime.ts +127 -0
- package/src/capabilities/index.ts +3 -0
- package/src/capabilities/intent-resolver.ts +8 -8
- package/src/capabilities/react-surface.tsx +15 -15
- package/src/components/AutomationPanel/AutomationPanel.stories.tsx +14 -16
- package/src/components/AutomationPanel/AutomationPanel.tsx +104 -52
- package/src/components/AutomationSettings.tsx +30 -0
- package/src/components/FunctionsContainer.tsx +17 -13
- package/src/components/FunctionsPanel/FunctionsPanel.tsx +35 -16
- package/src/components/FunctionsRegistry/FunctionsRegistry.tsx +135 -0
- package/src/components/FunctionsRegistry/index.ts +5 -0
- package/src/components/TriggerEditor/FunctionInputEditor.tsx +10 -4
- package/src/components/TriggerEditor/SpecSelector.tsx +22 -16
- package/src/components/TriggerEditor/TriggerEditor.stories.tsx +69 -27
- package/src/components/TriggerEditor/TriggerEditor.tsx +44 -24
- package/src/components/TriggerSettings.tsx +25 -0
- package/src/components/index.ts +1 -1
- package/src/events.ts +11 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/useComputeRuntimeCallback.ts +68 -0
- package/src/hooks/useTriggerRuntimeControls.ts +53 -0
- package/src/index.ts +3 -0
- package/src/meta.ts +6 -5
- package/src/testing/test-functions.ts +1 -1
- package/src/translations.ts +7 -0
- package/src/types/schema.ts +1 -1
- package/dist/lib/browser/AutomationContainer-5UYKI7EG.mjs +0 -38
- package/dist/lib/browser/AutomationContainer-5UYKI7EG.mjs.map +0 -7
- package/dist/lib/browser/AutomationPanel-YYERBNYJ.mjs +0 -11
- package/dist/lib/browser/FunctionsContainer-VOGKIPHA.mjs +0 -39
- package/dist/lib/browser/FunctionsContainer-VOGKIPHA.mjs.map +0 -7
- package/dist/lib/browser/app-graph-builder-4OFKIRAI.mjs.map +0 -7
- package/dist/lib/browser/chunk-7EE4SA6M.mjs.map +0 -7
- package/dist/lib/browser/chunk-CHENFUQ6.mjs +0 -14
- package/dist/lib/browser/chunk-CHENFUQ6.mjs.map +0 -7
- package/dist/lib/browser/chunk-GW5U2DGT.mjs +0 -15
- package/dist/lib/browser/chunk-GW5U2DGT.mjs.map +0 -7
- package/dist/lib/browser/chunk-HN7OHFCB.mjs.map +0 -7
- package/dist/lib/browser/chunk-OX6OW6XP.mjs.map +0 -7
- package/dist/lib/browser/chunk-Z5DT4MHW.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-YZP6RKTR.mjs.map +0 -7
- package/dist/lib/browser/react-surface-WNOIIT4O.mjs.map +0 -7
- package/dist/lib/node-esm/AutomationContainer-EZMY6DTD.mjs +0 -39
- package/dist/lib/node-esm/AutomationContainer-EZMY6DTD.mjs.map +0 -7
- package/dist/lib/node-esm/FunctionsContainer-IHLMLXHH.mjs +0 -40
- package/dist/lib/node-esm/FunctionsContainer-IHLMLXHH.mjs.map +0 -7
- package/dist/lib/node-esm/app-graph-builder-555IHYOB.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-CX2AILIS.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-D4VWZD53.mjs +0 -16
- package/dist/lib/node-esm/chunk-D4VWZD53.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-GHRG4NQV.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NK5N3QKD.mjs +0 -17
- package/dist/lib/node-esm/chunk-NK5N3QKD.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OEZNHUL2.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YPUO4IVX.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-TSLQE27W.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-K6MQFIAS.mjs.map +0 -7
- package/dist/types/src/components/AutomationContainer.d.ts +0 -5
- package/dist/types/src/components/AutomationContainer.d.ts.map +0 -1
- package/src/components/AutomationContainer.tsx +0 -31
- /package/dist/lib/browser/{AutomationPanel-YYERBNYJ.mjs.map → AutomationPanel-7OECLR5N.mjs.map} +0 -0
- /package/dist/lib/browser/{FunctionsPanel-I443Y6KB.mjs.map → FunctionsPanel-CRW6SJUN.mjs.map} +0 -0
- /package/dist/lib/{node-esm/AutomationPanel-5EQQF5S2.mjs.map → browser/hooks/index.mjs.map} +0 -0
- /package/dist/lib/node-esm/{FunctionsPanel-ELINCXPW.mjs.map → AutomationPanel-HCVFNHGQ.mjs.map} +0 -0
|
@@ -2,60 +2,62 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
ScriptType,
|
|
15
|
-
TriggerKind,
|
|
16
|
-
} from '@dxos/functions';
|
|
5
|
+
import * as Array from 'effect/Array';
|
|
6
|
+
import * as EFn from 'effect/Function';
|
|
7
|
+
import * as Match from 'effect/Match';
|
|
8
|
+
import * as Schema from 'effect/Schema';
|
|
9
|
+
import React, { useMemo, useState } from 'react';
|
|
10
|
+
|
|
11
|
+
import { Filter, Obj, Tag } from '@dxos/echo';
|
|
12
|
+
import { Function, Script, Trigger } from '@dxos/functions';
|
|
13
|
+
import { useTypeOptions } from '@dxos/plugin-space';
|
|
17
14
|
import { type Client, useClient } from '@dxos/react-client';
|
|
18
15
|
import { type Space, getSpace, useQuery } from '@dxos/react-client/echo';
|
|
19
|
-
import { Clipboard, IconButton, Input, Separator, useTranslation } from '@dxos/react-ui';
|
|
16
|
+
import { Clipboard, IconButton, Input, Separator, type ThemedClassName, useTranslation } from '@dxos/react-ui';
|
|
20
17
|
import { ControlItem, controlItemClasses } from '@dxos/react-ui-form';
|
|
21
18
|
import { List } from '@dxos/react-ui-list';
|
|
22
19
|
import { ghostHover, mx } from '@dxos/react-ui-theme';
|
|
20
|
+
import { View } from '@dxos/schema';
|
|
21
|
+
import { Project } from '@dxos/types';
|
|
23
22
|
|
|
24
|
-
import {
|
|
23
|
+
import { meta } from '../../meta';
|
|
25
24
|
import { TriggerEditor, type TriggerEditorProps } from '../TriggerEditor';
|
|
26
25
|
|
|
27
26
|
const grid = 'grid grid-cols-[40px_1fr_32px] min-bs-[2.5rem]';
|
|
28
27
|
|
|
29
|
-
export type AutomationPanelProps = {
|
|
28
|
+
export type AutomationPanelProps = ThemedClassName<{
|
|
30
29
|
space: Space;
|
|
31
30
|
object?: Obj.Any;
|
|
32
|
-
initialTrigger?:
|
|
31
|
+
initialTrigger?: Trigger.Trigger;
|
|
33
32
|
onDone?: () => void;
|
|
34
|
-
}
|
|
33
|
+
}>;
|
|
35
34
|
|
|
36
35
|
// TODO(burdon): Factor out common layout with ViewEditor.
|
|
37
|
-
export const AutomationPanel = ({ space, object, initialTrigger, onDone }: AutomationPanelProps) => {
|
|
38
|
-
const { t } = useTranslation(
|
|
36
|
+
export const AutomationPanel = ({ classNames, space, object, initialTrigger, onDone }: AutomationPanelProps) => {
|
|
37
|
+
const { t } = useTranslation(meta.id);
|
|
39
38
|
const client = useClient();
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
const functions = useQuery(space, Filter.type(Function.Function));
|
|
40
|
+
const triggers = useQuery(space, Filter.type(Trigger.Trigger));
|
|
41
|
+
const filteredTriggers = useMemo(() => {
|
|
42
|
+
return object ? triggers.filter(triggerMatch(object)) : triggers;
|
|
43
|
+
}, [object, triggers]);
|
|
44
|
+
const tags = useQuery(space, Filter.type(Tag.Tag));
|
|
45
|
+
const types = useTypeOptions({ space, annotation: ['dynamic', 'limited-static', 'object-form'] });
|
|
46
|
+
|
|
47
|
+
const [trigger, setTrigger] = useState<Trigger.Trigger | undefined>(initialTrigger);
|
|
48
|
+
const [selected, setSelected] = useState<Trigger.Trigger>();
|
|
49
|
+
|
|
50
|
+
const handleSelect = (trigger: Trigger.Trigger) => {
|
|
51
|
+
setTrigger(trigger);
|
|
50
52
|
setSelected(trigger);
|
|
51
53
|
};
|
|
52
54
|
|
|
53
55
|
const handleAdd = () => {
|
|
54
|
-
setTrigger(
|
|
56
|
+
setTrigger(Trigger.make({}));
|
|
55
57
|
setSelected(undefined);
|
|
56
58
|
};
|
|
57
59
|
|
|
58
|
-
const handleDelete = (trigger:
|
|
60
|
+
const handleDelete = (trigger: Trigger.Trigger) => {
|
|
59
61
|
space.db.remove(trigger);
|
|
60
62
|
setTrigger(undefined);
|
|
61
63
|
setSelected(undefined);
|
|
@@ -65,7 +67,7 @@ export const AutomationPanel = ({ space, object, initialTrigger, onDone }: Autom
|
|
|
65
67
|
if (selected) {
|
|
66
68
|
Object.assign(selected, trigger);
|
|
67
69
|
} else {
|
|
68
|
-
space.db.add(
|
|
70
|
+
space.db.add(Trigger.make(trigger));
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
setTrigger(undefined);
|
|
@@ -81,24 +83,36 @@ export const AutomationPanel = ({ space, object, initialTrigger, onDone }: Autom
|
|
|
81
83
|
if (trigger) {
|
|
82
84
|
return (
|
|
83
85
|
<ControlItem title={t('trigger editor title')}>
|
|
84
|
-
<TriggerEditor
|
|
86
|
+
<TriggerEditor
|
|
87
|
+
space={space}
|
|
88
|
+
trigger={trigger}
|
|
89
|
+
readonlySpec={Boolean(object)}
|
|
90
|
+
tags={tags}
|
|
91
|
+
types={types}
|
|
92
|
+
onSave={handleSave}
|
|
93
|
+
onCancel={handleCancel}
|
|
94
|
+
/>
|
|
85
95
|
</ControlItem>
|
|
86
96
|
);
|
|
87
97
|
}
|
|
88
98
|
|
|
89
99
|
return (
|
|
90
|
-
<div className={controlItemClasses}>
|
|
91
|
-
{
|
|
92
|
-
<List.Root<
|
|
93
|
-
{
|
|
94
|
-
|
|
95
|
-
|
|
100
|
+
<div className={mx(controlItemClasses, classNames)}>
|
|
101
|
+
{filteredTriggers.length > 0 && (
|
|
102
|
+
<List.Root<Trigger.Trigger>
|
|
103
|
+
items={filteredTriggers}
|
|
104
|
+
isItem={Schema.is(Trigger.Trigger)}
|
|
105
|
+
getId={(field) => field.id}
|
|
106
|
+
>
|
|
107
|
+
{({ items: filteredTriggers }) => (
|
|
108
|
+
<div role='list' className='flex flex-col is-full'>
|
|
109
|
+
{filteredTriggers?.map((trigger) => {
|
|
96
110
|
const copyAction = getCopyAction(client, trigger);
|
|
97
111
|
return (
|
|
98
|
-
<List.Item<
|
|
112
|
+
<List.Item<Trigger.Trigger>
|
|
99
113
|
key={trigger.id}
|
|
100
114
|
item={trigger}
|
|
101
|
-
classNames={mx(grid, ghostHover, 'items-center', '
|
|
115
|
+
classNames={mx(grid, ghostHover, 'items-center', 'pli-2')}
|
|
102
116
|
>
|
|
103
117
|
<Input.Root>
|
|
104
118
|
<Input.Switch
|
|
@@ -109,10 +123,10 @@ export const AutomationPanel = ({ space, object, initialTrigger, onDone }: Autom
|
|
|
109
123
|
|
|
110
124
|
<div className={'flex'}>
|
|
111
125
|
<List.ItemTitle
|
|
112
|
-
classNames='
|
|
126
|
+
classNames='pli-1 cursor-pointer is-0 shrink truncate'
|
|
113
127
|
onClick={() => handleSelect(trigger)}
|
|
114
128
|
>
|
|
115
|
-
{getFunctionName(
|
|
129
|
+
{getFunctionName(functions, trigger) ?? '∅'}
|
|
116
130
|
</List.ItemTitle>
|
|
117
131
|
|
|
118
132
|
{/* TODO: a better way to expose copy action */}
|
|
@@ -132,25 +146,25 @@ export const AutomationPanel = ({ space, object, initialTrigger, onDone }: Autom
|
|
|
132
146
|
)}
|
|
133
147
|
</List.Root>
|
|
134
148
|
)}
|
|
135
|
-
{
|
|
149
|
+
{filteredTriggers.length > 0 && <Separator classNames='mlb-4' />}
|
|
136
150
|
<IconButton icon='ph--plus--regular' label={t('new trigger label')} onClick={handleAdd} />
|
|
137
151
|
</div>
|
|
138
152
|
);
|
|
139
153
|
};
|
|
140
154
|
|
|
141
|
-
const getCopyAction = (client: Client, trigger:
|
|
142
|
-
if (trigger?.spec?.kind ===
|
|
155
|
+
const getCopyAction = (client: Client, trigger: Trigger.Trigger | undefined) => {
|
|
156
|
+
if (trigger?.spec?.kind === 'email') {
|
|
143
157
|
return { translationKey: 'trigger copy email', contentProvider: () => `${getSpace(trigger)!.id}@dxos.network` };
|
|
144
158
|
}
|
|
145
159
|
|
|
146
|
-
if (trigger?.spec?.kind ===
|
|
160
|
+
if (trigger?.spec?.kind === 'webhook') {
|
|
147
161
|
return { translationKey: 'trigger copy url', contentProvider: () => getWebhookUrl(client, trigger) };
|
|
148
162
|
}
|
|
149
163
|
|
|
150
164
|
return undefined;
|
|
151
165
|
};
|
|
152
166
|
|
|
153
|
-
const getWebhookUrl = (client: Client, trigger:
|
|
167
|
+
const getWebhookUrl = (client: Client, trigger: Trigger.Trigger) => {
|
|
154
168
|
const spaceId = getSpace(trigger)!.id;
|
|
155
169
|
const edgeUrl = new URL(client.config.values.runtime!.services!.edge!.url!);
|
|
156
170
|
const isSecure = edgeUrl.protocol.startsWith('https') || edgeUrl.protocol.startsWith('wss');
|
|
@@ -158,14 +172,52 @@ const getWebhookUrl = (client: Client, trigger: FunctionTrigger) => {
|
|
|
158
172
|
return new URL(`/webhook/${spaceId}:${trigger.id}`, edgeUrl).toString();
|
|
159
173
|
};
|
|
160
174
|
|
|
161
|
-
const getFunctionName = (
|
|
175
|
+
const getFunctionName = (functions: Function.Function[], trigger: Trigger.Trigger) => {
|
|
162
176
|
// TODO(wittjosiah): Truncation should be done in the UI.
|
|
163
177
|
// Warning that the List component is currently a can of worms.
|
|
164
178
|
const shortId = trigger.function && `${trigger.function.dxn.toString().slice(0, 16)}…`;
|
|
165
179
|
const functionObject = functions.find((fn) => fn === trigger.function?.target);
|
|
166
|
-
|
|
167
|
-
|
|
180
|
+
return functionObject?.name ?? shortId;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const scriptMatch = (script: Script.Script) => (trigger: Trigger.Trigger) => {
|
|
184
|
+
const fn = trigger.function?.target;
|
|
185
|
+
if (!Obj.instanceOf(Function.Function, fn)) {
|
|
186
|
+
return false;
|
|
168
187
|
}
|
|
169
188
|
|
|
170
|
-
return
|
|
189
|
+
return fn.source?.target === script;
|
|
171
190
|
};
|
|
191
|
+
|
|
192
|
+
const projectMatch = (project: Project.Project) => {
|
|
193
|
+
const viewQueries = EFn.pipe(
|
|
194
|
+
project.collections,
|
|
195
|
+
Array.map((collection) => collection.target),
|
|
196
|
+
Array.filter(Schema.is(View.View)),
|
|
197
|
+
Array.map((view) => Obj.getSnapshot(view).query.ast),
|
|
198
|
+
Array.map((ast) => JSON.stringify(ast)),
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
return (trigger: Trigger.Trigger) => {
|
|
202
|
+
const spec = Obj.getSnapshot(trigger).spec;
|
|
203
|
+
if (spec?.kind !== 'subscription') {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// TODO(wittjosiah): Implement better way of comparing query ASTs.
|
|
208
|
+
return viewQueries.some((query) => JSON.stringify(spec.query) === query);
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const triggerMatch = Match.type<Obj.Any>().pipe(
|
|
213
|
+
Match.withReturnType<(trigger: Trigger.Trigger) => boolean>(),
|
|
214
|
+
Match.when(
|
|
215
|
+
(obj) => Obj.instanceOf(Script.Script, obj),
|
|
216
|
+
(obj) => scriptMatch(obj),
|
|
217
|
+
),
|
|
218
|
+
Match.when(
|
|
219
|
+
(obj) => Obj.instanceOf(Project.Project, obj),
|
|
220
|
+
(obj) => projectMatch(obj),
|
|
221
|
+
),
|
|
222
|
+
Match.orElse((_obj) => () => true),
|
|
223
|
+
);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
import { useTranslation } from '@dxos/react-ui';
|
|
8
|
+
import { ControlPage, ControlSection } from '@dxos/react-ui-form';
|
|
9
|
+
|
|
10
|
+
import { meta } from '../meta';
|
|
11
|
+
|
|
12
|
+
import { AutomationPanel, type AutomationPanelProps } from './AutomationPanel';
|
|
13
|
+
import { TriggersSettings } from './TriggerSettings';
|
|
14
|
+
|
|
15
|
+
export const AutomationSettings = (props: AutomationPanelProps) => {
|
|
16
|
+
const { t } = useTranslation(meta.id);
|
|
17
|
+
return (
|
|
18
|
+
<ControlPage>
|
|
19
|
+
<ControlSection
|
|
20
|
+
title={t('automation verbose label', { ns: meta.id })}
|
|
21
|
+
description={t('automation description', { ns: meta.id })}
|
|
22
|
+
>
|
|
23
|
+
<AutomationPanel {...props} />
|
|
24
|
+
<TriggersSettings space={props.space} />
|
|
25
|
+
</ControlSection>
|
|
26
|
+
</ControlPage>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default AutomationSettings;
|
|
@@ -7,25 +7,29 @@ import React from 'react';
|
|
|
7
7
|
import { type Space } from '@dxos/react-client/echo';
|
|
8
8
|
import { useTranslation } from '@dxos/react-ui';
|
|
9
9
|
import { ControlPage, ControlSection } from '@dxos/react-ui-form';
|
|
10
|
-
import { StackItem } from '@dxos/react-ui-stack';
|
|
11
10
|
|
|
12
|
-
import {
|
|
11
|
+
import { meta } from '../meta';
|
|
13
12
|
|
|
14
13
|
import { FunctionsPanel } from './FunctionsPanel';
|
|
14
|
+
import { FunctionsRegistry } from './FunctionsRegistry';
|
|
15
15
|
|
|
16
16
|
export const FunctionsContainer = ({ space }: { space: Space }) => {
|
|
17
|
-
const { t } = useTranslation(
|
|
17
|
+
const { t } = useTranslation(meta.id);
|
|
18
18
|
return (
|
|
19
|
-
<
|
|
20
|
-
<
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
<ControlPage>
|
|
20
|
+
<ControlSection
|
|
21
|
+
title={t('functions verbose label', { ns: meta.id })}
|
|
22
|
+
description={t('functions description', { ns: meta.id })}
|
|
23
|
+
>
|
|
24
|
+
<FunctionsPanel space={space} />
|
|
25
|
+
</ControlSection>
|
|
26
|
+
<ControlSection
|
|
27
|
+
title={t('functions registry verbose label', { ns: meta.id })}
|
|
28
|
+
description={t('functions registry description', { ns: meta.id })}
|
|
29
|
+
>
|
|
30
|
+
<FunctionsRegistry space={space} />
|
|
31
|
+
</ControlSection>
|
|
32
|
+
</ControlPage>
|
|
29
33
|
);
|
|
30
34
|
};
|
|
31
35
|
|
|
@@ -2,18 +2,21 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
import React, { useCallback, useMemo } from 'react';
|
|
7
7
|
|
|
8
|
-
import { LayoutAction, createIntent
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
8
|
+
import { LayoutAction, createIntent } from '@dxos/app-framework';
|
|
9
|
+
import { useIntentDispatcher } from '@dxos/app-framework/react';
|
|
10
|
+
import { Obj } from '@dxos/echo';
|
|
11
|
+
import { Function, Script } from '@dxos/functions';
|
|
12
|
+
import { SpaceAction } from '@dxos/plugin-space/types';
|
|
13
|
+
import { Filter, type Space, useQuery } from '@dxos/react-client/echo';
|
|
14
|
+
import { Button, IconButton, useTranslation } from '@dxos/react-ui';
|
|
12
15
|
import { controlItemClasses } from '@dxos/react-ui-form';
|
|
13
16
|
import { List } from '@dxos/react-ui-list';
|
|
14
17
|
import { ghostHover, mx } from '@dxos/react-ui-theme';
|
|
15
18
|
|
|
16
|
-
import {
|
|
19
|
+
import { meta } from '../../meta';
|
|
17
20
|
|
|
18
21
|
const grid = 'grid grid-cols-[1fr_auto] min-bs-[2.5rem]';
|
|
19
22
|
|
|
@@ -22,9 +25,9 @@ export type FunctionsPanelProps = {
|
|
|
22
25
|
};
|
|
23
26
|
|
|
24
27
|
export const FunctionsPanel = ({ space }: FunctionsPanelProps) => {
|
|
25
|
-
const { t } = useTranslation(
|
|
26
|
-
const functions = useQuery(space, Filter.type(
|
|
27
|
-
const scripts = useQuery(space, Filter.type(
|
|
28
|
+
const { t } = useTranslation(meta.id);
|
|
29
|
+
const functions = useQuery(space, Filter.type(Function.Function));
|
|
30
|
+
const scripts = useQuery(space, Filter.type(Script.Script));
|
|
28
31
|
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
29
32
|
|
|
30
33
|
const functionToScriptMap = useMemo(
|
|
@@ -40,13 +43,13 @@ export const FunctionsPanel = ({ space }: FunctionsPanelProps) => {
|
|
|
40
43
|
}
|
|
41
44
|
return map;
|
|
42
45
|
},
|
|
43
|
-
{} as Record<string,
|
|
46
|
+
{} as Record<string, Script.Script>,
|
|
44
47
|
),
|
|
45
48
|
[functions, scripts],
|
|
46
49
|
);
|
|
47
50
|
|
|
48
51
|
const getScriptName = useCallback(
|
|
49
|
-
(func:
|
|
52
|
+
(func: Function.Function) => {
|
|
50
53
|
const script = functionToScriptMap[func.id];
|
|
51
54
|
return script?.name;
|
|
52
55
|
},
|
|
@@ -54,23 +57,33 @@ export const FunctionsPanel = ({ space }: FunctionsPanelProps) => {
|
|
|
54
57
|
);
|
|
55
58
|
|
|
56
59
|
const handleGoToScript = useCallback(
|
|
57
|
-
(func:
|
|
60
|
+
(func: Function.Function) => {
|
|
58
61
|
const script = functionToScriptMap[func.id];
|
|
59
62
|
if (script) {
|
|
60
|
-
void dispatch(
|
|
63
|
+
void dispatch(
|
|
64
|
+
createIntent(LayoutAction.Open, {
|
|
65
|
+
part: 'main',
|
|
66
|
+
subject: [Obj.getDXN(script).toString()],
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
61
69
|
}
|
|
62
70
|
},
|
|
63
71
|
[functionToScriptMap, dispatch],
|
|
64
72
|
);
|
|
65
73
|
|
|
74
|
+
const handleDelete = useCallback(
|
|
75
|
+
(func: Function.Function) => dispatch(createIntent(SpaceAction.RemoveObjects, { objects: [func] })),
|
|
76
|
+
[dispatch],
|
|
77
|
+
);
|
|
78
|
+
|
|
66
79
|
return (
|
|
67
80
|
<div role='none' className={mx(controlItemClasses)}>
|
|
68
81
|
{functions.length > 0 && (
|
|
69
|
-
<List.Root<
|
|
82
|
+
<List.Root<Function.Function> items={functions} isItem={Schema.is(Function.Function)} getId={(func) => func.id}>
|
|
70
83
|
{({ items }) => (
|
|
71
|
-
<div role='list' className='flex flex-col
|
|
84
|
+
<div role='list' className='flex flex-col is-full'>
|
|
72
85
|
{items?.map((func) => (
|
|
73
|
-
<List.Item<
|
|
86
|
+
<List.Item<Function.Function>
|
|
74
87
|
key={func.id}
|
|
75
88
|
item={func}
|
|
76
89
|
classNames={mx(grid, ghostHover, 'items-center', 'pli-2', 'min-bs-[3rem]')}
|
|
@@ -84,6 +97,12 @@ export const FunctionsPanel = ({ space }: FunctionsPanelProps) => {
|
|
|
84
97
|
{functionToScriptMap[func.id] && (
|
|
85
98
|
<Button onClick={() => handleGoToScript(func)}>{t('go to function source button label')}</Button>
|
|
86
99
|
)}
|
|
100
|
+
<IconButton
|
|
101
|
+
iconOnly
|
|
102
|
+
icon='ph--trash--regular'
|
|
103
|
+
label={t('delete function button label')}
|
|
104
|
+
onClick={() => handleDelete(func)}
|
|
105
|
+
/>
|
|
87
106
|
</List.Item>
|
|
88
107
|
))}
|
|
89
108
|
</div>
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Array from 'effect/Array';
|
|
6
|
+
import * as EffectFunction from 'effect/Function';
|
|
7
|
+
import * as Order from 'effect/Order';
|
|
8
|
+
import * as Schema from 'effect/Schema';
|
|
9
|
+
import { useState } from 'react';
|
|
10
|
+
import React, { useCallback } from 'react';
|
|
11
|
+
|
|
12
|
+
import { Obj } from '@dxos/echo';
|
|
13
|
+
import { Function } from '@dxos/functions';
|
|
14
|
+
import { getDeployedFunctions } from '@dxos/functions-runtime/edge';
|
|
15
|
+
import { useClient } from '@dxos/react-client';
|
|
16
|
+
import { Filter, Query, type Space, useQuery } from '@dxos/react-client/echo';
|
|
17
|
+
import { useAsyncEffect } from '@dxos/react-ui';
|
|
18
|
+
import { IconButton, useTranslation } from '@dxos/react-ui';
|
|
19
|
+
import { controlItemClasses } from '@dxos/react-ui-form';
|
|
20
|
+
import { List } from '@dxos/react-ui-list';
|
|
21
|
+
import { ghostHover, mx } from '@dxos/react-ui-theme';
|
|
22
|
+
|
|
23
|
+
import { meta } from '../../meta';
|
|
24
|
+
|
|
25
|
+
const grid = 'grid grid-cols-[1fr_1fr_auto] min-bs-[2.5rem]';
|
|
26
|
+
|
|
27
|
+
type FunctionsRegistryProps = {
|
|
28
|
+
space: Space;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const FunctionsRegistry = ({ space }: FunctionsRegistryProps) => {
|
|
32
|
+
const client = useClient();
|
|
33
|
+
const [loading, setLoading] = useState(true);
|
|
34
|
+
const [functions, setFunctions] = useState<Function.Function[]>([]);
|
|
35
|
+
const { t } = useTranslation(meta.id);
|
|
36
|
+
|
|
37
|
+
const dbFunctions = useQuery(space, Filter.type(Function.Function));
|
|
38
|
+
|
|
39
|
+
const state = (func: Function.Function) => {
|
|
40
|
+
const dbFunction = dbFunctions.find((f) => f.key === func.key);
|
|
41
|
+
if (!dbFunction) {
|
|
42
|
+
return 'import';
|
|
43
|
+
}
|
|
44
|
+
if (dbFunction.version === func.version && dbFunction.updated === func.updated) {
|
|
45
|
+
return 'none';
|
|
46
|
+
}
|
|
47
|
+
return 'update';
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
useAsyncEffect(async () => {
|
|
51
|
+
setLoading(true);
|
|
52
|
+
const functions = await getDeployedFunctions(client);
|
|
53
|
+
setFunctions(functions);
|
|
54
|
+
setLoading(false);
|
|
55
|
+
}, []);
|
|
56
|
+
|
|
57
|
+
const dedupedFunctions = EffectFunction.pipe(
|
|
58
|
+
functions,
|
|
59
|
+
Array.filter((_) => _.key !== undefined),
|
|
60
|
+
Array.sort(Order.reverse(Order.mapInput(Order.string, (_: Function.Function) => _.updated ?? ''))),
|
|
61
|
+
Array.dedupeWith((self, that) => self.key === that.key),
|
|
62
|
+
Array.sort(Order.mapInput(Order.string, (_: Function.Function) => _.key ?? '')),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const hanleImportOrUpdate = useCallback(
|
|
66
|
+
async (func: Function.Function) => {
|
|
67
|
+
const {
|
|
68
|
+
objects: [existingFunc],
|
|
69
|
+
} = await space.db.query(Query.type(Function.Function, { key: func.key })).run();
|
|
70
|
+
if (!existingFunc) {
|
|
71
|
+
space.db.add(func);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
existingFunc.version = func.version;
|
|
75
|
+
existingFunc.updated = func.updated;
|
|
76
|
+
existingFunc.name = func.name;
|
|
77
|
+
existingFunc.description = func.description;
|
|
78
|
+
// TODO(dmaretskyi): A workaround for an ECHO bug.
|
|
79
|
+
existingFunc.inputSchema = JSON.parse(JSON.stringify(func.inputSchema));
|
|
80
|
+
existingFunc.outputSchema = JSON.parse(JSON.stringify(func.outputSchema));
|
|
81
|
+
Obj.getMeta(existingFunc).keys = JSON.parse(JSON.stringify(Obj.getMeta(func).keys));
|
|
82
|
+
},
|
|
83
|
+
[space],
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<div role='none' className={mx(controlItemClasses)}>
|
|
88
|
+
{dedupedFunctions.length > 0 && (
|
|
89
|
+
<List.Root<Function.Function>
|
|
90
|
+
items={dedupedFunctions}
|
|
91
|
+
isItem={Schema.is(Function.Function)}
|
|
92
|
+
getId={(func) => func.id}
|
|
93
|
+
>
|
|
94
|
+
{({ items }) => (
|
|
95
|
+
<div role='list' className='flex flex-col is-full'>
|
|
96
|
+
{items?.map((func) => (
|
|
97
|
+
<List.Item<Function.Function>
|
|
98
|
+
key={func.id}
|
|
99
|
+
item={func}
|
|
100
|
+
classNames={mx(grid, ghostHover, 'items-center', 'pli-2', 'min-bs-[3rem]')}
|
|
101
|
+
>
|
|
102
|
+
<div className='flex flex-col truncate'>
|
|
103
|
+
<List.ItemTitle classNames='truncate'>{func.name}</List.ItemTitle>
|
|
104
|
+
<div className='text-xs text-description truncate'>{func.key}</div>
|
|
105
|
+
</div>
|
|
106
|
+
<div className='flex flex-col truncate'>
|
|
107
|
+
<div className='text-xs text-description truncate'>{func.version}</div>
|
|
108
|
+
<div className='text-xs text-description truncate'>
|
|
109
|
+
{func.updated ? `Uploaded ${new Date(func.updated).toLocaleString()}` : ''}
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
|
|
113
|
+
<IconButton
|
|
114
|
+
iconOnly
|
|
115
|
+
icon={state(func) === 'update' ? 'ph--arrows-clockwise--regular' : 'ph--download--regular'}
|
|
116
|
+
label={
|
|
117
|
+
state(func) === 'update' ? t('update function button label') : t('import function button label')
|
|
118
|
+
}
|
|
119
|
+
disabled={state(func) === 'none'}
|
|
120
|
+
onClick={() => hanleImportOrUpdate(func)}
|
|
121
|
+
/>
|
|
122
|
+
</List.Item>
|
|
123
|
+
))}
|
|
124
|
+
</div>
|
|
125
|
+
)}
|
|
126
|
+
</List.Root>
|
|
127
|
+
)}
|
|
128
|
+
|
|
129
|
+
{dedupedFunctions.length === 0 && !loading && (
|
|
130
|
+
<div className='text-center plb-4 text-gray-500'>{t('no functions found')}</div>
|
|
131
|
+
)}
|
|
132
|
+
{loading && <div className='text-center plb-4 text-gray-500'>{t('loading functions')}</div>}
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
};
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
import React, { useCallback, useMemo } from 'react';
|
|
6
6
|
|
|
7
7
|
import { Ref, Type } from '@dxos/echo';
|
|
8
|
-
import { type JsonPath } from '@dxos/echo
|
|
9
|
-
import { type
|
|
8
|
+
import { type JsonPath } from '@dxos/echo/internal';
|
|
9
|
+
import { type Function } from '@dxos/functions';
|
|
10
10
|
import { useOnTransition } from '@dxos/react-ui';
|
|
11
11
|
import { Form, type FormInputStateProps, type QueryRefOptions, useFormValues } from '@dxos/react-ui-form';
|
|
12
12
|
|
|
13
13
|
export type FunctionInputEditorProps = {
|
|
14
|
-
functions:
|
|
14
|
+
functions: Function.Function[];
|
|
15
15
|
onQueryRefOptions: QueryRefOptions;
|
|
16
16
|
} & FormInputStateProps;
|
|
17
17
|
|
|
@@ -39,7 +39,13 @@ export const FunctionInputEditor = ({
|
|
|
39
39
|
useOnTransition(
|
|
40
40
|
// Clear function parameter input when the function changes.
|
|
41
41
|
selectedFunctionValue,
|
|
42
|
-
(prevValue) =>
|
|
42
|
+
(prevValue) => {
|
|
43
|
+
if (!Ref.isRef(prevValue) || !Ref.isRef(selectedFunctionValue)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return prevValue.dxn.toString() !== selectedFunctionValue.dxn.toString();
|
|
48
|
+
},
|
|
43
49
|
(currValue) => currValue !== undefined,
|
|
44
50
|
() => onValueChange('object', {}),
|
|
45
51
|
);
|
|
@@ -4,32 +4,38 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { useCallback, useMemo } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { Filter, Query } from '@dxos/echo';
|
|
8
|
+
import { Trigger } from '@dxos/functions';
|
|
8
9
|
import { useTranslation } from '@dxos/react-ui';
|
|
9
10
|
import { type InputProps, SelectInput, useInputProps } from '@dxos/react-ui-form';
|
|
10
11
|
|
|
11
|
-
import {
|
|
12
|
+
import { meta } from '../../meta';
|
|
12
13
|
|
|
13
14
|
export type SpecSelectorProps = InputProps;
|
|
14
15
|
|
|
15
16
|
export const SpecSelector = (props: SpecSelectorProps) => {
|
|
16
|
-
const { t } = useTranslation(
|
|
17
|
-
const specProps = useInputProps(['spec' satisfies keyof
|
|
17
|
+
const { t } = useTranslation(meta.id);
|
|
18
|
+
const specProps = useInputProps(['spec' satisfies keyof Trigger.Trigger]);
|
|
18
19
|
|
|
19
20
|
const handleTypeChange = useCallback(
|
|
20
|
-
(_type: any, value: string):
|
|
21
|
+
(_type: any, value: string): Trigger.Spec | undefined => {
|
|
21
22
|
const getDefaultTriggerSpec = (kind: string) => {
|
|
22
23
|
switch (kind) {
|
|
23
|
-
case
|
|
24
|
-
return { kind:
|
|
25
|
-
case
|
|
26
|
-
return {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
case 'timer':
|
|
25
|
+
return { kind: 'timer', cron: '' };
|
|
26
|
+
case 'subscription':
|
|
27
|
+
return {
|
|
28
|
+
kind: 'subscription',
|
|
29
|
+
query: {
|
|
30
|
+
ast: Query.select(Filter.nothing()).ast,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
case 'queue':
|
|
34
|
+
return { kind: 'queue', queue: 'dxn:' };
|
|
35
|
+
case 'email':
|
|
36
|
+
return { kind: 'email' };
|
|
37
|
+
case 'webhook':
|
|
38
|
+
return { kind: 'webhook' };
|
|
33
39
|
default:
|
|
34
40
|
return undefined;
|
|
35
41
|
}
|
|
@@ -48,7 +54,7 @@ export const SpecSelector = (props: SpecSelectorProps) => {
|
|
|
48
54
|
|
|
49
55
|
const options = useMemo(
|
|
50
56
|
() =>
|
|
51
|
-
|
|
57
|
+
Trigger.Kinds.map((kind) => ({
|
|
52
58
|
value: kind,
|
|
53
59
|
label: t(`trigger type ${kind}`),
|
|
54
60
|
})),
|