@@ -4,12 +4,15 @@ import FormEmoji from '../../../../design/components/molecules/Form/atoms/FormEm
44import FormInput from '../../../../design/components/molecules/Form/atoms/FormInput'
55import FormTextarea from '../../../../design/components/molecules/Form/atoms/FormTextArea'
66import FormRow from '../../../../design/components/molecules/Form/templates/FormRow'
7+ import { LiteralNode , StructNode } from '../../../lib/automations/ast'
78import { flattenObj } from '../../../lib/utils/object'
89import { ActionConfiguratorProps } from './'
910import ActionConfigurationInput from './ActionConfigurationInput'
1011import FolderSelect from './FolderSelect'
1112import PropertySelect from './PropertySelect'
1213
14+ // TODO: flatten type (bring from backend) ? do top level? 'declarations' || 'imports'
15+ // TODO: sort by type
1316const 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