Skip to content

Commit 6d564d8

Browse files
convert create builders
1 parent 74c636e commit 6d564d8

File tree

9 files changed

+248
-77
lines changed

9 files changed

+248
-77
lines changed

src/cloud/components/Automations/EventInfo.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react'
2-
import { JsonTypeDef } from '../../lib/automations/events'
32

43
interface EventSelectProps {
54
name: string

src/cloud/components/Automations/PipeBuilder.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ const PipeBuilder = ({ pipe, onChange }: PipeBuilderProps) => {
3434
}, [pipe.event])
3535

3636
const action = useMemo(() => {
37+
if (pipe.configuration.type !== 'operation') {
38+
return SUPPORTED_ACTION_OPTIONS[0]
39+
}
40+
41+
const identifier = pipe.configuration.identifier
3742
return (
38-
SUPPORTED_ACTION_OPTIONS.find(({ value }) => value === pipe.action) ||
43+
SUPPORTED_ACTION_OPTIONS.find(({ value }) => value === identifier) ||
3944
SUPPORTED_ACTION_OPTIONS[0]
4045
)
41-
}, [pipe.action])
46+
}, [pipe.configuration])
4247

4348
return (
4449
<Container>
@@ -63,11 +68,7 @@ const PipeBuilder = ({ pipe, onChange }: PipeBuilderProps) => {
6368
</FormRowItem>
6469
</FormRow>
6570
<FormRow>
66-
{currentEvent != null ? (
67-
<EventInfo name={pipe.event} typeDef={currentEvent} />
68-
) : (
69-
<div>Select Event</div>
70-
)}
71+
<div>Select Event</div>
7172
</FormRow>
7273
</div>
7374

@@ -96,7 +97,19 @@ const PipeBuilder = ({ pipe, onChange }: PipeBuilderProps) => {
9697
<FormSelect
9798
options={SUPPORTED_ACTION_OPTIONS}
9899
value={action}
99-
onChange={({ value }) => onChange({ ...pipe, action: value })}
100+
onChange={({ value }) =>
101+
onChange({
102+
...pipe,
103+
configuration: {
104+
type: 'operation',
105+
identifier: value,
106+
input: {
107+
type: 'constructor',
108+
info: { type: 'struct', refs: {} },
109+
},
110+
},
111+
})
112+
}
100113
/>
101114
</FormRowItem>
102115
</FormRow>

src/cloud/components/Automations/actions/ActionConfigurationInput.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ import React, { useMemo, useState } from 'react'
22
import FormSelect from '../../../../design/components/molecules/Form/atoms/FormSelect'
33
import FormRowItem from '../../../../design/components/molecules/Form/templates/FormRowItem'
44
import { pickBy } from 'ramda'
5+
import { BoostAST } from '../../../lib/automations'
6+
import { RefNode } from '../../../lib/automations/ast'
57

68
const CONFIG_TYPES = [
79
{ label: 'Event', value: 'event' },
810
{ label: 'Custom', value: 'custom' },
911
]
1012

1113
interface ActionConfigurationInputProps {
12-
onChange: (value: any) => void
13-
value: any
14+
onChange: (value: BoostAST) => void
15+
value: BoostAST
1416
customInput: (
1517
onChange: ActionConfigurationInputProps['onChange'],
1618
value: any
@@ -26,11 +28,11 @@ const ActionConfigurationInput = ({
2628
type: dataType,
2729
}: ActionConfigurationInputProps) => {
2830
const [type, setType] = useState(() => {
29-
if (typeof value === 'string') {
30-
if (value.startsWith('$event')) {
31+
if (value.type === 'reference') {
32+
if (value.identifier.startsWith('$event')) {
3133
return CONFIG_TYPES[0]
3234
}
33-
if (value.startsWith('$env')) {
35+
if (value.identifier.startsWith('$env')) {
3436
return CONFIG_TYPES[1]
3537
}
3638
}
@@ -44,19 +46,17 @@ const ActionConfigurationInput = ({
4446
}, [eventDataOptions, dataType])
4547

4648
const normalized = useMemo(() => {
47-
if (typeof value === 'string') {
48-
if (value.startsWith('$event')) {
49-
return value.substr('$event.'.length)
49+
if (value.type === 'reference') {
50+
if (value.identifier.startsWith('$event')) {
51+
return value.identifier.substr('$event.'.length)
5052
}
5153

52-
if (value.startsWith('$env')) {
53-
return value.substr('$env.'.length)
54+
if (value.identifier.startsWith('$env')) {
55+
return value.identifier.substr('$env.'.length)
5456
}
5557
}
5658

57-
return typeof value === 'string' || typeof value === 'number'
58-
? value.toString()
59-
: ''
59+
return value.type === 'literal' ? value.value.toString() : ''
6060
}, [value])
6161

6262
return (
@@ -69,7 +69,7 @@ const ActionConfigurationInput = ({
6969
<FormSelect
7070
value={{ label: normalized, value: normalized }}
7171
options={options}
72-
onChange={({ value }) => onChange(`$event.${value}`)}
72+
onChange={({ value }) => onChange(RefNode(`$event.${value}`))}
7373
/>
7474
)}
7575
{type.value === 'custom' && customInput(onChange, value)}

src/cloud/components/Automations/actions/CreateDocActionConfigurator.tsx

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import FormEmoji from '../../../../design/components/molecules/Form/atoms/FormEm
44
import FormInput from '../../../../design/components/molecules/Form/atoms/FormInput'
55
import FormTextarea from '../../../../design/components/molecules/Form/atoms/FormTextArea'
66
import FormRow from '../../../../design/components/molecules/Form/templates/FormRow'
7+
import { LiteralNode, StructNode } from '../../../lib/automations/ast'
78
import { flattenObj } from '../../../lib/utils/object'
89
import { ActionConfiguratorProps } from './'
910
import ActionConfigurationInput from './ActionConfigurationInput'
1011
import FolderSelect from './FolderSelect'
1112
import PropertySelect from './PropertySelect'
1213

14+
// TODO: flatten type (bring from backend) ? do top level? 'declarations' || 'imports'
15+
// TODO: sort by type
1316
const CreateDocActionConfigurator = ({
1417
configuration,
1518
onChange,
@@ -19,74 +22,103 @@ const CreateDocActionConfigurator = ({
1922
return flattenObj(eventType as any)
2023
}, [eventType])
2124

25+
const constructorTree = useMemo(() => {
26+
if (
27+
configuration.type !== 'constructor' ||
28+
configuration.info.type !== 'struct'
29+
) {
30+
return {}
31+
}
32+
return configuration.info.refs
33+
}, [configuration])
34+
2235
return (
2336
<div>
2437
<FormRow row={{ title: 'Title' }}>
2538
<ActionConfigurationInput
26-
value={configuration.title}
39+
value={constructorTree.title}
2740
type={'string'}
28-
onChange={(title) => onChange({ ...configuration, title })}
41+
onChange={(title) =>
42+
onChange(StructNode({ ...constructorTree, title }))
43+
}
2944
eventDataOptions={eventDataOptions}
3045
customInput={(onChange, value) => {
3146
return (
3247
<FormInput
3348
value={value}
34-
onChange={(ev) => onChange(ev.target.value)}
49+
onChange={(ev) =>
50+
onChange(LiteralNode('string', ev.target.value))
51+
}
3552
/>
3653
)
3754
}}
3855
/>
3956
</FormRow>
4057
<FormRow row={{ title: 'Emoji' }}>
4158
<ActionConfigurationInput
42-
value={configuration.emoji}
59+
value={constructorTree.emoji}
4360
type={'string'}
44-
onChange={(emoji) => onChange({ ...configuration, emoji })}
61+
onChange={(emoji) =>
62+
onChange(StructNode({ ...constructorTree, emoji }))
63+
}
4564
eventDataOptions={eventDataOptions}
4665
customInput={(onChange, value) => {
4766
return (
4867
<FormEmoji
4968
emoji={value}
5069
defaultIcon={mdiFileDocumentOutline}
51-
setEmoji={onChange}
70+
setEmoji={(emojiStr) =>
71+
onChange(LiteralNode('string', emojiStr))
72+
}
5273
/>
5374
)
5475
}}
5576
/>
5677
</FormRow>
5778
<FormRow row={{ title: 'Content' }}>
5879
<ActionConfigurationInput
59-
value={configuration.content}
80+
value={constructorTree.content}
6081
type={'string'}
61-
onChange={(content) => onChange({ ...configuration, content })}
82+
onChange={(content) =>
83+
onChange(StructNode({ ...constructorTree, content }))
84+
}
6285
eventDataOptions={eventDataOptions}
6386
customInput={(onChange, value) => {
6487
return (
6588
<FormTextarea
6689
value={value}
67-
onChange={(ev) => onChange(ev.target.value)}
90+
onChange={(ev) =>
91+
onChange(LiteralNode('string', ev.target.value))
92+
}
6893
/>
6994
)
7095
}}
7196
/>
7297
</FormRow>
7398
<FormRow row={{ title: 'Parent Folder' }}>
7499
<ActionConfigurationInput
75-
value={configuration.parentFolder}
76-
type={'string'}
100+
value={constructorTree.parentFolder}
101+
type={'folder'}
77102
onChange={(parentFolder) =>
78-
onChange({ ...configuration, parentFolder })
103+
onChange(StructNode({ ...constructorTree, parentFolder }))
79104
}
80105
eventDataOptions={eventDataOptions}
81106
customInput={(onChange, value) => {
82-
return <FolderSelect value={value} onChange={onChange} />
107+
return (
108+
<FolderSelect
109+
value={value}
110+
onChange={(id) => onChange(LiteralNode('folder', id))}
111+
/>
112+
)
83113
}}
84114
/>
85115
</FormRow>
86116
<FormRow row={{ title: 'Props' }}></FormRow>
87117
<PropertySelect
88-
value={configuration.props || {}}
89-
onChange={(props) => onChange({ ...configuration, props })}
118+
value={constructorTree.props || {}}
119+
onChange={(props) =>
120+
onChange(StructNode({ ...constructorTree, props }))
121+
}
90122
eventDataOptions={eventDataOptions}
91123
/>
92124
</div>

0 commit comments

Comments
 (0)