Skip to content

Commit 610836f

Browse files
committed
chore: refactor RTE to accept custom menu options
1 parent 66917b4 commit 610836f

File tree

6 files changed

+37
-3
lines changed

6 files changed

+37
-3
lines changed

packages/backend/src/graphql/schema.graphql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ type ActionSubstepArgument {
228228

229229
# Only for multirow
230230
subFields: [ActionSubstepArgument]
231+
232+
# Only for rich text
233+
customRteMenuOptions: [String]
231234
}
232235

233236
type DropdownClickableLink {
@@ -270,6 +273,7 @@ enum AppCategory {
270273
data
271274
communication
272275
logic
276+
ai
273277
others
274278
}
275279

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export default function InputCreator(props: InputCreatorProps): JSX.Element {
145145
variablesEnabled={variables}
146146
isRich
147147
noVariablesMessage={noVariablesMessage}
148+
customRteMenuOptions={schema?.customRteMenuOptions}
148149
/>
149150
)
150151
}

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ enum MenuLabels {
6363
Undo = 'Undo',
6464
Redo = 'Redo',
6565
}
66-
const menuButtons = [
66+
const DEFAULT_MENU_BUTTONS = [
6767
{
6868
label: MenuLabels.Bold,
6969
onClick: (editor: Editor) => editor.chain().focus().toggleBold().run(),
@@ -238,9 +238,15 @@ interface MenuBarProps {
238238
editor: Editor | null
239239
variableMap: VariableInfoMap
240240
editable: boolean
241+
customMenuOptions?: string[]
241242
}
242243

243-
export const MenuBar = ({ editor, variableMap, editable }: MenuBarProps) => {
244+
export const MenuBar = ({
245+
editor,
246+
variableMap,
247+
editable,
248+
customMenuOptions,
249+
}: MenuBarProps) => {
244250
const {
245251
isOpen: isDialogOpen,
246252
onClose,
@@ -321,6 +327,18 @@ export const MenuBar = ({ editor, variableMap, editable }: MenuBarProps) => {
321327
[editor, dialogValue, onDialogClose],
322328
)
323329

330+
const menuButtons = useMemo(() => {
331+
if (customMenuOptions) {
332+
return customMenuOptions
333+
.map((option) =>
334+
DEFAULT_MENU_BUTTONS.find(({ label }) => label === option),
335+
)
336+
.filter((button): button is NonNullable<typeof button> => !!button)
337+
}
338+
339+
return DEFAULT_MENU_BUTTONS
340+
}, [customMenuOptions])
341+
324342
if (!editor) {
325343
return null
326344
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ interface EditorProps {
100100
autoFocus?: boolean
101101
singleVariableSelection?: boolean
102102
noVariablesMessage?: string
103+
customRteMenuOptions?: string[]
103104
}
104105
const Editor = ({
105106
onChange,
@@ -114,6 +115,7 @@ const Editor = ({
114115
singleVariableSelection,
115116
autoFocus = false,
116117
noVariablesMessage,
118+
customRteMenuOptions,
117119
}: EditorProps) => {
118120
const { priorExecutionSteps } = useContext(StepExecutionsContext)
119121
const { allApps } = useContext(EditorContext)
@@ -292,6 +294,7 @@ const Editor = ({
292294
editor={editor}
293295
variableMap={varInfo}
294296
editable={editable ?? false}
297+
customMenuOptions={customRteMenuOptions}
295298
/>
296299
)}
297300
<EditorContent
@@ -348,6 +351,7 @@ interface RichTextEditorProps {
348351
autoFocus?: boolean
349352
singleVariableSelection?: boolean
350353
noVariablesMessage?: string
354+
customRteMenuOptions?: string[]
351355
}
352356
const RichTextEditor = ({
353357
required,
@@ -365,6 +369,7 @@ const RichTextEditor = ({
365369
autoFocus,
366370
singleVariableSelection,
367371
noVariablesMessage,
372+
customRteMenuOptions,
368373
}: RichTextEditorProps) => {
369374
const { readOnly } = useContext(EditorContext)
370375
const { control, getValues } = useFormContext()
@@ -413,6 +418,7 @@ const RichTextEditor = ({
413418
autoFocus={shouldAutoFocus}
414419
singleVariableSelection={singleVariableSelection}
415420
noVariablesMessage={noVariablesMessage}
421+
customRteMenuOptions={customRteMenuOptions}
416422
/>
417423
)}
418424
/>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ export const GET_APPS = gql`
226226
url
227227
}
228228
singleVariableSelection
229+
customRteMenuOptions
229230
# Only for multi-row
230231
subFields {
231232
label

packages/types/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@ export interface IFieldMultiRow extends IBaseField {
448448
export interface IFieldRichText extends IBaseField {
449449
type: 'rich-text'
450450
value?: string
451+
452+
// Specifies the order and what menu options to show in the RTE
453+
// 'divider' is specified manually to determine when a divider should be shown
454+
customRteMenuOptions?: string[]
451455
}
452456

453457
export interface IFieldDragDrop extends IBaseField {
@@ -612,7 +616,7 @@ export interface IApp {
612616
setupMessage?: SetupMessage
613617
}
614618

615-
export type AppCategory = 'data' | 'communication' | 'logic' | 'others'
619+
export type AppCategory = 'data' | 'communication' | 'logic' | 'others' | 'ai'
616620

617621
export type TBeforeRequest = (
618622
$: IGlobalVariable,

0 commit comments

Comments
 (0)