-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(dashboard): Nv 4516 in app step editor custom step controls form #6900
Merged
BiswaViraj
merged 8 commits into
next
from
nv-4516-in-app-step-editor-custom-step-controls-form
Nov 8, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8a88d7c
feat(dashboard): in-app editor schema driven form
LetItRock b3fe5ae
feat(dashboard): add TextWidget and CustomStepControls components
BiswaViraj ff04844
update
BiswaViraj 1873c9c
feat(dashboard): add new widgets and enhance CustomStepControls with …
BiswaViraj c437f71
fix(dashboard): prevent rendering CustomStepControls when dataSchema …
BiswaViraj a9ebd1a
merge
BiswaViraj 5f1fbfe
fix: padding
BiswaViraj 71d0703
fix(workflow-editor): update link routing for step nodes to use build…
BiswaViraj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
apps/dashboard/src/components/workflow-editor/steps/controls/custom-step-controls.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useState } from 'react'; | ||
import { RJSFSchema } from '@rjsf/utils'; | ||
import { RiArrowDownSLine, RiArrowUpSLine, RiInputField } from 'react-icons/ri'; | ||
import { type ControlsMetadata } from '@novu/shared'; | ||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/primitives/collapsible'; | ||
import { JsonForm } from './json-form'; | ||
|
||
export function CustomStepControls({ dataSchema }: { dataSchema: ControlsMetadata['dataSchema'] }) { | ||
const [isEditorOpen, setIsEditorOpen] = useState(true); | ||
|
||
if (!dataSchema) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Collapsible | ||
open={isEditorOpen} | ||
onOpenChange={setIsEditorOpen} | ||
className="bg-neutral-alpha-50 border-neutral-alpha-200 flex w-full flex-col gap-2 rounded-lg border p-2" | ||
> | ||
<CollapsibleTrigger className="flex w-full items-center justify-between text-sm"> | ||
<div className="flex items-center gap-1"> | ||
<RiInputField className="text-feature size-5" /> | ||
<span className="text-sm font-medium">Custom steps controls</span> | ||
</div> | ||
|
||
{isEditorOpen ? ( | ||
<RiArrowUpSLine className="text-neutral-alpha-400 size-5" /> | ||
) : ( | ||
<RiArrowDownSLine className="text-neutral-alpha-400 size-5" /> | ||
)} | ||
</CollapsibleTrigger> | ||
|
||
<CollapsibleContent> | ||
<div className="bg-background rounded-md border border-dashed px-3 py-0"> | ||
<JsonForm schema={(dataSchema as RJSFSchema) || {}} variables={[]} /> | ||
</div> | ||
</CollapsibleContent> | ||
</Collapsible> | ||
); | ||
} |
55 changes: 55 additions & 0 deletions
55
apps/dashboard/src/components/workflow-editor/steps/controls/json-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Form, { FormProps } from '@rjsf/core'; | ||
import { RegistryWidgetsType, UiSchema } from '@rjsf/utils'; | ||
import validator from '@rjsf/validator-ajv8'; | ||
import { TextWidget } from './text-widget'; | ||
import { SwitchWidget } from './switch-widget'; | ||
import { SelectWidget } from './select-widget'; | ||
|
||
export const JSON_SCHEMA_FORM_ID_DELIMITER = '~~~'; | ||
|
||
const UI_SCHEMA: UiSchema = { | ||
'ui:globalOptions': { addable: true, copyable: false, label: true, orderable: true }, | ||
'ui:options': { | ||
hideError: true, | ||
submitButtonOptions: { | ||
norender: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const WIDGETS: RegistryWidgetsType = { | ||
TextWidget: TextWidget, | ||
URLWidget: TextWidget, | ||
EmailWidget: TextWidget, | ||
CheckboxWidget: SwitchWidget, | ||
SelectWidget: SelectWidget, | ||
}; | ||
|
||
type JsonFormProps<TFormData = unknown> = Pick< | ||
FormProps<TFormData>, | ||
'onChange' | 'onSubmit' | 'onBlur' | 'schema' | 'formData' | 'tagName' | 'onError' | ||
> & { | ||
variables?: string[]; | ||
}; | ||
|
||
export function JsonForm(props: JsonFormProps) { | ||
return ( | ||
<Form | ||
tagName={'fieldset'} | ||
className="[&_.control-label]:hidden [&_.field-decription]:hidden [&_.panel.panel-danger.errors]:hidden" | ||
uiSchema={UI_SCHEMA} | ||
widgets={WIDGETS} | ||
validator={validator} | ||
autoComplete={'false'} | ||
/** | ||
* TODO: Add support for variables | ||
*/ | ||
formContext={{ variables: [] }} | ||
idSeparator={JSON_SCHEMA_FORM_ID_DELIMITER} | ||
{...props} | ||
/** | ||
* TODO: Add support for Arrays and Nested Objects | ||
*/ | ||
/> | ||
); | ||
} |
49 changes: 49 additions & 0 deletions
49
apps/dashboard/src/components/workflow-editor/steps/controls/select-widget.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { type WidgetProps } from '@rjsf/utils'; | ||
import { useFormContext } from 'react-hook-form'; | ||
import { FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/primitives/form/form'; | ||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/primitives/select'; | ||
import { capitalize } from '@/utils/string'; | ||
|
||
export function SelectWidget(props: WidgetProps) { | ||
const { label, required, readonly, options, name } = props; | ||
|
||
const data = options.enumOptions?.map((option) => { | ||
return { | ||
label: option.label, | ||
value: String(option.value), | ||
}; | ||
}); | ||
|
||
const { control } = useFormContext(); | ||
|
||
return ( | ||
<FormField | ||
control={control} | ||
name={name} | ||
render={({ field }) => ( | ||
<FormItem className="my-2 py-1"> | ||
<FormLabel>{capitalize(label)}</FormLabel> | ||
<FormControl> | ||
<Select value={field.value} onValueChange={field.onChange} disabled={readonly} required={required}> | ||
<SelectTrigger className="group p-1.5 shadow-sm last:[&>svg]:hidden"> | ||
<SelectValue asChild> | ||
<div className="flex items-center gap-2"> | ||
<span className="text-foreground text-sm">{field.value}</span> | ||
</div> | ||
</SelectValue> | ||
</SelectTrigger> | ||
<SelectContent> | ||
{data?.map((item) => ( | ||
<SelectItem key={item.value} value={item.value}> | ||
{item.label} | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
); | ||
} |
29 changes: 29 additions & 0 deletions
29
apps/dashboard/src/components/workflow-editor/steps/controls/switch-widget.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { type WidgetProps } from '@rjsf/utils'; | ||
import { useFormContext } from 'react-hook-form'; | ||
import { FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/primitives/form/form'; | ||
import { Switch } from '@/components/primitives/switch'; | ||
import { capitalize } from '@/utils/string'; | ||
|
||
export function SwitchWidget(props: WidgetProps) { | ||
const { label, readonly, name } = props; | ||
|
||
const { control } = useFormContext(); | ||
|
||
return ( | ||
<FormField | ||
control={control} | ||
name={name} | ||
render={({ field }) => ( | ||
<FormItem> | ||
<div className="my-2 flex w-full items-center justify-between space-y-0 py-1"> | ||
<FormLabel className="cursor-pointer">{capitalize(label)}</FormLabel> | ||
<FormControl> | ||
<Switch checked={field.value} onCheckedChange={field.onChange} disabled={readonly} /> | ||
</FormControl> | ||
</div> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
); | ||
} |
48 changes: 48 additions & 0 deletions
48
apps/dashboard/src/components/workflow-editor/steps/controls/text-widget.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { type WidgetProps } from '@rjsf/utils'; | ||
import { EditorView } from '@uiw/react-codemirror'; | ||
import { liquid } from '@codemirror/lang-liquid'; | ||
import { useFormContext } from 'react-hook-form'; | ||
import { Editor } from '@/components/primitives/editor'; | ||
import { FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/primitives/form/form'; | ||
import { InputField } from '@/components/primitives/input'; | ||
import { capitalize } from '@/utils/string'; | ||
|
||
export function TextWidget(props: WidgetProps) { | ||
const { label, readonly, name } = props; | ||
|
||
const { | ||
control, | ||
formState: { errors }, | ||
} = useFormContext(); | ||
|
||
return ( | ||
<FormField | ||
control={control} | ||
name={name} | ||
render={({ field }) => ( | ||
<FormItem className="my-2 w-full py-1"> | ||
<FormLabel>{capitalize(label)}</FormLabel> | ||
<FormControl> | ||
<InputField size="md" className="px-1" state={errors[name] ? 'error' : 'default'}> | ||
<Editor | ||
placeholder={capitalize(label)} | ||
size="md" | ||
id={label} | ||
extensions={[ | ||
liquid({ | ||
variables: [{ type: 'variable', label: 'asdf' }], | ||
}), | ||
EditorView.lineWrapping, | ||
]} | ||
value={field.value} | ||
onChange={(val) => field.onChange(val)} | ||
readOnly={readonly} | ||
/> | ||
</InputField> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added boolean support