@@ -6,7 +6,11 @@ import {
66 SelectTrigger ,
77 SelectValue ,
88} from '@/components/ui'
9- import { queryFlowsForSelectOption } from '@/lib/query-options/flow'
9+ import { NOT_CHOOSE } from '@/constants'
10+ import {
11+ queryFlowOption ,
12+ queryFlowsForSelectOption ,
13+ } from '@/lib/query-options/flow'
1014import { useQuery } from '@tanstack/react-query'
1115import _ from 'lodash'
1216import { useTranslation } from 'react-i18next'
@@ -17,38 +21,122 @@ export const SubFlowContent = () => {
1721 const { id } = useParams ( )
1822 const { data : flows } = useQuery ( queryFlowsForSelectOption ( ) )
1923 const { t } = useTranslation ( 'forms' )
20- const { handleChangeSelectedNode, selectedNode } = useFlowCtx ( )
24+ const { handleChangeSelectedNode, selectedNode, flow } = useFlowCtx ( )
25+ const { data : subflow } = useQuery ( {
26+ ...queryFlowOption ( selectedNode ?. data ?. subFlowId ) ,
27+ enabled : ! ! selectedNode ?. data ?. subFlowId ,
28+ } )
2129
2230 return (
23- < div className = 'space-y-2' >
24- < Label > { t ( 'sub_flow.label' ) } </ Label >
25- < Select
26- value = { selectedNode ?. data ?. subFlowId }
27- onValueChange = { ( value ) => {
28- if ( ! selectedNode ) return
29-
30- const cloneSelectedNode = _ . cloneDeep ( selectedNode )
31-
32- cloneSelectedNode . data . subFlowId = value
33-
34- handleChangeSelectedNode ( cloneSelectedNode )
35- } }
36- >
37- < SelectTrigger >
38- < SelectValue placeholder = { t ( 'sub_flow.placeholder' ) } />
39- </ SelectTrigger >
40- < SelectContent >
41- { flows ?. map ( ( flow ) => {
42- if ( flow . value === id ) return null
43-
44- return (
45- < SelectItem key = { flow . value } value = { flow . value } >
46- { flow . label }
31+ < div className = 'space-y-3' >
32+ < div className = 'space-y-2' >
33+ < Label > { t ( 'sub_flow.label' ) } </ Label >
34+ < Select
35+ value = { selectedNode ?. data ?. subFlowId }
36+ onValueChange = { ( value ) => {
37+ if ( ! selectedNode ) return
38+
39+ const cloneSelectedNode = _ . cloneDeep ( selectedNode )
40+
41+ cloneSelectedNode . data . subFlowId = value
42+
43+ handleChangeSelectedNode ( cloneSelectedNode )
44+ } }
45+ >
46+ < SelectTrigger >
47+ < SelectValue placeholder = { t ( 'sub_flow.placeholder' ) } />
48+ </ SelectTrigger >
49+ < SelectContent >
50+ { flows ?. map ( ( flow ) => {
51+ if ( flow . value === id ) return null
52+
53+ return (
54+ < SelectItem key = { flow . value } value = { flow . value } >
55+ { flow . label }
56+ </ SelectItem >
57+ )
58+ } ) }
59+ </ SelectContent >
60+ </ Select >
61+ </ div >
62+ < div className = 'flex gap-3' >
63+ < div className = 'space-y-2 w-full' >
64+ < Label > { t ( 'assign_var.label' ) } </ Label >
65+ < Select
66+ value = { selectedNode ?. data ?. assignTo || NOT_CHOOSE }
67+ onValueChange = { ( value ) => {
68+ if ( ! selectedNode ) return
69+
70+ const cloneSelectedNode = _ . cloneDeep ( selectedNode )
71+
72+ if ( value === NOT_CHOOSE ) {
73+ delete cloneSelectedNode . data . assignTo
74+ } else {
75+ cloneSelectedNode . data . assignTo = value
76+ }
77+
78+ handleChangeSelectedNode ( cloneSelectedNode )
79+ } }
80+ >
81+ < SelectTrigger >
82+ < SelectValue placeholder = { t ( 'assign_var.placeholder' ) } />
83+ </ SelectTrigger >
84+ < SelectContent >
85+ < SelectItem value = { NOT_CHOOSE } >
86+ { t ( 'assign_var.placeholder' ) }
87+ </ SelectItem >
88+ { flow . variables ?. map ( ( variable , index ) => {
89+ return (
90+ < SelectItem
91+ key = { `${ variable . name } -${ index } ` }
92+ value = { variable . name }
93+ >
94+ { variable . name }
95+ </ SelectItem >
96+ )
97+ } ) }
98+ </ SelectContent >
99+ </ Select >
100+ </ div >
101+ < div className = 'space-y-2 w-full' >
102+ < Label > { t ( 'output_var.label' ) } </ Label >
103+ < Select
104+ value = { selectedNode ?. data ?. outputVar || NOT_CHOOSE }
105+ onValueChange = { ( value ) => {
106+ if ( ! selectedNode ) return
107+
108+ const cloneSelectedNode = _ . cloneDeep ( selectedNode )
109+
110+ if ( value === NOT_CHOOSE ) {
111+ delete cloneSelectedNode . data . outputVar
112+ } else {
113+ cloneSelectedNode . data . outputVar = value
114+ }
115+
116+ handleChangeSelectedNode ( cloneSelectedNode )
117+ } }
118+ >
119+ < SelectTrigger >
120+ < SelectValue placeholder = { t ( 'output_var.placeholder' ) } />
121+ </ SelectTrigger >
122+ < SelectContent >
123+ < SelectItem value = { NOT_CHOOSE } >
124+ { t ( 'output_var.placeholder' ) }
47125 </ SelectItem >
48- )
49- } ) }
50- </ SelectContent >
51- </ Select >
126+ { subflow ?. variables ?. map ( ( variable , index ) => {
127+ return (
128+ < SelectItem
129+ key = { `${ variable . name } -${ index } ` }
130+ value = { variable . name }
131+ >
132+ { variable . name }
133+ </ SelectItem >
134+ )
135+ } ) }
136+ </ SelectContent >
137+ </ Select >
138+ </ div >
139+ </ div >
52140 </ div >
53141 )
54142}
0 commit comments