@dxos/plugin-automation 0.8.1-main.ae460ac → 0.8.1-staging.31c3ee1
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-ITYXSN5Z.mjs → AutomationPanel-YAHFXQX6.mjs} +28 -21
- package/dist/lib/browser/AutomationPanel-YAHFXQX6.mjs.map +7 -0
- package/dist/lib/browser/app-graph-builder-K3BIQFWW.mjs +40 -0
- package/dist/lib/browser/app-graph-builder-K3BIQFWW.mjs.map +7 -0
- package/dist/lib/browser/chunk-FALBBJNO.mjs +138 -0
- package/dist/lib/browser/chunk-FALBBJNO.mjs.map +7 -0
- package/dist/lib/browser/chunk-MT3FZH4V.mjs +8 -0
- package/dist/lib/browser/{chunk-OFDNNRLE.mjs → chunk-WKKQV4PC.mjs} +2 -2
- package/dist/lib/browser/chunk-WKKQV4PC.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +33 -18
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-4QQSJR4A.mjs +42 -0
- package/dist/lib/browser/react-surface-4QQSJR4A.mjs.map +7 -0
- package/dist/lib/node/{AutomationPanel-X33HHDMQ.cjs → AutomationPanel-ZKAMIU6O.cjs} +36 -29
- package/dist/lib/node/AutomationPanel-ZKAMIU6O.cjs.map +7 -0
- package/dist/lib/node/app-graph-builder-HO4FPGZ5.cjs +56 -0
- package/dist/lib/node/app-graph-builder-HO4FPGZ5.cjs.map +7 -0
- package/dist/lib/node/{chunk-ORMEYEBE.cjs → chunk-7GXNXMSM.cjs} +4 -4
- package/dist/lib/node/chunk-7GXNXMSM.cjs.map +7 -0
- package/dist/lib/node/{chunk-CB5OB6JH.cjs → chunk-AGJ6XTDN.cjs} +5 -5
- package/dist/lib/node/chunk-FTEDH5Q6.cjs +167 -0
- package/dist/lib/node/chunk-FTEDH5Q6.cjs.map +7 -0
- package/dist/lib/node/index.cjs +40 -25
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/{react-surface-2WRVAPGR.cjs → react-surface-52M54VWV.cjs} +28 -13
- package/dist/lib/node/react-surface-52M54VWV.cjs.map +7 -0
- package/dist/lib/node-esm/{AutomationPanel-HY3GB4BT.mjs → AutomationPanel-XF7YPSKM.mjs} +28 -21
- package/dist/lib/node-esm/AutomationPanel-XF7YPSKM.mjs.map +7 -0
- package/dist/lib/node-esm/app-graph-builder-XCJR33VS.mjs +41 -0
- package/dist/lib/node-esm/app-graph-builder-XCJR33VS.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-6MUUH67V.mjs → chunk-DZ44LGYT.mjs} +2 -2
- package/dist/lib/node-esm/chunk-DZ44LGYT.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-M4QXMIIB.mjs +139 -0
- package/dist/lib/node-esm/chunk-M4QXMIIB.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-OA75PSGH.mjs +10 -0
- package/dist/lib/node-esm/index.mjs +33 -18
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/react-surface-MGKM3OO3.mjs +43 -0
- package/dist/lib/node-esm/react-surface-MGKM3OO3.mjs.map +7 -0
- package/dist/types/src/AutomationPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts +181 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +177 -1
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +2 -1
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts +3 -2
- package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -7
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +5 -3
- package/dist/types/src/translations.d.ts.map +1 -1
- package/package.json +24 -20
- package/src/AutomationPlugin.tsx +15 -6
- package/src/capabilities/app-graph-builder.ts +31 -0
- package/src/capabilities/index.ts +1 -1
- package/src/capabilities/react-surface.tsx +22 -7
- package/src/components/AutomationPanel/AutomationPanel.stories.tsx +1 -1
- package/src/components/AutomationPanel/AutomationPanel.tsx +60 -56
- package/src/components/TriggerEditor/TriggerEditor.stories.tsx +1 -1
- package/src/components/TriggerEditor/TriggerEditor.tsx +90 -81
- package/src/meta.ts +2 -2
- package/src/translations.ts +6 -4
- package/dist/lib/browser/AutomationPanel-ITYXSN5Z.mjs.map +0 -7
- package/dist/lib/browser/chunk-OFDNNRLE.mjs.map +0 -7
- package/dist/lib/browser/chunk-U7QLNY2S.mjs +0 -8
- package/dist/lib/browser/chunk-WY2C7JY4.mjs +0 -119
- package/dist/lib/browser/chunk-WY2C7JY4.mjs.map +0 -7
- package/dist/lib/browser/complementary-panel-4CPOJL4Y.mjs +0 -56
- package/dist/lib/browser/complementary-panel-4CPOJL4Y.mjs.map +0 -7
- package/dist/lib/browser/react-surface-SAPMN4PF.mjs +0 -27
- package/dist/lib/browser/react-surface-SAPMN4PF.mjs.map +0 -7
- package/dist/lib/node/AutomationPanel-X33HHDMQ.cjs.map +0 -7
- package/dist/lib/node/chunk-7Q5SNGCL.cjs +0 -148
- package/dist/lib/node/chunk-7Q5SNGCL.cjs.map +0 -7
- package/dist/lib/node/chunk-ORMEYEBE.cjs.map +0 -7
- package/dist/lib/node/complementary-panel-ZYJJ42ZU.cjs +0 -72
- package/dist/lib/node/complementary-panel-ZYJJ42ZU.cjs.map +0 -7
- package/dist/lib/node/react-surface-2WRVAPGR.cjs.map +0 -7
- package/dist/lib/node-esm/AutomationPanel-HY3GB4BT.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-6MUUH67V.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-R3P2WPBQ.mjs +0 -10
- package/dist/lib/node-esm/chunk-UDD2VA6G.mjs +0 -120
- package/dist/lib/node-esm/chunk-UDD2VA6G.mjs.map +0 -7
- package/dist/lib/node-esm/complementary-panel-S42RIIAY.mjs +0 -57
- package/dist/lib/node-esm/complementary-panel-S42RIIAY.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-QWLPOYXO.mjs +0 -28
- package/dist/lib/node-esm/react-surface-QWLPOYXO.mjs.map +0 -7
- package/dist/types/src/capabilities/complementary-panel.d.ts +0 -4
- package/dist/types/src/capabilities/complementary-panel.d.ts.map +0 -1
- package/src/capabilities/complementary-panel.ts +0 -56
- /package/dist/lib/browser/{chunk-U7QLNY2S.mjs.map → chunk-MT3FZH4V.mjs.map} +0 -0
- /package/dist/lib/node/{chunk-CB5OB6JH.cjs.map → chunk-AGJ6XTDN.cjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-R3P2WPBQ.mjs.map → chunk-OA75PSGH.mjs.map} +0 -0
|
@@ -5,18 +5,33 @@
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
7
|
import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
|
|
8
|
-
import {
|
|
8
|
+
import { isInstanceOf } from '@dxos/echo-schema';
|
|
9
|
+
import { ScriptType } from '@dxos/functions/types';
|
|
10
|
+
import { getSpace, isSpace, type Space } from '@dxos/react-client/echo';
|
|
11
|
+
import { StackItem } from '@dxos/react-ui-stack';
|
|
9
12
|
|
|
10
13
|
import { AutomationPanel } from '../components';
|
|
11
|
-
import {
|
|
14
|
+
import { meta } from '../meta';
|
|
12
15
|
|
|
13
16
|
export default () =>
|
|
14
17
|
contributes(Capabilities.ReactSurface, [
|
|
15
18
|
createSurface({
|
|
16
|
-
id: `${
|
|
17
|
-
role: '
|
|
18
|
-
filter: (data): data is { subject:
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
id: `${meta.id}/automation`,
|
|
20
|
+
role: 'space-settings--automation',
|
|
21
|
+
filter: (data): data is { subject: Space } => isSpace(data.subject),
|
|
22
|
+
component: ({ data }) => <AutomationPanel space={data.subject} />,
|
|
23
|
+
}),
|
|
24
|
+
createSurface({
|
|
25
|
+
id: `${meta.id}/companion/automation`,
|
|
26
|
+
role: 'article',
|
|
27
|
+
filter: (data): data is { companionTo: ScriptType; subject: 'automation' } =>
|
|
28
|
+
isInstanceOf(ScriptType, data.companionTo) && data.subject === 'automation',
|
|
29
|
+
component: ({ data, role }) => {
|
|
30
|
+
return (
|
|
31
|
+
<StackItem.Content role={role}>
|
|
32
|
+
<AutomationPanel space={getSpace(data.companionTo)!} object={data.companionTo} />
|
|
33
|
+
</StackItem.Content>
|
|
34
|
+
);
|
|
35
|
+
},
|
|
21
36
|
}),
|
|
22
37
|
]);
|
|
@@ -7,7 +7,7 @@ import '@dxos-theme';
|
|
|
7
7
|
import { type Meta } from '@storybook/react';
|
|
8
8
|
import React from 'react';
|
|
9
9
|
|
|
10
|
-
import { FunctionType, FunctionTrigger } from '@dxos/functions';
|
|
10
|
+
import { FunctionType, FunctionTrigger } from '@dxos/functions/types';
|
|
11
11
|
import { create, useSpaces } from '@dxos/react-client/echo';
|
|
12
12
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
13
13
|
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
@@ -12,11 +12,13 @@ import {
|
|
|
12
12
|
TriggerKind,
|
|
13
13
|
type FunctionTriggerType,
|
|
14
14
|
ScriptType,
|
|
15
|
-
} from '@dxos/functions';
|
|
15
|
+
} from '@dxos/functions/types';
|
|
16
16
|
import { type Client, useClient } from '@dxos/react-client';
|
|
17
17
|
import { create, Filter, useQuery, type Space, type ReactiveObject, getSpace } from '@dxos/react-client/echo';
|
|
18
|
-
import { Clipboard, IconButton, Input, useTranslation } from '@dxos/react-ui';
|
|
18
|
+
import { Clipboard, IconButton, Input, Separator, useTranslation } from '@dxos/react-ui';
|
|
19
|
+
import { ControlItem, controlItemClasses } from '@dxos/react-ui-form';
|
|
19
20
|
import { List } from '@dxos/react-ui-list';
|
|
21
|
+
import { StackItem } from '@dxos/react-ui-stack';
|
|
20
22
|
import { ghostHover, mx } from '@dxos/react-ui-theme';
|
|
21
23
|
|
|
22
24
|
import { AUTOMATION_PLUGIN } from '../../meta';
|
|
@@ -47,7 +49,7 @@ export const AutomationPanel = ({ space, object }: AutomationPanelProps) => {
|
|
|
47
49
|
};
|
|
48
50
|
|
|
49
51
|
const handleAdd = () => {
|
|
50
|
-
setTrigger(create(FunctionTriggerSchema, {
|
|
52
|
+
setTrigger(create(FunctionTriggerSchema, {}));
|
|
51
53
|
setSelected(undefined);
|
|
52
54
|
};
|
|
53
55
|
|
|
@@ -74,60 +76,62 @@ export const AutomationPanel = ({ space, object }: AutomationPanelProps) => {
|
|
|
74
76
|
|
|
75
77
|
return (
|
|
76
78
|
<Clipboard.Provider>
|
|
77
|
-
<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
{(
|
|
81
|
-
<
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
<
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
</Input.Root>
|
|
96
|
-
|
|
97
|
-
<div className={'flex'}>
|
|
98
|
-
<List.ItemTitle
|
|
99
|
-
classNames='px-1 cursor-pointer w-0 shrink truncate'
|
|
100
|
-
onClick={() => handleSelect(trigger)}
|
|
79
|
+
<StackItem.Content classNames='block overflow-y-auto'>
|
|
80
|
+
<div className='flex flex-col w-full'>
|
|
81
|
+
{trigger ? (
|
|
82
|
+
<ControlItem title={t('trigger editor title')}>
|
|
83
|
+
<TriggerEditor space={space} trigger={trigger} onSave={handleSave} onCancel={handleCancel} />
|
|
84
|
+
</ControlItem>
|
|
85
|
+
) : (
|
|
86
|
+
<div role='none' className={controlItemClasses}>
|
|
87
|
+
<List.Root<FunctionTrigger> items={triggers} isItem={S.is(FunctionTrigger)} getId={(field) => field.id}>
|
|
88
|
+
{({ items: triggers }) => (
|
|
89
|
+
<div role='list' className='flex flex-col w-full'>
|
|
90
|
+
{triggers?.map((trigger) => {
|
|
91
|
+
const copyAction = getCopyAction(client, trigger);
|
|
92
|
+
return (
|
|
93
|
+
<List.Item<FunctionTrigger>
|
|
94
|
+
key={trigger.id}
|
|
95
|
+
item={trigger}
|
|
96
|
+
classNames={mx(grid, ghostHover, 'items-center', 'px-2')}
|
|
101
97
|
>
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
98
|
+
<Input.Root>
|
|
99
|
+
<Input.Switch
|
|
100
|
+
checked={trigger.enabled}
|
|
101
|
+
onCheckedChange={(checked) => (trigger.enabled = checked)}
|
|
102
|
+
/>
|
|
103
|
+
</Input.Root>
|
|
104
|
+
|
|
105
|
+
<div className={'flex'}>
|
|
106
|
+
<List.ItemTitle
|
|
107
|
+
classNames='px-1 cursor-pointer w-0 shrink truncate'
|
|
108
|
+
onClick={() => handleSelect(trigger)}
|
|
109
|
+
>
|
|
110
|
+
{getFunctionName(scripts, functions, trigger) ?? '∅'}
|
|
111
|
+
</List.ItemTitle>
|
|
112
|
+
|
|
113
|
+
{/* TODO: a better way to expose copy action */}
|
|
114
|
+
{copyAction && (
|
|
115
|
+
<Clipboard.IconButton
|
|
116
|
+
label={t(copyAction.translationKey)}
|
|
117
|
+
value={copyAction.contentProvider()}
|
|
118
|
+
/>
|
|
119
|
+
)}
|
|
120
|
+
</div>
|
|
121
|
+
|
|
122
|
+
<List.ItemDeleteButton onClick={() => handleDelete(trigger)} />
|
|
123
|
+
</List.Item>
|
|
124
|
+
);
|
|
125
|
+
})}
|
|
126
|
+
</div>
|
|
127
|
+
)}
|
|
128
|
+
</List.Root>
|
|
129
|
+
{triggers.length > 0 && <Separator classNames='mlb-4' />}
|
|
130
|
+
<IconButton icon='ph--plus--regular' label={t('new trigger label')} onClick={handleAdd} />
|
|
131
|
+
</div>
|
|
132
|
+
)}
|
|
133
|
+
</div>
|
|
134
|
+
</StackItem.Content>
|
|
131
135
|
</Clipboard.Provider>
|
|
132
136
|
);
|
|
133
137
|
};
|
|
@@ -7,7 +7,7 @@ import '@dxos-theme';
|
|
|
7
7
|
import { type Meta } from '@storybook/react';
|
|
8
8
|
import React, { useEffect, useState } from 'react';
|
|
9
9
|
|
|
10
|
-
import { FunctionType, FunctionTrigger, TriggerKind } from '@dxos/functions';
|
|
10
|
+
import { FunctionType, FunctionTrigger, TriggerKind } from '@dxos/functions/types';
|
|
11
11
|
import { create } from '@dxos/live-object';
|
|
12
12
|
import { useSpaces } from '@dxos/react-client/echo';
|
|
13
13
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, { useEffect, useState } from 'react';
|
|
5
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
6
6
|
|
|
7
7
|
import { ComputeGraph } from '@dxos/conductor';
|
|
8
8
|
import {
|
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
type FunctionTrigger,
|
|
13
13
|
ScriptType,
|
|
14
14
|
TriggerKind,
|
|
15
|
-
} from '@dxos/functions';
|
|
15
|
+
} from '@dxos/functions/types';
|
|
16
16
|
import { Filter, useQuery, type Space } from '@dxos/react-client/echo';
|
|
17
17
|
import { IconButton, Input, useTranslation } from '@dxos/react-ui';
|
|
18
|
-
import { Form, SelectInput, TextInput } from '@dxos/react-ui-form';
|
|
18
|
+
import { type CustomInputMap, Form, type InputProps, SelectInput, TextInput, useInputProps } from '@dxos/react-ui-form';
|
|
19
19
|
|
|
20
20
|
import { AUTOMATION_PLUGIN } from '../../meta';
|
|
21
21
|
|
|
@@ -26,6 +26,30 @@ export type TriggerEditorProps = {
|
|
|
26
26
|
onCancel?: () => void;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
const PayloadInput = (props: InputProps & { property: string }) => {
|
|
30
|
+
const { t } = useTranslation(AUTOMATION_PLUGIN);
|
|
31
|
+
// TODO(dmaretskyi): Prop name (`meta`) should be passed in.
|
|
32
|
+
const inputProps = useInputProps(['meta', props.property]);
|
|
33
|
+
return (
|
|
34
|
+
<div role='none' className='flex items-center mt-2 gap-1'>
|
|
35
|
+
<div role='none' className='flex-1'>
|
|
36
|
+
<TextInput {...inputProps} type='string' label={props.property} />
|
|
37
|
+
</div>
|
|
38
|
+
<IconButton
|
|
39
|
+
icon='ph--trash--regular'
|
|
40
|
+
iconOnly
|
|
41
|
+
classNames={'mt-6'}
|
|
42
|
+
label={t('trigger meta remove')}
|
|
43
|
+
onClick={() => {
|
|
44
|
+
const newValues: any = { ...props.getValue() };
|
|
45
|
+
delete newValues[props.property];
|
|
46
|
+
props.onValueChange('object', newValues);
|
|
47
|
+
}}
|
|
48
|
+
/>
|
|
49
|
+
</div>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
29
53
|
export const TriggerEditor = ({ space, trigger, onSave, onCancel }: TriggerEditorProps) => {
|
|
30
54
|
const { t } = useTranslation(AUTOMATION_PLUGIN);
|
|
31
55
|
|
|
@@ -37,90 +61,75 @@ export const TriggerEditor = ({ space, trigger, onSave, onCancel }: TriggerEdito
|
|
|
37
61
|
onSave?.(values);
|
|
38
62
|
};
|
|
39
63
|
|
|
64
|
+
const Custom = useMemo(
|
|
65
|
+
(): CustomInputMap => ({
|
|
66
|
+
['function' satisfies keyof FunctionTriggerType]: (props) => (
|
|
67
|
+
<SelectInput
|
|
68
|
+
{...props}
|
|
69
|
+
options={getWorkflowOptions(workflows).concat(getFunctionOptions(scripts, functions))}
|
|
70
|
+
/>
|
|
71
|
+
),
|
|
72
|
+
['spec.type' as const]: (props) => (
|
|
73
|
+
<SelectInput
|
|
74
|
+
{...props}
|
|
75
|
+
options={Object.values(TriggerKind).map((kind) => ({
|
|
76
|
+
value: kind,
|
|
77
|
+
label: t(`trigger type ${kind}`),
|
|
78
|
+
}))}
|
|
79
|
+
/>
|
|
80
|
+
),
|
|
81
|
+
// TODO(wittjosiah): Form should be able to handle arbitrary records by default.
|
|
82
|
+
['meta' as const]: (props) => {
|
|
83
|
+
const payload = props.getValue() ?? {};
|
|
84
|
+
useEffect(() => props.onValueChange('object', { ...payload }), []);
|
|
85
|
+
const [newPayloadFieldName, setNewPayloadFieldName] = useState('');
|
|
86
|
+
|
|
87
|
+
const handleAddPayload = useCallback(() => {
|
|
88
|
+
if (newPayloadFieldName.length) {
|
|
89
|
+
const payload = props.getValue() ?? {};
|
|
90
|
+
const payloadWithNewProp = { ...payload, [newPayloadFieldName]: '' };
|
|
91
|
+
setNewPayloadFieldName('');
|
|
92
|
+
props.onValueChange('object', payloadWithNewProp);
|
|
93
|
+
}
|
|
94
|
+
}, [newPayloadFieldName, props.getValue, props.onValueChange]);
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<>
|
|
98
|
+
<div>{/* TODO(wittjosiah): props.label */ 'Payload'}</div>
|
|
99
|
+
{[...Object.keys(payload)].map((key) => (
|
|
100
|
+
<PayloadInput key={key} property={key} {...props} />
|
|
101
|
+
))}
|
|
102
|
+
<div role='none' className='flex items-center mt-2 gap-1 plb-1'>
|
|
103
|
+
<div role='none' className='flex-1'>
|
|
104
|
+
<Input.Root>
|
|
105
|
+
<Input.TextInput
|
|
106
|
+
placeholder={t('trigger payload prop name placeholder')}
|
|
107
|
+
value={newPayloadFieldName}
|
|
108
|
+
onChange={(event) => setNewPayloadFieldName(event.target.value)}
|
|
109
|
+
/>
|
|
110
|
+
</Input.Root>
|
|
111
|
+
</div>
|
|
112
|
+
<IconButton
|
|
113
|
+
icon='ph--plus--regular'
|
|
114
|
+
iconOnly
|
|
115
|
+
label={t('trigger payload add')}
|
|
116
|
+
onClick={handleAddPayload}
|
|
117
|
+
/>
|
|
118
|
+
</div>
|
|
119
|
+
</>
|
|
120
|
+
);
|
|
121
|
+
},
|
|
122
|
+
}),
|
|
123
|
+
[workflows, scripts, functions, t],
|
|
124
|
+
);
|
|
125
|
+
|
|
40
126
|
return (
|
|
41
127
|
<Form<FunctionTriggerType>
|
|
42
128
|
schema={FunctionTriggerSchema}
|
|
43
129
|
values={trigger}
|
|
44
130
|
onSave={handleSave}
|
|
45
131
|
onCancel={onCancel}
|
|
46
|
-
Custom={
|
|
47
|
-
['function' satisfies keyof FunctionTriggerType]: (props) => (
|
|
48
|
-
<SelectInput
|
|
49
|
-
{...props}
|
|
50
|
-
options={getWorkflowOptions(workflows).concat(getFunctionOptions(scripts, functions))}
|
|
51
|
-
/>
|
|
52
|
-
),
|
|
53
|
-
['spec.type' as const]: (props) => (
|
|
54
|
-
<SelectInput
|
|
55
|
-
{...props}
|
|
56
|
-
options={Object.values(TriggerKind).map((kind) => ({
|
|
57
|
-
value: kind,
|
|
58
|
-
label: t(`trigger type ${kind}`),
|
|
59
|
-
}))}
|
|
60
|
-
/>
|
|
61
|
-
),
|
|
62
|
-
['meta' as const]: (props) => {
|
|
63
|
-
const meta = props.getValue()!;
|
|
64
|
-
useEffect(() => props.onValueChange('object', { ...meta }), []);
|
|
65
|
-
const [newMetaFieldName, setNewMetaFieldName] = useState('');
|
|
66
|
-
|
|
67
|
-
return (
|
|
68
|
-
<>
|
|
69
|
-
<div>{props.label}</div>
|
|
70
|
-
{[...Object.keys(meta)].map((key) => {
|
|
71
|
-
const compositeKey: any = `meta.${key}`;
|
|
72
|
-
return (
|
|
73
|
-
<div key={compositeKey} role='none' className='flex items-center mt-2 gap-1'>
|
|
74
|
-
<div role='none' className='flex-1'>
|
|
75
|
-
<TextInput
|
|
76
|
-
{...props}
|
|
77
|
-
getValue={() => (props.getValue() as any)[key]}
|
|
78
|
-
type={'string'}
|
|
79
|
-
label={key}
|
|
80
|
-
/>
|
|
81
|
-
</div>
|
|
82
|
-
<IconButton
|
|
83
|
-
icon='ph--trash--regular'
|
|
84
|
-
iconOnly
|
|
85
|
-
classNames={'mt-6'}
|
|
86
|
-
label={t('trigger meta remove')}
|
|
87
|
-
onClick={() => {
|
|
88
|
-
const newValues: any = { ...props.getValue() };
|
|
89
|
-
delete newValues[key];
|
|
90
|
-
props.onValueChange('object', newValues);
|
|
91
|
-
}}
|
|
92
|
-
/>
|
|
93
|
-
</div>
|
|
94
|
-
);
|
|
95
|
-
})}
|
|
96
|
-
<div role='none' className='flex items-center mt-2 gap-1 plb-1'>
|
|
97
|
-
<div role='none' className='flex-1'>
|
|
98
|
-
<Input.Root>
|
|
99
|
-
<Input.TextInput
|
|
100
|
-
placeholder={t('trigger meta prop name placeholder')}
|
|
101
|
-
value={newMetaFieldName}
|
|
102
|
-
onChange={(event) => setNewMetaFieldName(event.target.value)}
|
|
103
|
-
/>
|
|
104
|
-
</Input.Root>
|
|
105
|
-
</div>
|
|
106
|
-
<IconButton
|
|
107
|
-
icon='ph--plus--regular'
|
|
108
|
-
iconOnly
|
|
109
|
-
label={t('trigger meta add')}
|
|
110
|
-
onClick={() => {
|
|
111
|
-
if (newMetaFieldName.length) {
|
|
112
|
-
const meta = props.getValue() ?? {};
|
|
113
|
-
const metaWithNewProp = { ...meta, [newMetaFieldName]: '' };
|
|
114
|
-
setNewMetaFieldName('');
|
|
115
|
-
props.onValueChange('object', metaWithNewProp);
|
|
116
|
-
}
|
|
117
|
-
}}
|
|
118
|
-
/>
|
|
119
|
-
</div>
|
|
120
|
-
</>
|
|
121
|
-
);
|
|
122
|
-
},
|
|
123
|
-
}}
|
|
132
|
+
Custom={Custom}
|
|
124
133
|
/>
|
|
125
134
|
);
|
|
126
135
|
};
|
package/src/meta.ts
CHANGED
|
@@ -6,11 +6,11 @@ import { type PluginMeta } from '@dxos/app-framework';
|
|
|
6
6
|
|
|
7
7
|
export const AUTOMATION_PLUGIN = 'dxos.org/plugin/automation';
|
|
8
8
|
|
|
9
|
-
export const meta = {
|
|
9
|
+
export const meta: PluginMeta = {
|
|
10
10
|
id: AUTOMATION_PLUGIN,
|
|
11
11
|
name: 'Automation',
|
|
12
12
|
description:
|
|
13
13
|
'The Automation tab allows you to trigger pre-defined workflows related to the element you are interacting with inside of Composer.',
|
|
14
14
|
icon: 'ph--robot--regular',
|
|
15
15
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/experimental/plugin-automation',
|
|
16
|
-
}
|
|
16
|
+
};
|
package/src/translations.ts
CHANGED
|
@@ -10,8 +10,10 @@ export default [
|
|
|
10
10
|
[AUTOMATION_PLUGIN]: {
|
|
11
11
|
'plugin name': 'Automation',
|
|
12
12
|
'automation panel label': 'Automations',
|
|
13
|
+
'script automation label': 'Automation',
|
|
13
14
|
|
|
14
|
-
'
|
|
15
|
+
'trigger editor title': 'New Trigger',
|
|
16
|
+
'new trigger label': 'Add Trigger',
|
|
15
17
|
'trigger type timer': 'Timer',
|
|
16
18
|
'trigger type webhook': 'Webhook',
|
|
17
19
|
'trigger type websocket': 'Websocket',
|
|
@@ -22,9 +24,9 @@ export default [
|
|
|
22
24
|
'trigger copy url': 'Copy URL',
|
|
23
25
|
'trigger copy email': 'Copy Email',
|
|
24
26
|
|
|
25
|
-
'trigger
|
|
26
|
-
'trigger
|
|
27
|
-
'trigger
|
|
27
|
+
'trigger payload add': 'Add',
|
|
28
|
+
'trigger payload remove': 'Remove',
|
|
29
|
+
'trigger payload prop name placeholder': 'New payload property name',
|
|
28
30
|
},
|
|
29
31
|
},
|
|
30
32
|
},
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/AutomationPanel/AutomationPanel.tsx", "../../../src/components/AutomationPanel/index.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useState } from 'react';\n\nimport { S } from '@dxos/echo-schema';\nimport {\n FunctionType,\n FunctionTrigger,\n FunctionTriggerSchema,\n TriggerKind,\n type FunctionTriggerType,\n ScriptType,\n} from '@dxos/functions';\nimport { type Client, useClient } from '@dxos/react-client';\nimport { create, Filter, useQuery, type Space, type ReactiveObject, getSpace } from '@dxos/react-client/echo';\nimport { Clipboard, IconButton, Input, useTranslation } from '@dxos/react-ui';\nimport { List } from '@dxos/react-ui-list';\nimport { ghostHover, mx } from '@dxos/react-ui-theme';\n\nimport { AUTOMATION_PLUGIN } from '../../meta';\nimport { TriggerEditor, type TriggerEditorProps } from '../TriggerEditor';\n\nconst grid = 'grid grid-cols-[40px_1fr_32px] min-bs-[2.5rem]';\n\nexport type AutomationPanelProps = {\n space: Space;\n object?: ReactiveObject<any>;\n};\n\n// TODO(burdon): Factor out common layout with ViewEditor.\nexport const AutomationPanel = ({ space, object }: AutomationPanelProps) => {\n const { t } = useTranslation(AUTOMATION_PLUGIN);\n const client = useClient();\n const triggers = useQuery(space, Filter.schema(FunctionTrigger));\n const functions = useQuery(space, Filter.schema(FunctionType));\n const scripts = useQuery(space, Filter.schema(ScriptType));\n\n const [trigger, setTrigger] = useState<FunctionTriggerType>();\n const [selected, setSelected] = useState<FunctionTrigger>();\n\n const handleSelect = (trigger: FunctionTrigger) => {\n const { id: _, ...values } = trigger;\n setTrigger(values);\n setSelected(trigger);\n };\n\n const handleAdd = () => {\n setTrigger(create(FunctionTriggerSchema, { meta: {} }));\n setSelected(undefined);\n };\n\n const handleDelete = (trigger: FunctionTrigger) => {\n space.db.remove(trigger);\n setTrigger(undefined);\n setSelected(undefined);\n };\n\n const handleSave: TriggerEditorProps['onSave'] = (trigger) => {\n if (selected) {\n Object.assign(selected, trigger);\n } else {\n space.db.add(create(FunctionTrigger, trigger));\n }\n\n setTrigger(undefined);\n setSelected(undefined);\n };\n\n const handleCancel: TriggerEditorProps['onCancel'] = () => {\n setTrigger(undefined);\n };\n\n return (\n <Clipboard.Provider>\n <div className='flex flex-col w-full'>\n {!trigger && (\n <List.Root<FunctionTrigger> items={triggers} isItem={S.is(FunctionTrigger)} getId={(field) => field.id}>\n {({ items: triggers }) => (\n <div role='list' className='flex flex-col w-full'>\n {triggers?.map((trigger) => {\n const copyAction = getCopyAction(client, trigger);\n return (\n <List.Item<FunctionTrigger>\n key={trigger.id}\n item={trigger}\n classNames={mx(grid, ghostHover, 'items-center', 'px-2')}\n >\n <Input.Root>\n <Input.Switch\n checked={trigger.enabled}\n onCheckedChange={(checked) => (trigger.enabled = checked)}\n />\n </Input.Root>\n\n <div className={'flex'}>\n <List.ItemTitle\n classNames='px-1 cursor-pointer w-0 shrink truncate'\n onClick={() => handleSelect(trigger)}\n >\n {getFunctionName(scripts, functions, trigger) ?? '∅'}\n </List.ItemTitle>\n\n {/* TODO: a better way to expose copy action */}\n {copyAction && (\n <Clipboard.IconButton\n label={t(copyAction.translationKey)}\n value={copyAction.contentProvider()}\n />\n )}\n </div>\n\n <List.ItemDeleteButton onClick={() => handleDelete(trigger)} />\n </List.Item>\n );\n })}\n </div>\n )}\n </List.Root>\n )}\n\n {trigger && <TriggerEditor space={space} trigger={trigger} onSave={handleSave} onCancel={handleCancel} />}\n\n {!trigger && (\n <div className='flex p-2 justify-center'>\n <IconButton icon='ph--plus--regular' label={t('new trigger label')} onClick={handleAdd} />\n </div>\n )}\n </div>\n </Clipboard.Provider>\n );\n};\n\nconst getCopyAction = (client: Client, trigger: FunctionTrigger | undefined) => {\n if (trigger?.spec?.type === TriggerKind.Email) {\n return { translationKey: 'trigger copy email', contentProvider: () => `${getSpace(trigger)!.id}@dxos.network` };\n }\n\n if (trigger?.spec?.type === TriggerKind.Webhook) {\n return { translationKey: 'trigger copy url', contentProvider: () => getWebhookUrl(client, trigger) };\n }\n\n return undefined;\n};\n\nconst getWebhookUrl = (client: Client, trigger: FunctionTrigger) => {\n const spaceId = getSpace(trigger)!.id;\n const edgeUrl = new URL(client.config.values.runtime!.services!.edge!.url!);\n const isSecure = edgeUrl.protocol.startsWith('https') || edgeUrl.protocol.startsWith('wss');\n edgeUrl.protocol = isSecure ? 'https' : 'http';\n return new URL(`/webhook/${spaceId}:${trigger.id}`, edgeUrl).toString();\n};\n\nconst getFunctionName = (scripts: ScriptType[], functions: FunctionType[], trigger: FunctionTriggerType) => {\n // TODO(wittjosiah): Truncation should be done in the UI.\n // Warning that the List component is currently a can of worms.\n const shortId = trigger.function && `${trigger.function?.slice(0, 16)}…`;\n const functionObject = functions.find((fn) => `dxn:worker:${fn.name}` === trigger.function);\n if (!functionObject) {\n return shortId;\n }\n return scripts.find((s) => functionObject.source?.target?.id === s.id)?.name ?? shortId;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AutomationPanel } from './AutomationPanel';\n\nexport default AutomationPanel;\n"],
|
|
5
|
-
"mappings": "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",
|
|
6
|
-
"names": ["React", "useState", "S", "FunctionType", "FunctionTrigger", "FunctionTriggerSchema", "TriggerKind", "ScriptType", "useClient", "create", "Filter", "useQuery", "getSpace", "Clipboard", "IconButton", "Input", "useTranslation", "List", "ghostHover", "mx", "grid", "AutomationPanel", "space", "object", "t", "useTranslation", "AUTOMATION_PLUGIN", "client", "useClient", "triggers", "useQuery", "Filter", "schema", "FunctionTrigger", "functions", "FunctionType", "scripts", "ScriptType", "trigger", "setTrigger", "useState", "selected", "setSelected", "handleSelect", "id", "_", "values", "handleAdd", "create", "FunctionTriggerSchema", "meta", "undefined", "handleDelete", "db", "remove", "handleSave", "Object", "assign", "add", "handleCancel", "Clipboard", "Provider", "div", "className", "List", "Root", "items", "isItem", "S", "is", "getId", "field", "role", "map", "copyAction", "getCopyAction", "Item", "key", "item", "classNames", "mx", "ghostHover", "Input", "Switch", "checked", "enabled", "onCheckedChange", "ItemTitle", "onClick", "getFunctionName", "IconButton", "label", "translationKey", "value", "contentProvider", "ItemDeleteButton", "TriggerEditor", "onSave", "onCancel", "icon", "spec", "type", "TriggerKind", "Email", "getSpace", "Webhook", "getWebhookUrl", "spaceId", "edgeUrl", "URL", "config", "runtime", "services", "edge", "url", "isSecure", "protocol", "startsWith", "toString", "shortId", "function", "slice", "functionObject", "find", "fn", "name", "s", "source", "target", "AutomationPanel"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/meta.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\n\nexport const AUTOMATION_PLUGIN = 'dxos.org/plugin/automation';\n\nexport const meta = {\n id: AUTOMATION_PLUGIN,\n name: 'Automation',\n description:\n 'The Automation tab allows you to trigger pre-defined workflows related to the element you are interacting with inside of Composer.',\n icon: 'ph--robot--regular',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/experimental/plugin-automation',\n} satisfies PluginMeta;\n"],
|
|
5
|
-
"mappings": ";AAMO,IAAMA,oBAAoB;AAE1B,IAAMC,OAAO;EAClBC,IAAIF;EACJG,MAAM;EACNC,aACE;EACFC,MAAM;EACNC,QAAQ;AACV;",
|
|
6
|
-
"names": ["AUTOMATION_PLUGIN", "meta", "id", "name", "description", "icon", "source"]
|
|
7
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// packages/plugins/experimental/plugin-automation/src/components/index.ts
|
|
2
|
-
import { lazy } from "react";
|
|
3
|
-
var AutomationPanel = lazy(() => import("./AutomationPanel-ITYXSN5Z.mjs"));
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
AutomationPanel
|
|
7
|
-
};
|
|
8
|
-
//# sourceMappingURL=chunk-U7QLNY2S.mjs.map
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AUTOMATION_PLUGIN
|
|
3
|
-
} from "./chunk-OFDNNRLE.mjs";
|
|
4
|
-
|
|
5
|
-
// packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/TriggerEditor.tsx
|
|
6
|
-
import React, { useEffect, useState } from "react";
|
|
7
|
-
import { ComputeGraph } from "@dxos/conductor";
|
|
8
|
-
import { FunctionType, FunctionTriggerSchema, ScriptType, TriggerKind } from "@dxos/functions";
|
|
9
|
-
import { Filter, useQuery } from "@dxos/react-client/echo";
|
|
10
|
-
import { IconButton, Input, useTranslation } from "@dxos/react-ui";
|
|
11
|
-
import { Form, SelectInput, TextInput } from "@dxos/react-ui-form";
|
|
12
|
-
var TriggerEditor = ({ space, trigger, onSave, onCancel }) => {
|
|
13
|
-
const { t } = useTranslation(AUTOMATION_PLUGIN);
|
|
14
|
-
const functions = useQuery(space, Filter.schema(FunctionType));
|
|
15
|
-
const workflows = useQuery(space, Filter.schema(ComputeGraph));
|
|
16
|
-
const scripts = useQuery(space, Filter.schema(ScriptType));
|
|
17
|
-
const handleSave = (values) => {
|
|
18
|
-
onSave?.(values);
|
|
19
|
-
};
|
|
20
|
-
return /* @__PURE__ */ React.createElement(Form, {
|
|
21
|
-
schema: FunctionTriggerSchema,
|
|
22
|
-
values: trigger,
|
|
23
|
-
onSave: handleSave,
|
|
24
|
-
onCancel,
|
|
25
|
-
Custom: {
|
|
26
|
-
["function"]: (props) => /* @__PURE__ */ React.createElement(SelectInput, {
|
|
27
|
-
...props,
|
|
28
|
-
options: getWorkflowOptions(workflows).concat(getFunctionOptions(scripts, functions))
|
|
29
|
-
}),
|
|
30
|
-
["spec.type"]: (props) => /* @__PURE__ */ React.createElement(SelectInput, {
|
|
31
|
-
...props,
|
|
32
|
-
options: Object.values(TriggerKind).map((kind) => ({
|
|
33
|
-
value: kind,
|
|
34
|
-
label: t(`trigger type ${kind}`)
|
|
35
|
-
}))
|
|
36
|
-
}),
|
|
37
|
-
["meta"]: (props) => {
|
|
38
|
-
const meta = props.getValue();
|
|
39
|
-
useEffect(() => props.onValueChange("object", {
|
|
40
|
-
...meta
|
|
41
|
-
}), []);
|
|
42
|
-
const [newMetaFieldName, setNewMetaFieldName] = useState("");
|
|
43
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", null, props.label), [
|
|
44
|
-
...Object.keys(meta)
|
|
45
|
-
].map((key) => {
|
|
46
|
-
const compositeKey = `meta.${key}`;
|
|
47
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
48
|
-
key: compositeKey,
|
|
49
|
-
role: "none",
|
|
50
|
-
className: "flex items-center mt-2 gap-1"
|
|
51
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
52
|
-
role: "none",
|
|
53
|
-
className: "flex-1"
|
|
54
|
-
}, /* @__PURE__ */ React.createElement(TextInput, {
|
|
55
|
-
...props,
|
|
56
|
-
getValue: () => props.getValue()[key],
|
|
57
|
-
type: "string",
|
|
58
|
-
label: key
|
|
59
|
-
})), /* @__PURE__ */ React.createElement(IconButton, {
|
|
60
|
-
icon: "ph--trash--regular",
|
|
61
|
-
iconOnly: true,
|
|
62
|
-
classNames: "mt-6",
|
|
63
|
-
label: t("trigger meta remove"),
|
|
64
|
-
onClick: () => {
|
|
65
|
-
const newValues = {
|
|
66
|
-
...props.getValue()
|
|
67
|
-
};
|
|
68
|
-
delete newValues[key];
|
|
69
|
-
props.onValueChange("object", newValues);
|
|
70
|
-
}
|
|
71
|
-
}));
|
|
72
|
-
}), /* @__PURE__ */ React.createElement("div", {
|
|
73
|
-
role: "none",
|
|
74
|
-
className: "flex items-center mt-2 gap-1 plb-1"
|
|
75
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
76
|
-
role: "none",
|
|
77
|
-
className: "flex-1"
|
|
78
|
-
}, /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.TextInput, {
|
|
79
|
-
placeholder: t("trigger meta prop name placeholder"),
|
|
80
|
-
value: newMetaFieldName,
|
|
81
|
-
onChange: (event) => setNewMetaFieldName(event.target.value)
|
|
82
|
-
}))), /* @__PURE__ */ React.createElement(IconButton, {
|
|
83
|
-
icon: "ph--plus--regular",
|
|
84
|
-
iconOnly: true,
|
|
85
|
-
label: t("trigger meta add"),
|
|
86
|
-
onClick: () => {
|
|
87
|
-
if (newMetaFieldName.length) {
|
|
88
|
-
const meta2 = props.getValue() ?? {};
|
|
89
|
-
const metaWithNewProp = {
|
|
90
|
-
...meta2,
|
|
91
|
-
[newMetaFieldName]: ""
|
|
92
|
-
};
|
|
93
|
-
setNewMetaFieldName("");
|
|
94
|
-
props.onValueChange("object", metaWithNewProp);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
})));
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
var getWorkflowOptions = (graphs) => {
|
|
103
|
-
return graphs.map((graph) => ({
|
|
104
|
-
label: `compute-${graph.id}`,
|
|
105
|
-
value: `dxn:echo:@:${graph.id}`
|
|
106
|
-
}));
|
|
107
|
-
};
|
|
108
|
-
var getFunctionOptions = (scripts, functions) => {
|
|
109
|
-
const getLabel = (fn) => scripts.find((s) => fn.source?.target?.id === s.id)?.name ?? fn.name;
|
|
110
|
-
return functions.map((fn) => ({
|
|
111
|
-
label: getLabel(fn),
|
|
112
|
-
value: `dxn:worker:${fn.name}`
|
|
113
|
-
}));
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export {
|
|
117
|
-
TriggerEditor
|
|
118
|
-
};
|
|
119
|
-
//# sourceMappingURL=chunk-WY2C7JY4.mjs.map
|