Skip to content

Commit 4657f22

Browse files
authored
PLU-343 [FIND-SINGLE-ROW-3]: show tooltips for variables, show formsg attachment (#954)
### Problem - Certain variable types can be confusing to users, e.g. users may not know what Row ID can be used for - FormSG attachments not showing in output results, users may think that they're not processed ### Solution Add a tag to variables with a explanation tooltip. Also, show all variable types (including files) in output. - Added a new `VariableTag` component that displays tags for specific variable types (array, file, tile_row_id) - Each tag includes a tooltip explaining the variable's purpose - Remove filtering by variable type in TestSubstep output. ![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/ycT2Xb5nBEjN2kf2gy95/93afab7a-a263-4c3c-95c1-0d9ee8136e64.png) ![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/ycT2Xb5nBEjN2kf2gy95/6b4950fb-d058-4dd7-a20e-3db11ceb4623.png) ### How to test? a. Test that FormSG show attachment results in test results b. Test that variables has the appropriate Variable Tag (e.g. attachment, tile row ID, etc.)
1 parent 6646c77 commit 4657f22

File tree

2 files changed

+78
-20
lines changed

2 files changed

+78
-20
lines changed

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ import { EXECUTE_FLOW } from '@/graphql/mutations/execute-flow'
2323
import { EXECUTE_STEP } from '@/graphql/mutations/execute-step'
2424
import { GET_FLOW } from '@/graphql/queries/get-flow'
2525
import { GET_TEST_EXECUTION_STEPS } from '@/graphql/queries/get-test-execution-steps'
26-
import {
27-
extractVariables,
28-
filterVariables,
29-
VISIBLE_VARIABLE_TYPES,
30-
} from '@/helpers/variables'
26+
import { extractVariables } from '@/helpers/variables'
3127

3228
import FlowSubstepTitle from '../FlowSubstepTitle'
3329

@@ -118,13 +114,7 @@ function TestSubstep(props: TestSubstepProps): JSX.Element {
118114
if (!currentExecutionStep) {
119115
return null
120116
}
121-
const stepWithVariables = filterVariables(
122-
extractVariables([currentExecutionStep]),
123-
(variable) => {
124-
const variableType = variable.type ?? 'text'
125-
return VISIBLE_VARIABLE_TYPES.includes(variableType)
126-
},
127-
)
117+
const stepWithVariables = extractVariables([currentExecutionStep])
128118
if (stepWithVariables.length > 0) {
129119
return stepWithVariables[0].output
130120
}

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

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,67 @@
1-
import { Box, Text } from '@chakra-ui/react'
1+
import { TDataOutMetadatumType } from '@plumber/types'
2+
3+
import { useMemo } from 'react'
4+
import { Box, Tag, Text, Tooltip } from '@chakra-ui/react'
25

36
import { type Variable } from '@/helpers/variables'
7+
import { POPOVER_MOTION_PROPS } from '@/theme/constants'
8+
9+
function VariableTag({
10+
type,
11+
}: {
12+
type: TDataOutMetadatumType | null
13+
}): JSX.Element | null {
14+
const { label, tooltip } = useMemo(() => {
15+
switch (type) {
16+
case 'array':
17+
return {
18+
label: 'List',
19+
tooltip: 'This variable can be used in for-each loops (coming soon!)',
20+
}
21+
case 'file':
22+
return {
23+
label: 'File',
24+
tooltip:
25+
'This variable can be used as an attachment in Email by Postman action.',
26+
}
27+
case 'tile_row_id':
28+
return {
29+
label: 'Tile Row ID',
30+
tooltip: `This variable can be used in Tile's Update Single Row action`,
31+
}
32+
default:
33+
return {
34+
label: null,
35+
tooltip: null,
36+
}
37+
}
38+
}, [type])
39+
40+
if (!label) {
41+
return null
42+
}
43+
44+
return (
45+
<Tooltip
46+
label={tooltip}
47+
placement="right"
48+
hasArrow
49+
motionProps={POPOVER_MOTION_PROPS}
50+
>
51+
<Tag size="xs" variant="outline">
52+
{label}
53+
</Tag>
54+
</Tooltip>
55+
)
56+
}
457

5-
function makeVariableComponent(
6-
variable: Variable,
7-
onClick?: (variable: Variable) => void,
8-
): JSX.Element {
58+
function VariableItem({
59+
variable,
60+
onClick,
61+
}: {
62+
variable: Variable
63+
onClick?: (variable: Variable) => void
64+
}): JSX.Element {
965
return (
1066
<Box
1167
key={`suggestion-${variable.name}`}
@@ -37,8 +93,14 @@ function makeVariableComponent(
3793
: undefined
3894
}
3995
>
40-
<Text textStyle="body-1" color="base.content.strong">
41-
{variable.label ?? variable.name}
96+
<Text
97+
textStyle="body-1"
98+
color="base.content.strong"
99+
display="flex"
100+
alignItems="center"
101+
gap={2}
102+
>
103+
{variable.label ?? variable.name} <VariableTag type={variable.type} />
42104
</Text>
43105
<Text textStyle="body-2" color="base.content.medium">
44106
{variable.displayedValue ?? variable.value?.toString() ?? ''}
@@ -66,7 +128,13 @@ export default function VariablesList(props: VariablesListProps) {
66128
overflowY="auto"
67129
p={onClick ? undefined : '1rem'}
68130
>
69-
{variables.map((variable) => makeVariableComponent(variable, onClick))}
131+
{variables.map((variable, index) => (
132+
<VariableItem
133+
key={`variable-${variable.name}-${index}`}
134+
variable={variable}
135+
onClick={onClick}
136+
/>
137+
))}
70138
</Box>
71139
)
72140
}

0 commit comments

Comments
 (0)