@@ -19,6 +19,7 @@ import { cn } from '@/lib/utils';
1919import { format } from 'date-fns' ;
2020import { controlSchema } from './schemas' ;
2121import { saveDraftCatalogId } from '@/utils/draftStorage' ;
22+ import { getAllLinkers } from '@/services/linkers' ;
2223
2324export function NewControlForm ( { catalogId, onClose, onSuccess, customSubmit = null } ) {
2425 const [ loading , setLoading ] = useState ( false ) ;
@@ -30,6 +31,7 @@ export function NewControlForm({ catalogId, onClose, onSuccess, customSubmit = n
3031 const [ scopeValue , setScopeValue ] = useState ( '' ) ;
3132 const [ selectedParam , setSelectedParam ] = useState ( '' ) ;
3233 const [ paramValue , setParamValue ] = useState ( '' ) ;
34+ const [ availableLinkers , setAvailableLinkers ] = useState ( [ ] ) ;
3335
3436 // Setup form with zod validation
3537 const form = useForm ( {
@@ -43,14 +45,16 @@ export function NewControlForm({ catalogId, onClose, onSuccess, customSubmit = n
4345 mashupId : '' ,
4446 params : { } ,
4547 scopes : { } ,
46- catalogId : catalogId
48+ catalogId : catalogId ,
49+ linkerId : '' , // Añadido linkerId
4750 }
4851 } ) ;
4952
5053 const { watch, setValue, getValues } = form ;
5154 const watchMashupId = watch ( 'mashupId' ) ;
5255 const watchParams = watch ( 'params' ) ;
5356 const watchScopes = watch ( 'scopes' ) ;
57+ const watchLinkerId = form . watch ( 'linkerId' ) ;
5458
5559 useEffect ( ( ) => {
5660 // Fetch available scopes for the dropdown
@@ -75,8 +79,20 @@ export function NewControlForm({ catalogId, onClose, onSuccess, customSubmit = n
7579 }
7680 } ;
7781
82+ // Fetch available linkers for the dropdown
83+ const fetchLinkers = async ( ) => {
84+ try {
85+ const response = await getAllLinkers ( ) ;
86+ setAvailableLinkers ( response ) ;
87+ } catch ( error ) {
88+ console . error ( 'Error fetching linkers:' , error ) ;
89+ toast . error ( 'Failed to fetch available linkers' ) ;
90+ }
91+ } ;
92+
7893 fetchScopes ( ) ;
7994 fetchMashups ( ) ;
95+ fetchLinkers ( ) ;
8096 } , [ ] ) ;
8197
8298 // When mashupId changes, fetch the params
@@ -388,6 +404,35 @@ export function NewControlForm({ catalogId, onClose, onSuccess, customSubmit = n
388404 ) }
389405 />
390406
407+ { /* Nuevo campo para seleccionar Linker */ }
408+ < FormField
409+ control = { form . control }
410+ name = "linkerId"
411+ render = { ( { field } ) => (
412+ < FormItem >
413+ < FormLabel > Linker*</ FormLabel >
414+ < Select
415+ onValueChange = { field . onChange }
416+ defaultValue = { field . value }
417+ >
418+ < FormControl >
419+ < SelectTrigger >
420+ < SelectValue placeholder = "Selecciona un linker" />
421+ </ SelectTrigger >
422+ </ FormControl >
423+ < SelectContent className = "max-h-60 overflow-y-auto" >
424+ { availableLinkers . map ( ( linker ) => (
425+ < SelectItem key = { linker . id } value = { linker . id } >
426+ { linker . name }
427+ </ SelectItem >
428+ ) ) }
429+ </ SelectContent >
430+ </ Select >
431+ < FormMessage />
432+ </ FormItem >
433+ ) }
434+ />
435+
391436 < div className = "space-y-2" >
392437 < FormLabel > Parameters*</ FormLabel >
393438 < div className = "flex space-x-2" >
0 commit comments