@@ -37,13 +37,14 @@ import { PiArrowLeft } from "@react-icons/all-files/pi/PiArrowLeft"
3737import { PiCaretDown } from "@react-icons/all-files/pi/PiCaretDown"
3838import { PiInfo } from "@react-icons/all-files/pi/PiInfo"
3939import { PiX } from "@react-icons/all-files/pi/PiX"
40+ import startCase from "lodash/startCase"
4041import { useEffect , useMemo } from "react"
4142import { Controller , type SubmitHandler , useForm } from "react-hook-form"
4243import Select from "react-select"
4344import CreateableSelect from "react-select/creatable"
4445import { z } from "zod/v3"
4546import type { TransformationField } from "../../schema"
46- import { transformationSchema } from "../../schema"
47+ import { DEFAULT_FOCUS_OBJECTS , transformationSchema } from "../../schema"
4748import { useEditorStore } from "../../store"
4849import { isStepAligned } from "../../utils"
4950import AnchorField from "../common/AnchorField"
@@ -61,6 +62,7 @@ export const TransformationConfigSidebar: React.FC = () => {
6162 addTransformation,
6263 updateTransformation,
6364 imageList,
65+ focusObjects,
6466 _setSidebarState,
6567 _internalState,
6668 _setTransformationToEdit,
@@ -296,40 +298,74 @@ export const TransformationConfigSidebar: React.FC = () => {
296298 < Controller
297299 name = { field . name }
298300 control = { control }
299- render = { ( { field : controllerField } ) => (
300- < Select
301- id = { field . name }
302- placeholder = "Select"
303- menuPlacement = "auto"
304- options = { field . fieldProps ?. options ?. map ( ( option ) => ( {
305- value : option . value ,
306- label : option . label ,
307- } ) ) }
308- value = { field . fieldProps ?. options ?. find (
309- ( option ) => option . value === controllerField . value ,
310- ) }
311- onChange = { ( selectedOption ) =>
312- controllerField . onChange ( selectedOption ?. value )
313- }
314- onBlur = { controllerField . onBlur }
315- styles = { {
316- control : ( base ) => ( {
317- ...base ,
318- fontSize : "12px" ,
319- minHeight : "32px" ,
320- borderColor : "#E2E8F0" ,
321- } ) ,
322- menu : ( base ) => ( {
323- ...base ,
324- zIndex : 10 ,
325- } ) ,
326- option : ( base ) => ( {
327- ...base ,
328- fontSize : "12px" ,
329- } ) ,
330- } }
331- />
332- ) }
301+ render = { ( { field : controllerField } ) => {
302+ // For focusObject field, use focusObjects from store or default list
303+ const selectOptions =
304+ field . name === "focusObject"
305+ ? ( focusObjects || DEFAULT_FOCUS_OBJECTS ) . map (
306+ ( obj ) => ( {
307+ value : obj ,
308+ label : startCase ( obj ) ,
309+ } ) ,
310+ )
311+ : field . fieldProps ?. options ?. map ( ( option ) => ( {
312+ value : option . value ,
313+ label : option . label ,
314+ } ) )
315+
316+ const isCreatable = field . fieldProps ?. isCreatable === true
317+ const SelectComponent = isCreatable
318+ ? CreateableSelect
319+ : Select
320+
321+ // For creatable selects, find the value in options or create a custom one
322+ const selectedValue = isCreatable
323+ ? selectOptions ?. find (
324+ ( option ) => option . value === controllerField . value ,
325+ ) ||
326+ ( controllerField . value
327+ ? {
328+ value : controllerField . value as string ,
329+ label : startCase ( controllerField . value as string ) ,
330+ }
331+ : null )
332+ : selectOptions ?. find (
333+ ( option ) => option . value === controllerField . value ,
334+ )
335+
336+ return (
337+ < SelectComponent
338+ id = { field . name }
339+ formatCreateLabel = { ( inputValue ) =>
340+ `Use "${ inputValue } "`
341+ }
342+ placeholder = "Select"
343+ menuPlacement = "auto"
344+ options = { selectOptions }
345+ value = { selectedValue }
346+ onChange = { ( selectedOption ) =>
347+ controllerField . onChange ( selectedOption ?. value )
348+ }
349+ onBlur = { controllerField . onBlur }
350+ styles = { {
351+ control : ( base ) => ( {
352+ ...base ,
353+ fontSize : "12px" ,
354+ minHeight : "32px" ,
355+ borderColor : "#E2E8F0" ,
356+ } ) ,
357+ menu : ( base ) => ( {
358+ ...base ,
359+ zIndex : 10 ,
360+ } ) ,
361+ option : ( base ) => ( {
362+ ...base ,
363+ fontSize : "12px" ,
364+ } ) ,
365+ } }
366+ />
367+ )
368+ } }
333369 />
334370 ) : null }
335371 { field . fieldType === "select-creatable" ? (
0 commit comments