Skip to content

Commit 6410a36

Browse files
committed
chore: refactor frontend to allow test step on mrf actions
1 parent dfb3c6f commit 6410a36

File tree

6 files changed

+33
-21
lines changed

6 files changed

+33
-21
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ function addStaticSubsteps(
8282
} else {
8383
computedStep.substeps.push(testStep)
8484
}
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
@@ -75,6 +75,7 @@ function ChooseConnectionSubstep(
7575
},
7676
fetchPolicy: 'cache-first',
7777
skip: !connection?.id,
78+
fetchPolicy: 'cache-first',
7879
})
7980

8081
const isTestStepValid = useMemo(() => {

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: 13 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
@@ -322,16 +327,7 @@ export default function FlowStepTestController(
322327
>
323328
{!isDirty ? 'Saved' : 'Save without checking'}
324329
</Button>
325-
<CheckAgainButton
326-
isUnstyledInfobox={isStepUnchecked}
327-
onClick={handleSaveAndTest}
328-
isLoading={isTestExecuting}
329-
isDisabled={!isValid || readOnly}
330-
step={step}
331-
executionStepMetadata={currentTestExecutionStep?.metadata}
332-
/>
333-
</Flex>
334-
) : (
330+
)}
335331
<CheckAgainButton
336332
isUnstyledInfobox={isStepUnchecked}
337333
onClick={handleSaveAndTest}
@@ -340,7 +336,7 @@ export default function FlowStepTestController(
340336
step={step}
341337
executionStepMetadata={currentTestExecutionStep?.metadata}
342338
/>
343-
)}
339+
</Flex>
344340
</Flex>
345341
</Infobox>
346342
<TestResult
@@ -362,7 +358,8 @@ export default function FlowStepTestController(
362358
<HStack w="100%" justifyContent="flex-end">
363359
{/* gathersg is a special case where there is a webhook url and the save step button
364360
needs to be shown to save the encryption key */}
365-
{(!step.webhookUrl || step.appKey === 'gathersg') && (
361+
{((!step.webhookUrl && !isMrfStep) ||
362+
step.appKey === 'gathersg') && (
366363
<Button
367364
isDisabled={readOnly || isSaving || !isDirty}
368365
isLoading={isSaving}

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

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

2323
function FlowSubstep(props: FlowSubstepProps): JSX.Element {
24-
const { isTrigger, substep, step, selectedActionOrTrigger } = props
24+
const { substep, step, selectedActionOrTrigger } = props
2525
const { getFlagValue } = useContext(LaunchDarklyContext)
2626
const formContext = useFormContext()
2727
const {
@@ -125,18 +125,24 @@ function FlowSubstep(props: FlowSubstepProps): JSX.Element {
125125
const handleSaveAndTest = useCallback(
126126
async (testRunMetadata?: Record<string, unknown>) => {
127127
try {
128-
await saveStep()
128+
if (
129+
!selectedActionOrTrigger ||
130+
!('hiddenFromUser' in selectedActionOrTrigger) ||
131+
selectedActionOrTrigger.hiddenFromUser !== true
132+
) {
133+
await saveStep()
134+
}
129135
await executeTestStep({ testRunMetadata })
130136
} catch (error) {
131137
console.error('Error saving and test step')
132138
}
133139
},
134-
[saveStep, executeTestStep],
140+
[selectedActionOrTrigger, executeTestStep, saveStep],
135141
)
136142

137143
return (
138144
<Box position="relative" display="flex" flexDirection="column">
139-
{(!isTrigger || argsToDisplay.length > 0) && (
145+
{argsToDisplay.length > 0 && (
140146
<Box flex="1" p={0} pb={4}>
141147
<Stack w="100%" spacing={4}>
142148
{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)