@dxos/plugin-automation 0.8.4-main.3f58842 → 0.8.4-main.406dc2a
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-3PHA5FTJ.mjs +11 -0
- package/dist/lib/browser/AutomationSettings-3EYSPFKB.mjs +69 -0
- package/dist/lib/browser/AutomationSettings-3EYSPFKB.mjs.map +7 -0
- package/dist/lib/browser/{FunctionsContainer-IOB333TX.mjs → FunctionsContainer-HHBMPUOD.mjs} +9 -12
- package/dist/lib/browser/FunctionsContainer-HHBMPUOD.mjs.map +7 -0
- package/dist/lib/browser/{FunctionsPanel-56ZKRVM5.mjs → FunctionsPanel-NRIKAPQV.mjs} +3 -3
- package/dist/lib/browser/{app-graph-builder-ZTAUTFI4.mjs → app-graph-builder-DV5HMFX4.mjs} +11 -10
- package/dist/lib/browser/app-graph-builder-DV5HMFX4.mjs.map +7 -0
- package/dist/lib/browser/chunk-5ARH77PV.mjs +15 -0
- package/dist/lib/browser/chunk-5ARH77PV.mjs.map +7 -0
- package/dist/lib/browser/chunk-6TUZQIEN.mjs +14 -0
- package/dist/lib/browser/chunk-6TUZQIEN.mjs.map +7 -0
- package/dist/lib/browser/chunk-DK7BLEKU.mjs +14 -0
- package/dist/lib/browser/chunk-DK7BLEKU.mjs.map +7 -0
- package/dist/lib/browser/{chunk-LYJVTIVD.mjs → chunk-DLLE4FKP.mjs} +6 -6
- package/dist/lib/browser/chunk-DLLE4FKP.mjs.map +7 -0
- package/dist/lib/browser/chunk-MVPRI3DB.mjs +53 -0
- package/dist/lib/browser/chunk-MVPRI3DB.mjs.map +7 -0
- package/dist/lib/browser/{chunk-FSJZXTS2.mjs → chunk-SUKAEYF3.mjs} +69 -32
- package/dist/lib/browser/chunk-SUKAEYF3.mjs.map +7 -0
- package/dist/lib/browser/{chunk-HN7OHFCB.mjs → chunk-VGBZKM3O.mjs} +3 -3
- package/dist/lib/browser/chunk-VGBZKM3O.mjs.map +7 -0
- package/dist/lib/browser/{chunk-ERTIGJYE.mjs → chunk-VL3KSDVL.mjs} +65 -29
- package/dist/lib/browser/chunk-VL3KSDVL.mjs.map +7 -0
- package/dist/lib/browser/{chunk-GW5U2DGT.mjs → chunk-WWURMV25.mjs} +2 -4
- package/dist/lib/browser/chunk-WWURMV25.mjs.map +7 -0
- package/dist/lib/browser/compute-runtime-YJREH6WP.mjs +160 -0
- package/dist/lib/browser/compute-runtime-YJREH6WP.mjs.map +7 -0
- package/dist/lib/browser/hooks/index.mjs +12 -0
- package/dist/lib/browser/index.mjs +36 -16
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/{intent-resolver-U3ZAQEFW.mjs → intent-resolver-D2OHKQRR.mjs} +11 -10
- package/dist/lib/browser/intent-resolver-D2OHKQRR.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-4DFSM7OX.mjs → react-surface-G7CG7BML.mjs} +18 -19
- package/dist/lib/browser/react-surface-G7CG7BML.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +2 -2
- package/dist/lib/node-esm/{AutomationPanel-YYUMSK2W.mjs → AutomationPanel-EETYIR35.mjs} +4 -4
- package/dist/lib/node-esm/AutomationSettings-WKSMWITV.mjs +70 -0
- package/dist/lib/node-esm/AutomationSettings-WKSMWITV.mjs.map +7 -0
- package/dist/lib/node-esm/{FunctionsContainer-DJWB6WFH.mjs → FunctionsContainer-ZKVOBUHV.mjs} +9 -12
- package/dist/lib/node-esm/FunctionsContainer-ZKVOBUHV.mjs.map +7 -0
- package/dist/lib/node-esm/{FunctionsPanel-KGIOZSPZ.mjs → FunctionsPanel-SAMRTELO.mjs} +3 -3
- package/dist/lib/node-esm/FunctionsPanel-SAMRTELO.mjs.map +7 -0
- package/dist/lib/node-esm/{app-graph-builder-3FP63ZSG.mjs → app-graph-builder-TR2WXPX2.mjs} +11 -10
- package/dist/lib/node-esm/app-graph-builder-TR2WXPX2.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-2EWXIFEK.mjs +16 -0
- package/dist/lib/node-esm/chunk-2EWXIFEK.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-NK5N3QKD.mjs → chunk-5MQJPJR2.mjs} +2 -4
- package/dist/lib/node-esm/chunk-5MQJPJR2.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-HIMYPGHF.mjs → chunk-AKHETVIQ.mjs} +65 -29
- package/dist/lib/node-esm/chunk-AKHETVIQ.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-B7N3H45O.mjs +16 -0
- package/dist/lib/node-esm/chunk-B7N3H45O.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-OEZNHUL2.mjs → chunk-CJUI6AKX.mjs} +3 -3
- package/dist/lib/node-esm/chunk-CJUI6AKX.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-AZH66CED.mjs → chunk-J3XEBEIE.mjs} +69 -32
- package/dist/lib/node-esm/chunk-J3XEBEIE.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-QCA543ZR.mjs +54 -0
- package/dist/lib/node-esm/chunk-QCA543ZR.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-WHCSOUNN.mjs +16 -0
- package/dist/lib/node-esm/chunk-WHCSOUNN.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-ZGPUV5VS.mjs → chunk-YQXW3JXD.mjs} +6 -6
- package/dist/lib/node-esm/chunk-YQXW3JXD.mjs.map +7 -0
- package/dist/lib/node-esm/compute-runtime-CMEPAYND.mjs +161 -0
- package/dist/lib/node-esm/compute-runtime-CMEPAYND.mjs.map +7 -0
- package/dist/lib/node-esm/hooks/index.mjs +13 -0
- package/dist/lib/node-esm/hooks/index.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +36 -16
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/{intent-resolver-3QWXEBPX.mjs → intent-resolver-2LGBVXT5.mjs} +11 -10
- package/dist/lib/node-esm/intent-resolver-2LGBVXT5.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-3PNW7NDW.mjs → react-surface-OMZSBDHS.mjs} +18 -19
- package/dist/lib/node-esm/react-surface-OMZSBDHS.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 +19 -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/intent-resolver.d.ts.map +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 +45 -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/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 +6 -4
- package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts.map +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts +47 -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 +8 -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 +2 -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 +2 -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 +60 -37
- package/src/AutomationPlugin.tsx +37 -31
- package/src/capabilities/app-graph-builder.ts +10 -9
- package/src/capabilities/capabilities.ts +48 -0
- package/src/capabilities/compute-runtime.ts +138 -0
- package/src/capabilities/index.ts +3 -0
- package/src/capabilities/intent-resolver.ts +7 -7
- package/src/capabilities/react-surface.tsx +13 -14
- package/src/components/AutomationPanel/AutomationPanel.stories.tsx +13 -13
- package/src/components/AutomationPanel/AutomationPanel.tsx +91 -40
- package/src/components/AutomationSettings.tsx +30 -0
- package/src/components/FunctionsContainer.tsx +11 -13
- package/src/components/FunctionsPanel/FunctionsPanel.tsx +5 -5
- package/src/components/TriggerEditor/FunctionInputEditor.tsx +8 -2
- package/src/components/TriggerEditor/SpecSelector.tsx +22 -16
- package/src/components/TriggerEditor/TriggerEditor.stories.tsx +66 -24
- package/src/components/TriggerEditor/TriggerEditor.tsx +40 -20
- 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 +30 -0
- package/src/hooks/useTriggerRuntimeControls.ts +52 -0
- package/src/index.ts +2 -0
- package/src/meta.ts +1 -3
- package/src/testing/test-functions.ts +1 -1
- package/src/translations.ts +4 -0
- package/src/types/schema.ts +1 -1
- package/dist/lib/browser/AutomationContainer-VZNV2ZQF.mjs +0 -38
- package/dist/lib/browser/AutomationContainer-VZNV2ZQF.mjs.map +0 -7
- package/dist/lib/browser/AutomationPanel-ZWA6GOFY.mjs +0 -11
- package/dist/lib/browser/FunctionsContainer-IOB333TX.mjs.map +0 -7
- package/dist/lib/browser/app-graph-builder-ZTAUTFI4.mjs.map +0 -7
- package/dist/lib/browser/chunk-ECSTS2UI.mjs +0 -14
- package/dist/lib/browser/chunk-ECSTS2UI.mjs.map +0 -7
- package/dist/lib/browser/chunk-ERTIGJYE.mjs.map +0 -7
- package/dist/lib/browser/chunk-FSJZXTS2.mjs.map +0 -7
- 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-LYJVTIVD.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-U3ZAQEFW.mjs.map +0 -7
- package/dist/lib/browser/react-surface-4DFSM7OX.mjs.map +0 -7
- package/dist/lib/node-esm/AutomationContainer-WMIH3F4V.mjs +0 -39
- package/dist/lib/node-esm/AutomationContainer-WMIH3F4V.mjs.map +0 -7
- package/dist/lib/node-esm/FunctionsContainer-DJWB6WFH.mjs.map +0 -7
- package/dist/lib/node-esm/app-graph-builder-3FP63ZSG.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AZH66CED.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HIMYPGHF.mjs.map +0 -7
- 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-SGZPTJ47.mjs +0 -16
- package/dist/lib/node-esm/chunk-SGZPTJ47.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZGPUV5VS.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-3QWXEBPX.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-3PNW7NDW.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 -30
- /package/dist/lib/browser/{AutomationPanel-ZWA6GOFY.mjs.map → AutomationPanel-3PHA5FTJ.mjs.map} +0 -0
- /package/dist/lib/browser/{FunctionsPanel-56ZKRVM5.mjs.map → FunctionsPanel-NRIKAPQV.mjs.map} +0 -0
- /package/dist/lib/{node-esm/AutomationPanel-YYUMSK2W.mjs.map → browser/hooks/index.mjs.map} +0 -0
- /package/dist/lib/node-esm/{FunctionsPanel-KGIOZSPZ.mjs.map → AutomationPanel-EETYIR35.mjs.map} +0 -0
|
@@ -2,56 +2,57 @@
|
|
|
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 Function 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 { FunctionTrigger, FunctionType, ScriptType } from '@dxos/functions';
|
|
13
|
+
import { useTypeOptions } from '@dxos/plugin-space';
|
|
17
14
|
import { type Client, useClient } from '@dxos/react-client';
|
|
18
|
-
import {
|
|
19
|
-
import { Clipboard, IconButton, Input, Separator, useTranslation } from '@dxos/react-ui';
|
|
15
|
+
import { type Space, getSpace, useQuery } from '@dxos/react-client/echo';
|
|
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 { DataType } from '@dxos/schema';
|
|
23
21
|
|
|
24
|
-
import {
|
|
22
|
+
import { meta } from '../../meta';
|
|
25
23
|
import { TriggerEditor, type TriggerEditorProps } from '../TriggerEditor';
|
|
26
24
|
|
|
27
25
|
const grid = 'grid grid-cols-[40px_1fr_32px] min-bs-[2.5rem]';
|
|
28
26
|
|
|
29
|
-
export type AutomationPanelProps = {
|
|
27
|
+
export type AutomationPanelProps = ThemedClassName<{
|
|
30
28
|
space: Space;
|
|
31
29
|
object?: Obj.Any;
|
|
32
|
-
initialTrigger?:
|
|
30
|
+
initialTrigger?: FunctionTrigger;
|
|
33
31
|
onDone?: () => void;
|
|
34
|
-
}
|
|
32
|
+
}>;
|
|
35
33
|
|
|
36
34
|
// TODO(burdon): Factor out common layout with ViewEditor.
|
|
37
|
-
export const AutomationPanel = ({ space, object, initialTrigger, onDone }: AutomationPanelProps) => {
|
|
38
|
-
const { t } = useTranslation(
|
|
35
|
+
export const AutomationPanel = ({ classNames, space, object, initialTrigger, onDone }: AutomationPanelProps) => {
|
|
36
|
+
const { t } = useTranslation(meta.id);
|
|
39
37
|
const client = useClient();
|
|
40
|
-
const triggers = useQuery(space, Filter.type(FunctionTrigger));
|
|
41
38
|
const functions = useQuery(space, Filter.type(FunctionType));
|
|
42
|
-
const
|
|
39
|
+
const triggers = useQuery(space, Filter.type(FunctionTrigger));
|
|
40
|
+
const filteredTriggers = useMemo(() => {
|
|
41
|
+
return object ? triggers.filter(triggerMatch(object)) : triggers;
|
|
42
|
+
}, [object, triggers]);
|
|
43
|
+
const tags = useQuery(space, Filter.type(Tag.Tag));
|
|
44
|
+
const types = useTypeOptions({ space, annotation: ['dynamic', 'limited-static', 'object-form'] });
|
|
43
45
|
|
|
44
|
-
const [trigger, setTrigger] = useState<
|
|
46
|
+
const [trigger, setTrigger] = useState<FunctionTrigger | undefined>(initialTrigger);
|
|
45
47
|
const [selected, setSelected] = useState<FunctionTrigger>();
|
|
46
48
|
|
|
47
49
|
const handleSelect = (trigger: FunctionTrigger) => {
|
|
48
|
-
|
|
49
|
-
setTrigger(values);
|
|
50
|
+
setTrigger(trigger);
|
|
50
51
|
setSelected(trigger);
|
|
51
52
|
};
|
|
52
53
|
|
|
53
54
|
const handleAdd = () => {
|
|
54
|
-
setTrigger(Obj.make(
|
|
55
|
+
setTrigger(Obj.make(FunctionTrigger, {}));
|
|
55
56
|
setSelected(undefined);
|
|
56
57
|
};
|
|
57
58
|
|
|
@@ -81,18 +82,30 @@ export const AutomationPanel = ({ space, object, initialTrigger, onDone }: Autom
|
|
|
81
82
|
if (trigger) {
|
|
82
83
|
return (
|
|
83
84
|
<ControlItem title={t('trigger editor title')}>
|
|
84
|
-
<TriggerEditor
|
|
85
|
+
<TriggerEditor
|
|
86
|
+
space={space}
|
|
87
|
+
trigger={trigger}
|
|
88
|
+
readonlySpec={Boolean(object)}
|
|
89
|
+
tags={tags}
|
|
90
|
+
types={types}
|
|
91
|
+
onSave={handleSave}
|
|
92
|
+
onCancel={handleCancel}
|
|
93
|
+
/>
|
|
85
94
|
</ControlItem>
|
|
86
95
|
);
|
|
87
96
|
}
|
|
88
97
|
|
|
89
98
|
return (
|
|
90
|
-
<div className={controlItemClasses}>
|
|
91
|
-
{
|
|
92
|
-
<List.Root<FunctionTrigger>
|
|
93
|
-
{
|
|
99
|
+
<div className={mx(controlItemClasses, classNames)}>
|
|
100
|
+
{filteredTriggers.length > 0 && (
|
|
101
|
+
<List.Root<FunctionTrigger>
|
|
102
|
+
items={filteredTriggers}
|
|
103
|
+
isItem={Schema.is(FunctionTrigger)}
|
|
104
|
+
getId={(field) => field.id}
|
|
105
|
+
>
|
|
106
|
+
{({ items: filteredTriggers }) => (
|
|
94
107
|
<div role='list' className='flex flex-col w-full'>
|
|
95
|
-
{
|
|
108
|
+
{filteredTriggers?.map((trigger) => {
|
|
96
109
|
const copyAction = getCopyAction(client, trigger);
|
|
97
110
|
return (
|
|
98
111
|
<List.Item<FunctionTrigger>
|
|
@@ -112,7 +125,7 @@ export const AutomationPanel = ({ space, object, initialTrigger, onDone }: Autom
|
|
|
112
125
|
classNames='px-1 cursor-pointer w-0 shrink truncate'
|
|
113
126
|
onClick={() => handleSelect(trigger)}
|
|
114
127
|
>
|
|
115
|
-
{getFunctionName(
|
|
128
|
+
{getFunctionName(functions, trigger) ?? '∅'}
|
|
116
129
|
</List.ItemTitle>
|
|
117
130
|
|
|
118
131
|
{/* TODO: a better way to expose copy action */}
|
|
@@ -132,18 +145,18 @@ export const AutomationPanel = ({ space, object, initialTrigger, onDone }: Autom
|
|
|
132
145
|
)}
|
|
133
146
|
</List.Root>
|
|
134
147
|
)}
|
|
135
|
-
{
|
|
148
|
+
{filteredTriggers.length > 0 && <Separator classNames='mlb-4' />}
|
|
136
149
|
<IconButton icon='ph--plus--regular' label={t('new trigger label')} onClick={handleAdd} />
|
|
137
150
|
</div>
|
|
138
151
|
);
|
|
139
152
|
};
|
|
140
153
|
|
|
141
154
|
const getCopyAction = (client: Client, trigger: FunctionTrigger | undefined) => {
|
|
142
|
-
if (trigger?.spec?.kind ===
|
|
155
|
+
if (trigger?.spec?.kind === 'email') {
|
|
143
156
|
return { translationKey: 'trigger copy email', contentProvider: () => `${getSpace(trigger)!.id}@dxos.network` };
|
|
144
157
|
}
|
|
145
158
|
|
|
146
|
-
if (trigger?.spec?.kind ===
|
|
159
|
+
if (trigger?.spec?.kind === 'webhook') {
|
|
147
160
|
return { translationKey: 'trigger copy url', contentProvider: () => getWebhookUrl(client, trigger) };
|
|
148
161
|
}
|
|
149
162
|
|
|
@@ -158,14 +171,52 @@ const getWebhookUrl = (client: Client, trigger: FunctionTrigger) => {
|
|
|
158
171
|
return new URL(`/webhook/${spaceId}:${trigger.id}`, edgeUrl).toString();
|
|
159
172
|
};
|
|
160
173
|
|
|
161
|
-
const getFunctionName = (
|
|
174
|
+
const getFunctionName = (functions: FunctionType[], trigger: FunctionTrigger) => {
|
|
162
175
|
// TODO(wittjosiah): Truncation should be done in the UI.
|
|
163
176
|
// Warning that the List component is currently a can of worms.
|
|
164
177
|
const shortId = trigger.function && `${trigger.function.dxn.toString().slice(0, 16)}…`;
|
|
165
178
|
const functionObject = functions.find((fn) => fn === trigger.function?.target);
|
|
166
|
-
|
|
167
|
-
|
|
179
|
+
return functionObject?.name ?? shortId;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const scriptMatch = (script: ScriptType) => (trigger: FunctionTrigger) => {
|
|
183
|
+
const fn = trigger.function?.target;
|
|
184
|
+
if (!Obj.instanceOf(FunctionType, fn)) {
|
|
185
|
+
return false;
|
|
168
186
|
}
|
|
169
187
|
|
|
170
|
-
return
|
|
188
|
+
return fn.source?.target === script;
|
|
171
189
|
};
|
|
190
|
+
|
|
191
|
+
const projectMatch = (project: DataType.Project) => {
|
|
192
|
+
const viewQueries = Function.pipe(
|
|
193
|
+
project.collections,
|
|
194
|
+
Array.map((collection) => collection.target),
|
|
195
|
+
Array.filter(Schema.is(DataType.View)),
|
|
196
|
+
Array.map((view) => Obj.getSnapshot(view).query.ast),
|
|
197
|
+
Array.map((ast) => JSON.stringify(ast)),
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
return (trigger: FunctionTrigger) => {
|
|
201
|
+
const spec = Obj.getSnapshot(trigger).spec;
|
|
202
|
+
if (spec?.kind !== 'subscription') {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// TODO(wittjosiah): Implement better way of comparing query ASTs.
|
|
207
|
+
return viewQueries.some((query) => JSON.stringify(spec.query) === query);
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const triggerMatch = Match.type<Obj.Any>().pipe(
|
|
212
|
+
Match.withReturnType<(trigger: FunctionTrigger) => boolean>(),
|
|
213
|
+
Match.when(
|
|
214
|
+
(obj) => Obj.instanceOf(ScriptType, obj),
|
|
215
|
+
(obj) => scriptMatch(obj),
|
|
216
|
+
),
|
|
217
|
+
Match.when(
|
|
218
|
+
(obj) => Obj.instanceOf(DataType.Project, obj),
|
|
219
|
+
(obj) => projectMatch(obj),
|
|
220
|
+
),
|
|
221
|
+
Match.orElse((_obj) => () => true),
|
|
222
|
+
);
|
|
@@ -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,24 +7,22 @@ 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
|
-
|
|
10
|
+
|
|
11
|
+
import { meta } from '../meta';
|
|
11
12
|
|
|
12
13
|
import { FunctionsPanel } from './FunctionsPanel';
|
|
13
|
-
import { AUTOMATION_PLUGIN } from '../meta';
|
|
14
14
|
|
|
15
15
|
export const FunctionsContainer = ({ space }: { space: Space }) => {
|
|
16
|
-
const { t } = useTranslation(
|
|
16
|
+
const { t } = useTranslation(meta.id);
|
|
17
17
|
return (
|
|
18
|
-
<
|
|
19
|
-
<
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
</ControlPage>
|
|
27
|
-
</StackItem.Content>
|
|
18
|
+
<ControlPage>
|
|
19
|
+
<ControlSection
|
|
20
|
+
title={t('functions verbose label', { ns: meta.id })}
|
|
21
|
+
description={t('functions description', { ns: meta.id })}
|
|
22
|
+
>
|
|
23
|
+
<FunctionsPanel space={space} />
|
|
24
|
+
</ControlSection>
|
|
25
|
+
</ControlPage>
|
|
28
26
|
);
|
|
29
27
|
};
|
|
30
28
|
|
|
@@ -2,18 +2,18 @@
|
|
|
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 {
|
|
8
|
+
import { LayoutAction, createIntent, useIntentDispatcher } from '@dxos/app-framework';
|
|
9
9
|
import { FunctionType, ScriptType } from '@dxos/functions';
|
|
10
|
-
import { Filter, fullyQualifiedId, useQuery
|
|
10
|
+
import { Filter, type Space, fullyQualifiedId, useQuery } from '@dxos/react-client/echo';
|
|
11
11
|
import { Button, useTranslation } from '@dxos/react-ui';
|
|
12
12
|
import { controlItemClasses } from '@dxos/react-ui-form';
|
|
13
13
|
import { List } from '@dxos/react-ui-list';
|
|
14
14
|
import { ghostHover, mx } from '@dxos/react-ui-theme';
|
|
15
15
|
|
|
16
|
-
import {
|
|
16
|
+
import { meta } from '../../meta';
|
|
17
17
|
|
|
18
18
|
const grid = 'grid grid-cols-[1fr_auto] min-bs-[2.5rem]';
|
|
19
19
|
|
|
@@ -22,7 +22,7 @@ export type FunctionsPanelProps = {
|
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export const FunctionsPanel = ({ space }: FunctionsPanelProps) => {
|
|
25
|
-
const { t } = useTranslation(
|
|
25
|
+
const { t } = useTranslation(meta.id);
|
|
26
26
|
const functions = useQuery(space, Filter.type(FunctionType));
|
|
27
27
|
const scripts = useQuery(space, Filter.type(ScriptType));
|
|
28
28
|
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
@@ -5,7 +5,7 @@
|
|
|
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
|
|
8
|
+
import { type JsonPath } from '@dxos/echo/internal';
|
|
9
9
|
import { type FunctionType } 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';
|
|
@@ -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 { type FunctionTrigger, TriggerKinds, type TriggerType } from '@dxos/functions';
|
|
8
9
|
import { useTranslation } from '@dxos/react-ui';
|
|
9
|
-
import {
|
|
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 FunctionTrigger]);
|
|
18
19
|
|
|
19
20
|
const handleTypeChange = useCallback(
|
|
20
21
|
(_type: any, value: string): TriggerType | 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
|
+
TriggerKinds.map((kind) => ({
|
|
52
58
|
value: kind,
|
|
53
59
|
label: t(`trigger type ${kind}`),
|
|
54
60
|
})),
|
|
@@ -2,32 +2,55 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import React, { useState } from 'react';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
import { Obj } from '@dxos/echo';
|
|
11
|
-
import { FunctionType, FunctionTrigger, TriggerKind } from '@dxos/functions';
|
|
8
|
+
import { Filter, Obj, Ref, Tag, Type } from '@dxos/echo';
|
|
9
|
+
import { FunctionTrigger, FunctionType } from '@dxos/functions';
|
|
10
|
+
import { invariant } from '@dxos/invariant';
|
|
12
11
|
import { faker } from '@dxos/random';
|
|
13
|
-
import {
|
|
14
|
-
import { ContactType, withClientProvider } from '@dxos/react-client/testing';
|
|
15
|
-
import {
|
|
12
|
+
import { useQuery } from '@dxos/react-client/echo';
|
|
13
|
+
import { ContactType, useClientProvider, withClientProvider } from '@dxos/react-client/testing';
|
|
14
|
+
import { useAsyncEffect } from '@dxos/react-ui';
|
|
15
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
16
|
+
import { DataType } from '@dxos/schema';
|
|
16
17
|
|
|
17
|
-
import { TriggerEditor } from './TriggerEditor';
|
|
18
18
|
import { functions } from '../../testing';
|
|
19
19
|
import { translations } from '../../translations';
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
import { TriggerEditor, type TriggerEditorProps } from './TriggerEditor';
|
|
22
|
+
|
|
23
|
+
const types = [
|
|
24
|
+
// TODO(burdon): Get label from annotation.
|
|
25
|
+
{ value: Type.getTypename(DataType.Organization), label: 'Organization' },
|
|
26
|
+
{ value: Type.getTypename(DataType.Person), label: 'Person' },
|
|
27
|
+
{ value: Type.getTypename(DataType.Project), label: 'Project' },
|
|
28
|
+
{ value: Type.getTypename(DataType.Employer), label: 'Employer' },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const DefaultStory = (props: Partial<TriggerEditorProps>) => {
|
|
32
|
+
const { space } = useClientProvider();
|
|
24
33
|
const [trigger, setTrigger] = useState<FunctionTrigger>();
|
|
25
|
-
|
|
34
|
+
const tags = useQuery(space, Filter.type(Tag.Tag));
|
|
35
|
+
|
|
36
|
+
useAsyncEffect(async () => {
|
|
26
37
|
if (!space) {
|
|
27
38
|
return;
|
|
28
39
|
}
|
|
29
40
|
|
|
30
|
-
const
|
|
41
|
+
const result = await space.db.query(Filter.type(FunctionType)).run();
|
|
42
|
+
const fn = result.objects.find((fn) => fn.name === 'example.com/function/forex');
|
|
43
|
+
invariant(fn);
|
|
44
|
+
const trigger = space.db.add(
|
|
45
|
+
Obj.make(FunctionTrigger, {
|
|
46
|
+
function: Ref.make(fn),
|
|
47
|
+
spec: { kind: 'webhook' },
|
|
48
|
+
input: {
|
|
49
|
+
from: 'USD',
|
|
50
|
+
to: 'JPY',
|
|
51
|
+
},
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
31
54
|
setTrigger(trigger);
|
|
32
55
|
}, [space]);
|
|
33
56
|
|
|
@@ -37,21 +60,33 @@ const DefaultStory = () => {
|
|
|
37
60
|
|
|
38
61
|
return (
|
|
39
62
|
<div role='none' className='w-[32rem] bs-fit border border-separator rounded-sm'>
|
|
40
|
-
<TriggerEditor
|
|
63
|
+
<TriggerEditor
|
|
64
|
+
space={space}
|
|
65
|
+
trigger={trigger}
|
|
66
|
+
types={types}
|
|
67
|
+
tags={tags}
|
|
68
|
+
onSave={(values) => console.log('on save', values)}
|
|
69
|
+
{...props}
|
|
70
|
+
/>
|
|
41
71
|
</div>
|
|
42
72
|
);
|
|
43
73
|
};
|
|
44
74
|
|
|
45
|
-
const meta
|
|
75
|
+
const meta = {
|
|
46
76
|
title: 'plugins/plugin-automation/TriggerEditor',
|
|
47
|
-
component: TriggerEditor,
|
|
77
|
+
component: TriggerEditor as any,
|
|
48
78
|
render: DefaultStory,
|
|
49
79
|
decorators: [
|
|
80
|
+
withTheme,
|
|
50
81
|
withClientProvider({
|
|
51
82
|
createIdentity: true,
|
|
52
83
|
createSpace: true,
|
|
53
|
-
types: [FunctionType, FunctionTrigger, ContactType],
|
|
54
|
-
|
|
84
|
+
types: [Tag.Tag, FunctionType, FunctionTrigger, ContactType],
|
|
85
|
+
onCreateSpace: ({ space }) => {
|
|
86
|
+
space.db.add(Tag.make({ label: 'Important' }));
|
|
87
|
+
space.db.add(Tag.make({ label: 'Investor' }));
|
|
88
|
+
space.db.add(Tag.make({ label: 'New' }));
|
|
89
|
+
|
|
55
90
|
for (const fn of functions) {
|
|
56
91
|
space.db.add(Obj.make(FunctionType, fn));
|
|
57
92
|
}
|
|
@@ -65,14 +100,21 @@ const meta: Meta = {
|
|
|
65
100
|
});
|
|
66
101
|
},
|
|
67
102
|
}),
|
|
68
|
-
withLayout({ fullscreen: true, classNames: 'flex justify-center m-2' }),
|
|
69
|
-
withTheme,
|
|
70
103
|
],
|
|
71
104
|
parameters: {
|
|
105
|
+
layout: 'column',
|
|
72
106
|
translations,
|
|
73
107
|
},
|
|
74
|
-
}
|
|
108
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
75
109
|
|
|
76
110
|
export default meta;
|
|
77
111
|
|
|
78
|
-
|
|
112
|
+
type Story = StoryObj<typeof meta>;
|
|
113
|
+
|
|
114
|
+
export const Default: Story = {};
|
|
115
|
+
|
|
116
|
+
export const ReadonlySpec: Story = {
|
|
117
|
+
args: {
|
|
118
|
+
readonlySpec: true,
|
|
119
|
+
},
|
|
120
|
+
};
|
|
@@ -5,40 +5,38 @@
|
|
|
5
5
|
import React, { useCallback, useMemo } from 'react';
|
|
6
6
|
|
|
7
7
|
import { ComputeGraph } from '@dxos/conductor';
|
|
8
|
-
import { Type } from '@dxos/echo';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
ScriptType,
|
|
15
|
-
} from '@dxos/functions';
|
|
16
|
-
import { Filter, Ref, useQuery, type Space } from '@dxos/react-client/echo';
|
|
17
|
-
import { type CustomInputMap, Form, SelectInput, useRefQueryLookupHandler } from '@dxos/react-ui-form';
|
|
8
|
+
import { type Query, Type } from '@dxos/echo';
|
|
9
|
+
import { FunctionTrigger, FunctionType, ScriptType } from '@dxos/functions';
|
|
10
|
+
import { Filter, Ref, type Space, useQuery } from '@dxos/react-client/echo';
|
|
11
|
+
import { Input } from '@dxos/react-ui';
|
|
12
|
+
import { QueryForm, type QueryFormProps } from '@dxos/react-ui-components';
|
|
13
|
+
import { type CustomInputMap, Form, InputHeader, SelectInput, useRefQueryLookupHandler } from '@dxos/react-ui-form';
|
|
18
14
|
|
|
19
15
|
import { FunctionInputEditor, type FunctionInputEditorProps } from './FunctionInputEditor';
|
|
20
16
|
import { SpecSelector } from './SpecSelector';
|
|
21
17
|
|
|
22
18
|
export type TriggerEditorProps = {
|
|
23
19
|
space: Space;
|
|
24
|
-
trigger:
|
|
20
|
+
trigger: FunctionTrigger;
|
|
21
|
+
// TODO(wittjosiah): This needs to apply to whole spec but currently only applies to spec.kind & spec.query.
|
|
22
|
+
readonlySpec?: boolean;
|
|
25
23
|
onSave?: (trigger: Omit<FunctionTrigger, 'id'>) => void;
|
|
26
24
|
onCancel?: () => void;
|
|
27
|
-
}
|
|
25
|
+
} & Pick<QueryFormProps, 'types' | 'tags'>;
|
|
28
26
|
|
|
29
|
-
export const TriggerEditor = ({ space, trigger, onSave, onCancel }: TriggerEditorProps) => {
|
|
30
|
-
const handleSave = (values:
|
|
27
|
+
export const TriggerEditor = ({ space, trigger, readonlySpec, types, tags, onSave, onCancel }: TriggerEditorProps) => {
|
|
28
|
+
const handleSave = ({ id: _, ...values }: FunctionTrigger) => {
|
|
31
29
|
onSave?.(values);
|
|
32
30
|
};
|
|
33
31
|
|
|
34
32
|
const handleRefQueryLookup = useRefQueryLookupHandler({ space });
|
|
35
|
-
const Custom = useCustomInputs(space, handleRefQueryLookup);
|
|
33
|
+
const Custom = useCustomInputs({ space, readonlySpec, types, tags, onQueryRefOptions: handleRefQueryLookup });
|
|
36
34
|
|
|
37
35
|
return (
|
|
38
36
|
<Form
|
|
39
37
|
outerSpacing={false}
|
|
40
38
|
Custom={Custom}
|
|
41
|
-
schema={
|
|
39
|
+
schema={FunctionTrigger}
|
|
42
40
|
values={trigger}
|
|
43
41
|
onSave={handleSave}
|
|
44
42
|
onCancel={onCancel}
|
|
@@ -47,7 +45,13 @@ export const TriggerEditor = ({ space, trigger, onSave, onCancel }: TriggerEdito
|
|
|
47
45
|
);
|
|
48
46
|
};
|
|
49
47
|
|
|
50
|
-
|
|
48
|
+
type UseCustomInputsProps = {
|
|
49
|
+
space: Space;
|
|
50
|
+
readonlySpec?: boolean;
|
|
51
|
+
onQueryRefOptions: FunctionInputEditorProps['onQueryRefOptions'];
|
|
52
|
+
} & Pick<QueryFormProps, 'types' | 'tags'>;
|
|
53
|
+
|
|
54
|
+
const useCustomInputs = ({ space, readonlySpec, types, tags, onQueryRefOptions }: UseCustomInputsProps) => {
|
|
51
55
|
const functions = useQuery(space, Filter.type(FunctionType));
|
|
52
56
|
const workflows = useQuery(space, Filter.type(ComputeGraph));
|
|
53
57
|
const scripts = useQuery(space, Filter.type(ScriptType));
|
|
@@ -55,7 +59,7 @@ const useCustomInputs = (space: Space, onQueryRefOptions: FunctionInputEditorPro
|
|
|
55
59
|
return useMemo(
|
|
56
60
|
(): CustomInputMap => ({
|
|
57
61
|
// Function selector.
|
|
58
|
-
['function' satisfies keyof
|
|
62
|
+
['function' satisfies keyof FunctionTrigger]: (props) => {
|
|
59
63
|
const getValue = useCallback(() => {
|
|
60
64
|
const formValue = props.getValue();
|
|
61
65
|
if (Ref.isRef(formValue)) {
|
|
@@ -86,14 +90,30 @@ const useCustomInputs = (space: Space, onQueryRefOptions: FunctionInputEditorPro
|
|
|
86
90
|
},
|
|
87
91
|
|
|
88
92
|
// Spec selector.
|
|
89
|
-
['spec.kind' as const]: SpecSelector
|
|
93
|
+
['spec.kind' as const]: (props) => <SpecSelector {...props} readonly={readonlySpec ? 'disabled-input' : false} />,
|
|
94
|
+
|
|
95
|
+
// TODO(wittjosiah): Copied from ViewEditor.
|
|
96
|
+
// Query input editor.
|
|
97
|
+
['spec.query' as const]: (props) => {
|
|
98
|
+
const handleChange = useCallback(
|
|
99
|
+
(query: Query.Any) => props.onValueChange('object', { ast: query.ast }),
|
|
100
|
+
[props.onValueChange],
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<Input.Root>
|
|
105
|
+
<InputHeader label={props.label} />
|
|
106
|
+
<QueryForm initialQuery={(props.getValue() as any).ast} types={types} tags={tags} onChange={handleChange} />
|
|
107
|
+
</Input.Root>
|
|
108
|
+
);
|
|
109
|
+
},
|
|
90
110
|
|
|
91
111
|
// Function input editor.
|
|
92
112
|
['input' as const]: (props) => (
|
|
93
113
|
<FunctionInputEditor {...props} functions={functions} onQueryRefOptions={onQueryRefOptions} />
|
|
94
114
|
),
|
|
95
115
|
}),
|
|
96
|
-
[workflows, scripts, functions],
|
|
116
|
+
[workflows, scripts, functions, readonlySpec],
|
|
97
117
|
);
|
|
98
118
|
};
|
|
99
119
|
|