Skip to content

Commit 8cb389b

Browse files
committed
chore: refactor frontend to allow test step on mrf actions
1 parent 699647e commit 8cb389b

File tree

7 files changed

+36
-25
lines changed

7 files changed

+36
-25
lines changed

packages/backend/src/helpers/get-app.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@ function addStaticSubsteps(
7979
name: 'Set up step',
8080
arguments: step.arguments,
8181
})
82+
} else {
83+
computedStep.substeps.push(testStep)
8284
}
83-
84-
computedStep.substeps.push(testStep)
85-
8685
return computedStep
8786
}
8887

packages/frontend/src/components/ChooseConnectionSubstep/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ function ChooseConnectionSubstep(
6767
flowId: supportsConnectionRegistration ? step.flowId : undefined,
6868
},
6969
skip: !connection?.id,
70+
fetchPolicy: 'cache-first',
7071
})
7172

7273
const isTestStepValid = useMemo(() => {

packages/frontend/src/components/EditorRightDrawer/Step.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export default function Step(props: StepProps): React.ReactElement | null {
6767
return (
6868
<>
6969
<Flex w="100%" flexDir="column">
70+
{/* {JSON.stringify(substeps)} */}
7071
<StepExecutionsProvider priorExecutionSteps={priorExecutionSteps}>
7172
<Form
7273
key={`${step.id}-${resetTimestamp}`}
@@ -91,8 +92,7 @@ export default function Step(props: StepProps): React.ReactElement | null {
9192
substep.key &&
9293
// NOTE: webhook trigger is a special case where we want to show the step configuration immediately
9394
((step.appKey === 'webhook' && step?.webhookUrl) ||
94-
['chooseConnection', 'testStep'].includes(substep.key) ===
95-
false) && (
95+
['chooseConnection'].includes(substep.key) === false) && (
9696
<FlowSubstep
9797
key={substep.key}
9898
hasConnection={hasConnection}

packages/frontend/src/components/FlowStepTestController/CheckAgainButton.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ export function CheckAgainButton(props: CheckAgainButtonProps) {
2828
const { isUnstyledInfobox, onClick, isLoading, isDisabled, step } = props
2929
const isFormSgTrigger =
3030
step.appKey === 'formsg' && step.key === 'newSubmission'
31+
const isFormSgAction =
32+
step.appKey === 'formsg' && step.key === 'mrfSubmission'
33+
3134
if (isFormSgTrigger) {
3235
return <FormSGCheckAgainButton {...props} />
3336
}
37+
if (isFormSgAction) {
38+
return <FormSGCheckAgainButton {...props} />
39+
}
3440
return (
3541
<Button
3642
variant={isUnstyledInfobox ? 'solid' : 'outline'}

packages/frontend/src/components/FlowStepTestController/index.tsx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,13 @@ export default function FlowStepTestController(
108108
} = useContext(EditorContext)
109109
const formContext = useFormContext()
110110

111-
const { isIfThenStep, isTrigger, selectedActionOrTrigger, substeps } =
112-
useStepMetadata(allApps, step)
111+
const {
112+
isIfThenStep,
113+
isTrigger,
114+
isMrfStep,
115+
selectedActionOrTrigger,
116+
substeps,
117+
} = useStepMetadata(allApps, step)
113118

114119
const {
115120
isTestSuccessful,
@@ -305,8 +310,8 @@ export default function FlowStepTestController(
305310
</Button>
306311
)}
307312
</Flex>
308-
{shouldShowSaveButton ? (
309-
<Flex>
313+
<Flex>
314+
{shouldShowSaveButton && (
310315
<Button
311316
variant="outline"
312317
// cant use responsive value for variant for some reason
@@ -321,16 +326,7 @@ export default function FlowStepTestController(
321326
>
322327
{!isDirty ? 'Saved' : 'Save without checking'}
323328
</Button>
324-
<CheckAgainButton
325-
isUnstyledInfobox={isStepUnchecked}
326-
onClick={handleSaveAndTest}
327-
isLoading={isTestExecuting}
328-
isDisabled={!isValid || readOnly}
329-
step={step}
330-
executionStepMetadata={currentTestExecutionStep?.metadata}
331-
/>
332-
</Flex>
333-
) : (
329+
)}
334330
<CheckAgainButton
335331
isUnstyledInfobox={isStepUnchecked}
336332
onClick={handleSaveAndTest}
@@ -339,7 +335,7 @@ export default function FlowStepTestController(
339335
step={step}
340336
executionStepMetadata={currentTestExecutionStep?.metadata}
341337
/>
342-
)}
338+
</Flex>
343339
</Flex>
344340
</Infobox>
345341
<TestResult
@@ -359,7 +355,7 @@ export default function FlowStepTestController(
359355
</Box>
360356
)}
361357
<HStack w="100%" justifyContent="flex-end">
362-
{!step.webhookUrl && (
358+
{!step.webhookUrl && !isMrfStep && (
363359
<Button
364360
isDisabled={readOnly || isSaving || !isDirty}
365361
isLoading={isSaving}

packages/frontend/src/components/FlowSubstep/index.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type FlowSubstepProps = {
2222
}
2323

2424
function FlowSubstep(props: FlowSubstepProps): JSX.Element {
25-
const { isTrigger, substep, step, selectedActionOrTrigger } = props
25+
const { substep, step, selectedActionOrTrigger } = props
2626
const { getFlagValue } = useContext(LaunchDarklyContext)
2727
const formContext = useFormContext()
2828
const {
@@ -133,18 +133,24 @@ function FlowSubstep(props: FlowSubstepProps): JSX.Element {
133133
const handleSaveAndTest = useCallback(
134134
async (testRunMetadata?: Record<string, unknown>) => {
135135
try {
136-
await saveStep()
136+
if (
137+
!selectedActionOrTrigger ||
138+
!('hiddenFromUser' in selectedActionOrTrigger) ||
139+
selectedActionOrTrigger.hiddenFromUser !== true
140+
) {
141+
await saveStep()
142+
}
137143
await executeTestStep({ testRunMetadata })
138144
} catch (error) {
139145
console.error('Error saving and test step')
140146
}
141147
},
142-
[saveStep, executeTestStep],
148+
[selectedActionOrTrigger, executeTestStep, saveStep],
143149
)
144150

145151
return (
146152
<Box position="relative" display="flex" flexDirection="column">
147-
{(!isTrigger || argsToDisplay.length > 0) && (
153+
{argsToDisplay.length > 0 && (
148154
<Box flex="1" p={0} pb={4}>
149155
<Stack w="100%" spacing={4}>
150156
{argsToDisplay.map((argument) => (

packages/frontend/src/hooks/useStepMetadata.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface UseStepMetadataResult {
1818
stepName: string
1919
substeps: ISubstep[]
2020
shouldShowDragHandle?: boolean
21+
isMrfStep: boolean
2122
}
2223

2324
export function useStepMetadata(
@@ -31,6 +32,7 @@ export function useStepMetadata(
3132
const isCompleted = step?.status === 'completed'
3233
const isTrigger = step?.type === 'trigger'
3334
const isIfThenStep = step ? checkIfThenStep(step) : false
35+
const isMrfStep = step?.key === 'mrfSubmission'
3436

3537
const apps: IApp[] = allApps?.filter((app: IApp) =>
3638
isTrigger ? !!app.triggers?.length : !!app.actions?.length,
@@ -88,6 +90,7 @@ export function useStepMetadata(
8890
hasConnection,
8991
isCompleted,
9092
isIfThenStep,
93+
isMrfStep,
9194
isTrigger,
9295
position: step?.position ?? 0,
9396
stepName: step?.config?.stepName

0 commit comments

Comments
 (0)