Skip to content

Commit b9ad250

Browse files
committed
chore: show approval tag, and fix some frontend stuff
1 parent 6477e5f commit b9ad250

File tree

6 files changed

+46
-34
lines changed

6 files changed

+46
-34
lines changed

packages/backend/src/apps/formsg/common/get-data-out-metadata.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,13 @@ async function getDataOutMetadata(
314314

315315
let questionIdsToShowForMrf: Set<string> | undefined
316316

317+
let approvalField: string | null = null
317318
if (parameters.mrf) {
318319
questionIdsToShowForMrf = new Set(
319320
(parameters.mrf as ParsedMrfWorkflowStep).fields,
320321
)
322+
approvalField =
323+
(parameters.mrf as ParsedMrfWorkflowStep).approvalField ?? null
321324
}
322325

323326
const fieldMetadata: IDataOutMetadata = Object.create(null)
@@ -370,6 +373,11 @@ async function getDataOutMetadata(
370373
isVisible: { isHidden: true },
371374
isHeader: { isHidden: true },
372375
}
376+
377+
if (approvalField && fieldId === approvalField) {
378+
fieldMetadata[fieldId].answer.type = 'approval'
379+
}
380+
373381
if (isAnswerArrayValid(fieldData)) {
374382
// table field will have a stringified table object in the answer field
375383
// so that it can be used in for-each

packages/backend/src/graphql/mutations/create-flow.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ const createFlow: MutationResolvers['createFlow'] = async (
1414
name: trimmedFlowName,
1515
})
1616

17+
/**
18+
* We do not need to create an empty action since the AddStepButton already looks like an empty step
19+
*/
1720
await flow.$relatedQuery('steps').insert([
1821
{
1922
type: 'trigger',
2023
position: 1,
2124
},
22-
{
23-
type: 'action',
24-
position: 2,
25-
},
2625
])
2726

2827
return flow

packages/frontend/src/components/Editor/components/AddStepButton.tsx

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ export function AddStepButton(props: AddStepButtonProps): JSX.Element {
2929
step.config.approval?.branch || approvalBranches[step.id]
3030

3131
const { dividerColor, iconBgColor } = useMemo(() => {
32-
if (approvalBranch === undefined) {
33-
return {
34-
dividerColor: 'base.divider.strong',
35-
iconBgColor: undefined,
36-
}
37-
}
3832
if (approvalBranch === 'approve') {
3933
return {
4034
dividerColor: 'green.500',
4135
iconBgColor: 'green.50',
4236
}
4337
}
38+
if (approvalBranch === 'reject') {
39+
return {
40+
dividerColor: 'red.500',
41+
iconBgColor: 'red.50',
42+
}
43+
}
4444
return {
45-
dividerColor: 'red.500',
46-
iconBgColor: 'red.50',
45+
dividerColor: 'base.divider.strong',
46+
iconBgColor: undefined,
4747
}
4848
}, [approvalBranch])
4949

@@ -58,18 +58,6 @@ export function AddStepButton(props: AddStepButtonProps): JSX.Element {
5858
})
5959

6060
const shouldShowDisabledMrfStep = isLastStep && disabledMrfStepToDisplay
61-
const containerHeight = useMemo(() => {
62-
if (showEmptyAction) {
63-
return undefined
64-
}
65-
if (isHidden) {
66-
return 12
67-
}
68-
if (shouldShowDisabledMrfStep) {
69-
return 36
70-
}
71-
return 16
72-
}, [showEmptyAction, isHidden, shouldShowDisabledMrfStep])
7361

7462
return (
7563
<Box
@@ -78,7 +66,7 @@ export function AddStepButton(props: AddStepButtonProps): JSX.Element {
7866
flexDir="column"
7967
alignItems="center"
8068
alignSelf="stretch"
81-
h={containerHeight}
69+
h="auto"
8270
w="100%"
8371
>
8472
{isHidden || (isDisabled && !isLastStep) ? (
@@ -104,7 +92,7 @@ export function AddStepButton(props: AddStepButtonProps): JSX.Element {
10492
</>
10593
)}
10694
{/* Top vertical line */}
107-
<Box h={6}>
95+
<Box h={4}>
10896
<Divider orientation="vertical" borderColor={dividerColor} />
10997
</Box>
11098
<TouchableTooltip
@@ -136,7 +124,7 @@ export function AddStepButton(props: AddStepButtonProps): JSX.Element {
136124
</TouchableTooltip>
137125
{/* Bottom vertical line */}
138126
{!isLastStep && (
139-
<Box h={6}>
127+
<Box h={4}>
140128
<Divider orientation="vertical" borderColor={dividerColor} />
141129
</Box>
142130
)}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ function VariableTag({
5050
label: 'Tile Row ID',
5151
tooltip: `This variable can be used in Tile's Update Single Row action`,
5252
}
53+
case 'approval':
54+
return {
55+
label: 'Approval',
56+
tooltip: 'This variable determines the approval status of this step',
57+
}
5358
default:
5459
return {
5560
label: null,

packages/frontend/src/contexts/MrfContext.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IStep, IStepApprovalBranch } from '@plumber/types'
22

3-
import { createContext, useContext, useState } from 'react'
3+
import { createContext, useContext, useEffect, useState } from 'react'
44
import get from 'lodash/get'
55

66
import { FORMSG_APP_KEY, MRF_ACTION_KEY } from '@/helpers/formsg'
@@ -29,6 +29,15 @@ interface MrfContextProviderProps {
2929
children: React.ReactNode
3030
}
3131

32+
function generateDefaultApprovalBranches(
33+
mrfApprovalSteps: IStep[],
34+
): Record<string, IStepApprovalBranch> {
35+
return mrfApprovalSteps.reduce((acc, step) => {
36+
acc[step.id] = 'approve'
37+
return acc
38+
}, {} as Record<string, IStepApprovalBranch>)
39+
}
40+
3241
export const MrfContextProvider = ({ children }: MrfContextProviderProps) => {
3342
const { flow } = useContext(EditorContext)
3443

@@ -45,12 +54,14 @@ export const MrfContextProvider = ({ children }: MrfContextProviderProps) => {
4554

4655
const [approvalBranches, setApprovalBranches] = useState<
4756
Record<string, IStepApprovalBranch>
48-
>({
49-
...mrfApprovalSteps.reduce((acc, step) => {
50-
acc[step.id] = 'approve'
51-
return acc
52-
}, {} as Record<string, IStepApprovalBranch>),
53-
})
57+
>(generateDefaultApprovalBranches(mrfApprovalSteps))
58+
59+
/**
60+
* We need to reset the state when the mrf approval steps change
61+
*/
62+
// useEffect(() => {
63+
// setApprovalBranches(generateDefaultApprovalBranches(mrfApprovalSteps))
64+
// }, [mrfApprovalSteps])
5465

5566
const setApprovalBranch = (stepId: string, branch: IStepApprovalBranch) => {
5667
setApprovalBranches((prev) => ({

packages/types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export type TDataOutMetadatumType =
5959
| 'array'
6060
| 'tile_row_id'
6161
| 'table'
62+
| 'approval'
6263

6364
/**
6465
* This should only be defined on _leaf_ nodes (i.e. **primitive array

0 commit comments

Comments
 (0)