Skip to content

Commit d9c692d

Browse files
committed
chore: refactor RTE to accept custom menu options
1 parent cd478e9 commit d9c692d

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
@@ -220,6 +220,9 @@ type ActionSubstepArgument {
220220

221221
# Only for multirow
222222
subFields: [ActionSubstepArgument]
223+
224+
# Only for rich text
225+
customRteMenuOptions: [String]
223226
}
224227

225228
type DropdownClickableLink {
@@ -262,6 +265,7 @@ enum AppCategory {
262265
data
263266
communication
264267
logic
268+
ai
265269
others
266270
}
267271

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export default function InputCreator(props: InputCreatorProps): JSX.Element {
121121
variablesEnabled={variables}
122122
isRich
123123
noVariablesMessage={noVariablesMessage}
124+
customRteMenuOptions={schema?.customRteMenuOptions}
124125
/>
125126
)
126127
}

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
@@ -435,6 +435,10 @@ export interface IFieldMultiRow extends IBaseField {
435435
export interface IFieldRichText extends IBaseField {
436436
type: 'rich-text'
437437
value?: string
438+
439+
// Specifies the order and what menu options to show in the RTE
440+
// 'divider' is specified manually to determine when a divider should be shown
441+
customRteMenuOptions?: string[]
438442
}
439443

440444
export interface IFieldDragDrop extends IBaseField {
@@ -599,7 +603,7 @@ export interface IApp {
599603
setupMessage?: SetupMessage
600604
}
601605

602-
export type AppCategory = 'data' | 'communication' | 'logic' | 'others'
606+
export type AppCategory = 'data' | 'communication' | 'logic' | 'others' | 'ai'
603607

604608
export type TBeforeRequest = (
605609
$: IGlobalVariable,

0 commit comments

Comments
 (0)