Skip to content

Commit 8b19830

Browse files
committed
chore: custom message for no variables
1 parent cdf3110 commit 8b19830

File tree

7 files changed

+20
-2
lines changed

7 files changed

+20
-2
lines changed

packages/backend/src/apps/toolbox/actions/for-each/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const action: IRawAction = {
3939
variables: true,
4040
variableTypes: ['array', 'table'],
4141
singleVariableSelection: true,
42+
noVariablesMessage:
43+
' No variables available - add one of the following steps above: Find multiple rows, Find multiple table rows, or include a checkbox/table field in your FormSG.',
4244
},
4345
],
4446

packages/backend/src/graphql/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ type ActionSubstepArgument {
207207
hiddenIf: FieldVisibilityCondition
208208
addRowButtonText: String
209209
tooltipText: String
210+
noVariablesMessage: String
210211

211212
# Only for string and multiline
212213
singleVariableSelection: Boolean

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default function InputCreator(props: InputCreatorProps): JSX.Element {
4343
type,
4444
placeholder,
4545
tooltipText,
46+
noVariablesMessage,
4647
} = schema
4748

4849
const computedName = namePrefix ? `${namePrefix}.${name}` : name
@@ -119,6 +120,7 @@ export default function InputCreator(props: InputCreatorProps): JSX.Element {
119120
placeholder={placeholder}
120121
variablesEnabled={variables}
121122
isRich
123+
noVariablesMessage={noVariablesMessage}
122124
/>
123125
)
124126
}
@@ -139,6 +141,7 @@ export default function InputCreator(props: InputCreatorProps): JSX.Element {
139141
parentType={parentType}
140142
autoFocus={autoFocus}
141143
singleVariableSelection={schema.singleVariableSelection}
144+
noVariablesMessage={noVariablesMessage}
142145
/>
143146
)
144147
}

packages/frontend/src/components/RichTextEditor/Suggestions.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import SuggestionsWrapper from '../SuggestionsWrapper'
99
interface SuggestionsProps {
1010
data: StepWithVariables[]
1111
onSuggestionClick: (variable: Variable) => void
12+
noVariablesMessage?: string
1213
}
1314

1415
function Suggestions(props: SuggestionsProps) {
15-
const { data, onSuggestionClick = () => null } = props
16+
const { data, onSuggestionClick = () => null, noVariablesMessage } = props
1617
const [current, setCurrent] = useState<number>(0)
1718

1819
const isEmpty = data.reduce(
@@ -23,7 +24,8 @@ function Suggestions(props: SuggestionsProps) {
2324
if (isEmpty) {
2425
return (
2526
<Text p={4} opacity={0.5} textStyle="body-1" color="base.content.medium">
26-
No variables available - complete earlier steps to use them here
27+
{noVariablesMessage ??
28+
'No variables available - complete earlier steps to use them here'}
2729
</Text>
2830
)
2931
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ interface EditorProps {
9999
parentType?: string
100100
autoFocus?: boolean
101101
singleVariableSelection?: boolean
102+
noVariablesMessage?: string
102103
}
103104
const Editor = ({
104105
onChange,
@@ -112,6 +113,7 @@ const Editor = ({
112113
parentType,
113114
singleVariableSelection,
114115
autoFocus = false,
116+
noVariablesMessage,
115117
}: EditorProps) => {
116118
const { priorExecutionSteps } = useContext(StepExecutionsContext)
117119
const { allApps } = useContext(EditorContext)
@@ -319,6 +321,7 @@ const Editor = ({
319321
<Suggestions
320322
data={stepsWithVariables}
321323
onSuggestionClick={(v) => editable && handleVariableClick(v)}
324+
noVariablesMessage={noVariablesMessage}
322325
/>
323326
</PopoverContent>
324327
</Portal>
@@ -344,6 +347,7 @@ interface RichTextEditorProps {
344347
parentType?: string
345348
autoFocus?: boolean
346349
singleVariableSelection?: boolean
350+
noVariablesMessage?: string
347351
}
348352
const RichTextEditor = ({
349353
required,
@@ -360,6 +364,7 @@ const RichTextEditor = ({
360364
parentType,
361365
autoFocus,
362366
singleVariableSelection,
367+
noVariablesMessage,
363368
}: RichTextEditorProps) => {
364369
const { readOnly } = useContext(EditorContext)
365370
const { control, getValues } = useFormContext()
@@ -407,6 +412,7 @@ const RichTextEditor = ({
407412
parentType={parentType}
408413
autoFocus={shouldAutoFocus}
409414
singleVariableSelection={singleVariableSelection}
415+
noVariablesMessage={noVariablesMessage}
410416
/>
411417
)}
412418
/>

packages/frontend/src/graphql/queries/get-apps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export const GET_APPS = gql`
195195
customStyle
196196
tooltipText
197197
value
198+
noVariablesMessage
198199
options {
199200
label
200201
description

packages/types/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ export interface IBaseField {
318318
* other array elements).
319319
*/
320320
hiddenIf?: IFieldVisibilityCondition
321+
322+
// message to show when no variables are available
323+
noVariablesMessage?: string
321324
}
322325

323326
export type DropdownAddNewType = 'modal' | 'inline'

0 commit comments

Comments
 (0)