Skip to content

Commit aaf483b

Browse files
committed
chore: add prop to rte to only select one variable
1 parent e5003e8 commit aaf483b

File tree

7 files changed

+36
-2
lines changed

7 files changed

+36
-2
lines changed

packages/backend/src/apps/tiles/actions/update-row/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const action: IRawAction = {
4848
op: 'is_empty',
4949
},
5050
variableTypes: ['tile_row_id'],
51+
singleVariableSelection: true,
5152
},
5253
{
5354
label: 'Row data',

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const action: IRawAction = {
2020
required: true,
2121
variables: true,
2222
variableTypes: ['array', 'table'],
23+
singleVariableSelection: true,
2324
},
2425
],
2526

packages/backend/src/graphql/schema.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ type ActionSubstepArgument {
196196
addRowButtonText: String
197197
tooltipText: String
198198

199+
# Only for string and multiline
200+
singleVariableSelection: Boolean
201+
199202
# Only for dropdown
200203
addNewOption: DropdownAddNewOption
201204

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export default function InputCreator(props: InputCreatorProps): JSX.Element {
137137
variableTypes={schema.variableTypes}
138138
parentType={parentType}
139139
autoFocus={autoFocus}
140+
singleVariableSelection={schema.singleVariableSelection}
140141
/>
141142
)
142143
}

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
checkAutoFocus,
4848
genVariableInfoMap,
4949
getPopoverPlacement,
50+
GLOBAL_VARIABLE_REGEX,
5051
singleLineEditorScroll,
5152
substituteOldTemplates,
5253
} from './utils'
@@ -96,6 +97,7 @@ interface EditorProps {
9697
variableTypes?: TDataOutMetadatumType[]
9798
parentType?: string
9899
autoFocus?: boolean
100+
singleVariableSelection?: boolean
99101
}
100102
const Editor = ({
101103
onChange,
@@ -107,6 +109,7 @@ const Editor = ({
107109
isSingleLine,
108110
variableTypes,
109111
parentType,
112+
singleVariableSelection,
110113
autoFocus = false,
111114
}: EditorProps) => {
112115
const { priorExecutionSteps } = useContext(StepExecutionsContext)
@@ -208,6 +211,12 @@ const Editor = ({
208211

209212
const handleVariableClick = useCallback(
210213
(variable: Variable) => {
214+
if (
215+
singleVariableSelection &&
216+
editor?.getText().match(GLOBAL_VARIABLE_REGEX)
217+
) {
218+
return
219+
}
211220
editor?.commands.insertContent({
212221
type: StepVariable.name,
213222
attrs: {
@@ -226,7 +235,7 @@ const Editor = ({
226235
})
227236
}
228237
},
229-
[editor, isMulticol],
238+
[editor, isMulticol, singleVariableSelection],
230239
)
231240

232241
const {
@@ -275,7 +284,15 @@ const Editor = ({
275284
editable={editable ?? false}
276285
/>
277286
)}
278-
<EditorContent className="editor__content" editor={editor} />
287+
<EditorContent
288+
className="editor__content"
289+
editor={editor}
290+
onKeyDown={(e) => {
291+
if (singleVariableSelection) {
292+
e.preventDefault()
293+
}
294+
}}
295+
/>
279296
<Portal>
280297
<PopoverContent
281298
w={isMobile ? '100%' : isMulticol ? '55vw' : '100%'}
@@ -318,6 +335,7 @@ interface RichTextEditorProps {
318335
variableTypes?: TDataOutMetadatumType[]
319336
parentType?: string
320337
autoFocus?: boolean
338+
singleVariableSelection?: boolean
321339
}
322340
const RichTextEditor = ({
323341
required,
@@ -333,6 +351,7 @@ const RichTextEditor = ({
333351
variableTypes,
334352
parentType,
335353
autoFocus,
354+
singleVariableSelection,
336355
}: RichTextEditorProps) => {
337356
const { readOnly } = useContext(EditorContext)
338357
const { control, getValues } = useFormContext()
@@ -379,6 +398,7 @@ const RichTextEditor = ({
379398
variableTypes={variableTypes}
380399
parentType={parentType}
381400
autoFocus={shouldAutoFocus}
401+
singleVariableSelection={singleVariableSelection}
382402
/>
383403
)}
384404
/>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ export const GET_APPS = gql`
215215
label
216216
type
217217
}
218+
singleVariableSelection
218219
# Only for multi-row
219220
subFields {
220221
label
@@ -253,6 +254,7 @@ export const GET_APPS = gql`
253254
value
254255
}
255256
}
257+
singleVariableSelection
256258
}
257259
}
258260
}

packages/types/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ export interface IFieldText extends IBaseField {
349349

350350
// Not applicable if field has variables.
351351
autoComplete?: AutoCompleteValue
352+
353+
// To only allow selection of one variable
354+
singleVariableSelection?: boolean
352355
}
353356

354357
export interface IFieldAttachment extends IBaseField {
@@ -364,6 +367,9 @@ export interface IFieldMultiline extends IBaseField {
364367

365368
// Not applicable if field has variables.
366369
autoComplete?: AutoCompleteValue
370+
371+
// To only allow selection of one variable
372+
singleVariableSelection?: boolean
367373
}
368374

369375
export interface IFieldMultiSelect extends IBaseField {

0 commit comments

Comments
 (0)