@@ -4,12 +4,15 @@ import FormEmoji from '../../../../design/components/molecules/Form/atoms/FormEm
4
4
import FormInput from '../../../../design/components/molecules/Form/atoms/FormInput'
5
5
import FormTextarea from '../../../../design/components/molecules/Form/atoms/FormTextArea'
6
6
import FormRow from '../../../../design/components/molecules/Form/templates/FormRow'
7
+ import { LiteralNode , StructNode } from '../../../lib/automations/ast'
7
8
import { flattenObj } from '../../../lib/utils/object'
8
9
import { ActionConfiguratorProps } from './'
9
10
import ActionConfigurationInput from './ActionConfigurationInput'
10
11
import FolderSelect from './FolderSelect'
11
12
import PropertySelect from './PropertySelect'
12
13
14
+ // TODO: flatten type (bring from backend) ? do top level? 'declarations' || 'imports'
15
+ // TODO: sort by type
13
16
const CreateDocActionConfigurator = ( {
14
17
configuration,
15
18
onChange,
@@ -19,74 +22,103 @@ const CreateDocActionConfigurator = ({
19
22
return flattenObj ( eventType as any )
20
23
} , [ eventType ] )
21
24
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
+
22
35
return (
23
36
< div >
24
37
< FormRow row = { { title : 'Title' } } >
25
38
< ActionConfigurationInput
26
- value = { configuration . title }
39
+ value = { constructorTree . title }
27
40
type = { 'string' }
28
- onChange = { ( title ) => onChange ( { ...configuration , title } ) }
41
+ onChange = { ( title ) =>
42
+ onChange ( StructNode ( { ...constructorTree , title } ) )
43
+ }
29
44
eventDataOptions = { eventDataOptions }
30
45
customInput = { ( onChange , value ) => {
31
46
return (
32
47
< FormInput
33
48
value = { value }
34
- onChange = { ( ev ) => onChange ( ev . target . value ) }
49
+ onChange = { ( ev ) =>
50
+ onChange ( LiteralNode ( 'string' , ev . target . value ) )
51
+ }
35
52
/>
36
53
)
37
54
} }
38
55
/>
39
56
</ FormRow >
40
57
< FormRow row = { { title : 'Emoji' } } >
41
58
< ActionConfigurationInput
42
- value = { configuration . emoji }
59
+ value = { constructorTree . emoji }
43
60
type = { 'string' }
44
- onChange = { ( emoji ) => onChange ( { ...configuration , emoji } ) }
61
+ onChange = { ( emoji ) =>
62
+ onChange ( StructNode ( { ...constructorTree , emoji } ) )
63
+ }
45
64
eventDataOptions = { eventDataOptions }
46
65
customInput = { ( onChange , value ) => {
47
66
return (
48
67
< FormEmoji
49
68
emoji = { value }
50
69
defaultIcon = { mdiFileDocumentOutline }
51
- setEmoji = { onChange }
70
+ setEmoji = { ( emojiStr ) =>
71
+ onChange ( LiteralNode ( 'string' , emojiStr ) )
72
+ }
52
73
/>
53
74
)
54
75
} }
55
76
/>
56
77
</ FormRow >
57
78
< FormRow row = { { title : 'Content' } } >
58
79
< ActionConfigurationInput
59
- value = { configuration . content }
80
+ value = { constructorTree . content }
60
81
type = { 'string' }
61
- onChange = { ( content ) => onChange ( { ...configuration , content } ) }
82
+ onChange = { ( content ) =>
83
+ onChange ( StructNode ( { ...constructorTree , content } ) )
84
+ }
62
85
eventDataOptions = { eventDataOptions }
63
86
customInput = { ( onChange , value ) => {
64
87
return (
65
88
< FormTextarea
66
89
value = { value }
67
- onChange = { ( ev ) => onChange ( ev . target . value ) }
90
+ onChange = { ( ev ) =>
91
+ onChange ( LiteralNode ( 'string' , ev . target . value ) )
92
+ }
68
93
/>
69
94
)
70
95
} }
71
96
/>
72
97
</ FormRow >
73
98
< FormRow row = { { title : 'Parent Folder' } } >
74
99
< ActionConfigurationInput
75
- value = { configuration . parentFolder }
76
- type = { 'string ' }
100
+ value = { constructorTree . parentFolder }
101
+ type = { 'folder ' }
77
102
onChange = { ( parentFolder ) =>
78
- onChange ( { ...configuration , parentFolder } )
103
+ onChange ( StructNode ( { ...constructorTree , parentFolder } ) )
79
104
}
80
105
eventDataOptions = { eventDataOptions }
81
106
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
+ )
83
113
} }
84
114
/>
85
115
</ FormRow >
86
116
< FormRow row = { { title : 'Props' } } > </ FormRow >
87
117
< PropertySelect
88
- value = { configuration . props || { } }
89
- onChange = { ( props ) => onChange ( { ...configuration , props } ) }
118
+ value = { constructorTree . props || { } }
119
+ onChange = { ( props ) =>
120
+ onChange ( StructNode ( { ...constructorTree , props } ) )
121
+ }
90
122
eventDataOptions = { eventDataOptions }
91
123
/>
92
124
</ div >
0 commit comments