11import type { IFlowTemplateConfig , IStep , ISubstep } from '@plumber/types'
22
3- import {
4- Fragment ,
5- useCallback ,
6- useContext ,
7- useEffect ,
8- useMemo ,
9- useState ,
10- } from 'react'
3+ import { Fragment , useCallback , useContext , useMemo } from 'react'
114import { BiInfoCircle } from 'react-icons/bi'
125import { Box , CircularProgress , Flex , useDisclosure } from '@chakra-ui/react'
13- import { yupResolver } from '@hookform/resolvers/yup'
146import { Infobox } from '@opengovsg/design-system-react'
15- import type { BaseSchema } from 'yup'
16- import * as yup from 'yup'
17- import type { ObjectShape } from 'yup/lib/object'
187
198import ChooseConnectionSubstep from '@/components/ChooseConnectionSubstep'
209import FlowSubstep from '@/components/FlowSubstep'
2110import Form from '@/components/Form'
2211import MarkdownRenderer from '@/components/MarkdownRenderer'
23- import TestSubstep from '@/components/TestSubstep'
2412import { EditorContext } from '@/contexts/Editor'
25- import { StepDisplayOverridesContext } from '@/contexts/StepDisplayOverrides'
2613import { StepExecutionsProvider } from '@/contexts/StepExecutions'
2714import { StepExecutionsToIncludeContext } from '@/contexts/StepExecutionsToInclude'
2815import { generateValidationSchema } from '@/helpers/editor'
@@ -45,15 +32,7 @@ type FlowStepProps = {
4532}
4633
4734export default function Step ( props : FlowStepProps ) : React . ReactElement | null {
48- const {
49- index,
50- step,
51- isLastStep,
52- collapsed,
53- onChange,
54- onContinue,
55- templateConfig,
56- } = props
35+ const { step, isLastStep, collapsed, onChange, templateConfig } = props
5736
5837 const {
5938 isOpen : isModalOpen ,
@@ -63,14 +42,6 @@ export default function Step(props: FlowStepProps): React.ReactElement | null {
6342
6443 const { allApps, onDrawerClose, testExecutionSteps } =
6544 useContext ( EditorContext )
66- const displayOverrides = useContext ( StepDisplayOverridesContext ) ?. [ step . id ]
67-
68- const cannotChooseApp = displayOverrides ?. disableActionChanges ?? false
69- const [ currentSubstep , setCurrentSubstep ] = useState < number | null > (
70- // OK to set to 1, even if a step has _no_ substeps, everything will just be
71- // collapsed due to matching logic below.
72- cannotChooseApp ? 1 : 0 ,
73- )
7445
7546 // This includes all steps that run even after the current step, but within the same branch.
7647 const stepExecutionsToInclude = useContext ( StepExecutionsToIncludeContext )
@@ -91,15 +62,11 @@ export default function Step(props: FlowStepProps): React.ReactElement | null {
9162
9263 const handleChange = useCallback (
9364 async ( { step } : { step : IStep } ) => {
94- return await onChange ( step )
65+ return onChange ( step )
9566 } ,
9667 [ onChange ] ,
9768 )
9869
99- const expandNextStep = useCallback ( ( ) => {
100- setCurrentSubstep ( ( currentSubstep ) => ( currentSubstep ?? 0 ) + 1 )
101- } , [ ] )
102-
10370 const handleSubmit = ( val : any ) => {
10471 handleChange ( { step : val as IStep } )
10572 }
@@ -122,15 +89,6 @@ export default function Step(props: FlowStepProps): React.ReactElement | null {
12289 const shouldShowInfobox : boolean =
12390 stepAppEventKey === templateStepAppEventKey && ! ! templateStepHelpMessage
12491
125- const toggleSubstep = ( substepIndex : number ) =>
126- setCurrentSubstep ( ( value ) => ( value !== substepIndex ? substepIndex : null ) )
127-
128- useEffect ( ( ) => {
129- if ( index !== null ) {
130- setCurrentSubstep ( cannotChooseApp ? 1 : 0 )
131- }
132- } , [ cannotChooseApp , index ] )
133-
13492 // this ensures that we do not have an empty drawer
13593 if ( ! step . appKey && ! step . key ) {
13694 onDrawerClose ( )
@@ -167,75 +125,39 @@ export default function Step(props: FlowStepProps): React.ReactElement | null {
167125 onSubmit = { handleSubmit }
168126 resolver = { stepValidationSchema }
169127 >
170- { /* Place ChooseConnectionSubstep outside the accordion structure */ }
171- { substeps ?. some (
172- ( substep : ISubstep ) => substep . key === 'chooseConnection' ,
173- ) &&
174- app && (
175- < ChooseConnectionSubstep
176- step = { step }
177- application = { app }
178- onReconnect = { onModalOpen }
179- />
128+ < Fragment >
129+ { /* Place ChooseConnectionSubstep outside the accordion structure */ }
130+ { substeps ?. some (
131+ ( substep : ISubstep ) => substep . key === 'chooseConnection' ,
132+ ) &&
133+ app && (
134+ < ChooseConnectionSubstep
135+ step = { step }
136+ application = { app }
137+ onReconnect = { onModalOpen }
138+ />
139+ ) }
140+
141+ { substeps ?. map (
142+ ( substep ) =>
143+ substep . key &&
144+ ( ( step . appKey === 'webhook' && step ?. webhookUrl ) ||
145+ [ 'chooseConnection' , 'testStep' ] . includes ( substep . key ) ===
146+ false ) && (
147+ < FlowSubstep
148+ key = { substep . key }
149+ substep = { substep }
150+ onSave = { handleChange }
151+ step = { step }
152+ selectedActionOrTrigger = { selectedActionOrTrigger }
153+ />
154+ ) ,
180155 ) }
181-
182- { /* Render the remaining substeps as accordions */ }
183- { substeps ?. length > 0 &&
184- substeps
185- . filter ( ( substep ) => substep . key !== 'chooseConnection' )
186- . map ( ( substep : ISubstep , index : number ) => {
187- return (
188- < Fragment key = { `${ substep ?. name } -${ index } ` } >
189- { substep . key === 'testStep' && (
190- < TestSubstep
191- expanded = { currentSubstep === index }
192- substep = { substep }
193- onExpand = { ( ) => toggleSubstep ( index ) }
194- onCollapse = { ( ) => toggleSubstep ( index ) }
195- onChange = { handleChange }
196- onContinue = { onContinue }
197- step = { step }
198- selectedActionOrTrigger = { selectedActionOrTrigger }
199- />
200- ) }
201-
202- { substep . key && substep . key !== 'testStep' && (
203- < FlowSubstep
204- expanded = { currentSubstep === index }
205- substep = { substep }
206- onExpand = { ( ) => toggleSubstep ( index ) }
207- onCollapse = { ( ) => toggleSubstep ( index ) }
208- onSubmit = { (
209- type ?: string ,
210- currentStep ?: IStep ,
211- status ?: string ,
212- ) => {
213- if ( type === 'save' && currentStep ) {
214- return handleChange ( {
215- step : {
216- ...currentStep ,
217- ...( status !== undefined && { status } ) ,
218- } ,
219- } )
220- } else {
221- expandNextStep ( )
222- }
223- } }
224- onChange = { handleChange }
225- step = { step }
226- settingsLabel = {
227- selectedActionOrTrigger ?. settingsStepLabel ??
228- app ?. substepLabels ?. settingsStepLabel
229- }
230- selectedActionOrTrigger = { selectedActionOrTrigger }
231- />
232- ) }
233- </ Fragment >
234- )
235- } ) }
156+ </ Fragment >
236157 </ Form >
237158 </ StepExecutionsProvider >
238159 </ Flex >
160+
239161 { isModalOpen && (
240162 < FlowStepConfigurationModal
241163 onClose = { onModalClose }
0 commit comments