@@ -25,7 +25,10 @@ export function ActionInputSection() {
25
25
const [ placeholderText , setPlaceholderText ] = useState < string > ( "" ) ;
26
26
const [ selectedComponent , setSelectedComponent ] = useState < string | null > ( null ) ;
27
27
const [ showComponentDropdown , setShowComponentDropdown ] = useState < boolean > ( false ) ;
28
+ const [ isNestedComponent , setIsNestedComponent ] = useState < boolean > ( false ) ;
29
+ const [ selectedNestComponent , setSelectedNestComponent ] = useState < string | null > ( null ) ;
28
30
const [ showEditorComponentsDropdown , setShowEditorComponentsDropdown ] = useState < boolean > ( false ) ;
31
+ const [ showStylingInput , setShowStylingInput ] = useState < boolean > ( false ) ;
29
32
const [ selectedEditorComponent , setSelectedEditorComponent ] = useState < string | null > ( null ) ;
30
33
const [ validationError , setValidationError ] = useState < string | null > ( null ) ;
31
34
const inputRef = useRef < InputRef > ( null ) ;
@@ -73,44 +76,55 @@ export function ActionInputSection() {
73
76
74
77
setShowComponentDropdown ( false ) ;
75
78
setShowEditorComponentsDropdown ( false ) ;
79
+ setShowStylingInput ( false ) ;
76
80
setSelectedComponent ( null ) ;
77
81
setSelectedEditorComponent ( null ) ;
82
+ setIsNestedComponent ( false ) ;
83
+ setSelectedNestComponent ( null ) ;
78
84
setActionValue ( "" ) ;
79
85
80
86
if ( action . requiresComponentSelection ) {
81
87
setShowComponentDropdown ( true ) ;
82
88
setPlaceholderText ( "Select a component to add" ) ;
83
- } else if ( action . requiresEditorComponentSelection ) {
89
+ }
90
+ if ( action . requiresEditorComponentSelection ) {
84
91
setShowEditorComponentsDropdown ( true ) ;
85
92
setPlaceholderText ( `Select a component to ${ action . label . toLowerCase ( ) } ` ) ;
86
- } else if ( action . requiresInput ) {
93
+ }
94
+ if ( action . requiresInput ) {
87
95
setPlaceholderText ( action . inputPlaceholder || `Enter ${ action . label . toLowerCase ( ) } value` ) ;
88
96
} else {
89
97
setPlaceholderText ( `Execute ${ action . label . toLowerCase ( ) } ` ) ;
90
98
}
99
+ if ( action . requiresStyle ) {
100
+ setShowStylingInput ( true ) ;
101
+ setPlaceholderText ( `Select a component to style` ) ;
102
+ }
103
+ if ( action . isNested ) {
104
+ setIsNestedComponent ( true ) ;
105
+ }
91
106
} , [ ] ) ;
92
107
93
108
const handleComponentSelection = useCallback ( ( key : string ) => {
94
109
if ( key . startsWith ( 'comp-' ) ) {
95
110
const compName = key . replace ( 'comp-' , '' ) ;
96
- setSelectedComponent ( compName ) ;
111
+ isNestedComponent ? setSelectedNestComponent ( compName ) : setSelectedComponent ( compName ) ;
97
112
setPlaceholderText ( `Configure ${ compName } component` ) ;
98
113
}
99
- } , [ ] ) ;
114
+ } , [ isNestedComponent ] ) ;
100
115
101
116
const handleEditorComponentSelection = useCallback ( ( key : string ) => {
102
117
setSelectedEditorComponent ( key ) ;
103
- if ( currentAction ) {
104
- setPlaceholderText ( `${ currentAction . label } ` ) ;
105
- }
118
+ setPlaceholderText ( `${ currentAction ?. label } ` ) ;
106
119
} , [ currentAction ] ) ;
107
120
121
+
108
122
const validateInput = useCallback ( ( value : string ) : string | null => {
109
123
if ( ! currentAction ?. validation ) return null ;
110
124
return currentAction . validation ( value ) ;
111
125
} , [ currentAction ] ) ;
112
126
113
- const handleInputChange = useCallback ( ( e : React . ChangeEvent < HTMLInputElement > ) => {
127
+ const handleInputChange = useCallback ( ( e : React . ChangeEvent < HTMLTextAreaElement | HTMLInputElement > ) => {
114
128
const value = e . target . value ;
115
129
setActionValue ( value ) ;
116
130
@@ -149,12 +163,18 @@ export function ActionInputSection() {
149
163
return ;
150
164
}
151
165
166
+ if ( currentAction . isNested && ! selectedNestComponent ) {
167
+ message . error ( 'Please select a component to nest' ) ;
168
+ return ;
169
+ }
170
+
152
171
try {
153
172
await currentAction . execute ( {
154
173
actionKey : selectedActionKey ,
155
174
actionValue,
156
175
selectedComponent,
157
176
selectedEditorComponent,
177
+ selectedNestComponent,
158
178
editorState
159
179
} ) ;
160
180
@@ -167,6 +187,8 @@ export function ActionInputSection() {
167
187
setSelectedEditorComponent ( null ) ;
168
188
setPlaceholderText ( "" ) ;
169
189
setValidationError ( null ) ;
190
+ setIsNestedComponent ( false ) ;
191
+ setSelectedNestComponent ( null ) ;
170
192
171
193
} catch ( error ) {
172
194
console . error ( 'Error executing action:' , error ) ;
@@ -177,6 +199,7 @@ export function ActionInputSection() {
177
199
actionValue ,
178
200
selectedComponent ,
179
201
selectedEditorComponent ,
202
+ selectedNestComponent ,
180
203
editorState ,
181
204
currentAction ,
182
205
validateInput
@@ -235,7 +258,7 @@ export function ActionInputSection() {
235
258
</ Button >
236
259
</ CustomDropdown >
237
260
238
- { showComponentDropdown && (
261
+ { ( showComponentDropdown || isNestedComponent ) && (
239
262
< CustomDropdown
240
263
overlayStyle = { {
241
264
maxHeight : '400px' ,
@@ -253,7 +276,13 @@ export function ActionInputSection() {
253
276
>
254
277
< Button size = { "small" } >
255
278
< Space >
256
- { selectedComponent ? selectedComponent : 'Select Component' }
279
+ {
280
+ selectedComponent
281
+ ? selectedComponent
282
+ : selectedNestComponent
283
+ ? selectedNestComponent
284
+ : 'New Component'
285
+ }
257
286
< DownOutlined />
258
287
</ Space >
259
288
</ Button >
@@ -278,23 +307,34 @@ export function ActionInputSection() {
278
307
>
279
308
< Button size = { "small" } >
280
309
< Space >
281
- { selectedEditorComponent ? selectedEditorComponent : 'Select Component' }
310
+ { selectedEditorComponent ? selectedEditorComponent : 'Editor Component' }
282
311
< DownOutlined />
283
312
</ Space >
284
313
</ Button >
285
314
</ CustomDropdown >
286
315
) }
287
-
316
+
288
317
{ shouldShowInput && (
289
- < Input
290
- ref = { inputRef }
291
- value = { actionValue }
292
- onChange = { handleInputChange }
293
- placeholder = { placeholderText }
294
- status = { validationError ? 'error' : undefined }
295
- />
318
+ showStylingInput ? (
319
+ < Input . TextArea
320
+ ref = { inputRef }
321
+ value = { actionValue }
322
+ onChange = { handleInputChange }
323
+ placeholder = { placeholderText }
324
+ status = { validationError ? 'error' : undefined }
325
+ autoSize = { { minRows : 1 } }
326
+ />
327
+ ) : (
328
+ < Input
329
+ ref = { inputRef }
330
+ value = { actionValue }
331
+ onChange = { handleInputChange }
332
+ placeholder = { placeholderText }
333
+ status = { validationError ? 'error' : undefined }
334
+ />
335
+ )
296
336
) }
297
-
337
+
298
338
{ validationError && (
299
339
< div style = { { color : '#ff4d4f' , fontSize : '12px' , marginTop : '-8px' } } >
300
340
{ validationError }
0 commit comments