11import React from "react" ;
2- import { Alert , Spacing , Text , useForm , useService , useStore } from "@code0-tech/pictor" ;
2+ import { Alert , Button , Flex , Spacing , Text , useForm , useService , useStore } from "@code0-tech/pictor" ;
33import { Flow , LiteralValue , Namespace , NamespaceProject } from "@code0-tech/sagittarius-graphql-types" ;
44import { FlowTypeService } from "@edition/flowtype/services/FlowType.service" ;
55import { FlowService } from "@edition/flow/services/Flow.service" ;
@@ -13,6 +13,8 @@ import {
1313} from "@core/util/fallback-translations" ;
1414import { useNodesData } from "@xyflow/react" ;
1515import { NodeSchema } from "@code0-tech/triangulum" ;
16+ import * as Collapsible from "@radix-ui/react-collapsible" ;
17+ import { IconChevronDown } from "@tabler/icons-react" ;
1618
1719export interface FunctionFileTriggerComponentProps {
1820 flowId : Flow [ 'id' ]
@@ -118,30 +120,54 @@ export const FunctionFileTriggerComponent: React.FC<FunctionFileTriggerComponent
118120 < Spacing spacing = { "xl" } />
119121 < Text size = { "md" } > Settings</ Text >
120122 < Spacing spacing = { "xl" } />
121- { definition ?. flowTypeSettings ?. map ( ( settingDefinition , index ) => {
122-
123- if ( ! settingDefinition ) return null
124-
125- const title = settingDefinition . names ?. [ 0 ] ?. content ?? FALLBACK_FLOW_TYPE_SETTING_NAME
126- const description = settingDefinition ?. descriptions ?. [ 0 ] ?. content ?? FALLBACK_FLOW_TYPE_SETTING_DESCRIPTION
127-
128- return < div >
129- { /*@ts -ignore*/ }
130- < DataTypeInputComponent data-qa-selector = { "flow-builder-setting" }
131- title = { title }
132- schema = { ( flowNode ?. data ?. schema as NodeSchema [ ] ) ?. [ index ] }
133- description = { description }
134- clearable
135- key = { settingDefinition . id }
136- onChange = { ( ) => {
137- changedSettings . current . add ( settingDefinition . id ! )
138- validate ( )
139- } }
140- { ...inputs . getInputProps ( settingDefinition . id ! ) }
141- />
142- < Spacing spacing = { "xl" } />
143- </ div >
123+ { ( ( ) => {
124+ const indexedSettings = definition ?. flowTypeSettings
125+ ?. map ( ( settingDefinition , index ) => ( { settingDefinition, index} ) )
126+ ?. filter ( ( { settingDefinition} ) => settingDefinition && ! settingDefinition . hidden ) ?? [ ]
127+
128+ const requiredSettings = indexedSettings . filter ( ( { settingDefinition} ) => ! settingDefinition ! . optional )
129+ const optionalSettings = indexedSettings . filter ( ( { settingDefinition} ) => settingDefinition ! . optional )
130+
131+ const renderSetting = ( settingDefinition : NonNullable < typeof indexedSettings [ number ] [ 'settingDefinition' ] > , index : number ) => {
132+ const title = settingDefinition . names ?. [ 0 ] ?. content ?? FALLBACK_FLOW_TYPE_SETTING_NAME
133+ const description = settingDefinition ?. descriptions ?. [ 0 ] ?. content ?? FALLBACK_FLOW_TYPE_SETTING_DESCRIPTION
134+
135+ return < div key = { settingDefinition . id } >
136+ { /*@ts -ignore*/ }
137+ < DataTypeInputComponent data-qa-selector = { "flow-builder-setting" }
138+ title = { title }
139+ schema = { ( flowNode ?. data ?. schema as NodeSchema [ ] ) ?. [ index ] }
140+ description = { description }
141+ clearable
142+ onChange = { ( ) => {
143+ changedSettings . current . add ( settingDefinition . id ! )
144+ validate ( )
145+ } }
146+ { ...inputs . getInputProps ( settingDefinition . id ! ) }
147+ />
148+ < Spacing spacing = { "xl" } />
149+ </ div >
150+ }
144151
145- } ) }
152+ return < >
153+ { requiredSettings . map ( ( { settingDefinition, index} ) => renderSetting ( settingDefinition ! , index ) ) }
154+ { optionalSettings . length > 0 && (
155+ < Collapsible . Root >
156+ < Collapsible . Trigger asChild >
157+ < Flex justify = { "space-between" } align = { "center" } style = { { gap : "0.7rem" } } >
158+ < Text size = { "md" } > Optional settings</ Text >
159+ < Button variant = { "none" } color = { "primary" } paddingSize = { "xxs" } >
160+ < IconChevronDown size = { 16 } />
161+ </ Button >
162+ </ Flex >
163+ </ Collapsible . Trigger >
164+ < Spacing spacing = { "md" } />
165+ < Collapsible . Content >
166+ { optionalSettings . map ( ( { settingDefinition, index} ) => renderSetting ( settingDefinition ! , index ) ) }
167+ </ Collapsible . Content >
168+ </ Collapsible . Root >
169+ ) }
170+ </ >
171+ } ) ( ) }
146172 </ >
147173} )
0 commit comments