-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboard): Nv 4885 push step editor (#7306)
- Loading branch information
1 parent
c27185e
commit 75af9d3
Showing
9 changed files
with
192 additions
and
2 deletions.
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
55 changes: 55 additions & 0 deletions
55
apps/dashboard/src/components/workflow-editor/steps/base/base-body.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 { EditorView } from '@uiw/react-codemirror'; | ||
import { useMemo } from 'react'; | ||
import { useFormContext } from 'react-hook-form'; | ||
|
||
import { Editor } from '@/components/primitives/editor'; | ||
import { FormControl, FormField, FormItem, FormMessage } from '@/components/primitives/form/form'; | ||
import { InputField } from '@/components/primitives/input'; | ||
import { completions } from '@/utils/liquid-autocomplete'; | ||
import { parseStepVariablesToLiquidVariables } from '@/utils/parseStepVariablesToLiquidVariables'; | ||
import { capitalize } from '@/utils/string'; | ||
import { autocompletion } from '@codemirror/autocomplete'; | ||
import { useWorkflow } from '@/components/workflow-editor/workflow-provider'; | ||
|
||
const bodyKey = 'body'; | ||
|
||
const basicSetup = { | ||
defaultKeymap: true, | ||
}; | ||
|
||
export const BaseBody = () => { | ||
const { control } = useFormContext(); | ||
const { step } = useWorkflow(); | ||
const variables = useMemo(() => (step ? parseStepVariablesToLiquidVariables(step.variables) : []), [step]); | ||
const extensions = useMemo( | ||
() => [autocompletion({ override: [completions(variables)] }), EditorView.lineWrapping], | ||
[variables] | ||
); | ||
|
||
return ( | ||
<FormField | ||
control={control} | ||
name={bodyKey} | ||
render={({ field }) => ( | ||
<FormItem className="w-full"> | ||
<FormControl> | ||
<InputField className="h-36 px-1"> | ||
<Editor | ||
fontFamily="inherit" | ||
placeholder={capitalize(field.name)} | ||
id={field.name} | ||
extensions={extensions} | ||
basicSetup={basicSetup} | ||
ref={field.ref} | ||
value={field.value} | ||
onChange={field.onChange} | ||
height="100%" | ||
/> | ||
</InputField> | ||
</FormControl> | ||
<FormMessage>{`This supports markdown and variables, type { for more.`}</FormMessage> | ||
</FormItem> | ||
)} | ||
/> | ||
); | ||
}; |
48 changes: 48 additions & 0 deletions
48
apps/dashboard/src/components/workflow-editor/steps/base/base-subject.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 { useMemo } from 'react'; | ||
import { EditorView } from '@uiw/react-codemirror'; | ||
import { useFormContext } from 'react-hook-form'; | ||
|
||
import { Editor } from '@/components/primitives/editor'; | ||
import { FormControl, FormField, FormItem, FormMessage } from '@/components/primitives/form/form'; | ||
import { InputField } from '@/components/primitives/input'; | ||
import { completions } from '@/utils/liquid-autocomplete'; | ||
import { parseStepVariablesToLiquidVariables } from '@/utils/parseStepVariablesToLiquidVariables'; | ||
import { capitalize } from '@/utils/string'; | ||
import { autocompletion } from '@codemirror/autocomplete'; | ||
import { useWorkflow } from '@/components/workflow-editor/workflow-provider'; | ||
|
||
const subjectKey = 'subject'; | ||
|
||
export const BaseSubject = () => { | ||
const { control } = useFormContext(); | ||
const { step } = useWorkflow(); | ||
const variables = useMemo(() => (step ? parseStepVariablesToLiquidVariables(step.variables) : []), [step]); | ||
const extensions = useMemo( | ||
() => [autocompletion({ override: [completions(variables)] }), EditorView.lineWrapping], | ||
[variables] | ||
); | ||
|
||
return ( | ||
<FormField | ||
control={control} | ||
name={subjectKey} | ||
render={({ field }) => ( | ||
<FormItem className="w-full"> | ||
<FormControl> | ||
<InputField size="fit" className="px-1"> | ||
<Editor | ||
fontFamily="inherit" | ||
placeholder={capitalize(field.name)} | ||
id={field.name} | ||
extensions={extensions} | ||
value={field.value} | ||
onChange={field.onChange} | ||
/> | ||
</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
28 changes: 28 additions & 0 deletions
28
apps/dashboard/src/components/workflow-editor/steps/push/push-editor.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,28 @@ | ||
import { getComponentByType } from '@/components/workflow-editor/steps/component-utils'; | ||
import { PushTabsSection } from '@/components/workflow-editor/steps/push/push-tabs-section'; | ||
import { type UiSchema } from '@novu/shared'; | ||
import { RiCellphoneFill } from 'react-icons/ri'; | ||
|
||
const subjectKey = 'subject'; | ||
const bodyKey = 'body'; | ||
|
||
type PushEditorProps = { uiSchema: UiSchema }; | ||
export const PushEditor = (props: PushEditorProps) => { | ||
const { uiSchema } = props; | ||
const { [bodyKey]: body, [subjectKey]: subject } = uiSchema?.properties ?? {}; | ||
|
||
return ( | ||
<div className="flex h-full flex-col"> | ||
<PushTabsSection className="py-5"> | ||
<div className="flex items-center gap-2.5 pb-2 text-sm font-medium"> | ||
<RiCellphoneFill className="size-3" /> | ||
<span>Push template editor</span> | ||
</div> | ||
<div className="flex flex-col gap-1 rounded-lg border border-neutral-100 p-1"> | ||
{getComponentByType({ component: subject.component })} | ||
{getComponentByType({ component: body.component })} | ||
</div> | ||
</PushTabsSection> | ||
</div> | ||
); | ||
}; |
8 changes: 8 additions & 0 deletions
8
apps/dashboard/src/components/workflow-editor/steps/push/push-tabs-section.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,8 @@ | ||
import { cn } from '@/utils/ui'; | ||
import { HTMLAttributes } from 'react'; | ||
|
||
type PushTabsSectionProps = HTMLAttributes<HTMLDivElement>; | ||
export const PushTabsSection = (props: PushTabsSectionProps) => { | ||
const { className, ...rest } = props; | ||
return <div className={cn('px-4 py-3', className)} {...rest} />; | ||
}; |
33 changes: 33 additions & 0 deletions
33
apps/dashboard/src/components/workflow-editor/steps/push/push-tabs.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,33 @@ | ||
import { useState } from 'react'; | ||
import { WorkflowOriginEnum } from '@novu/shared'; | ||
import { StepEditorProps } from '@/components/workflow-editor/steps/configure-step-template-form'; | ||
import { PushEditor } from '@/components/workflow-editor/steps/push/push-editor'; | ||
import { CustomStepControls } from '../controls/custom-step-controls'; | ||
import { TemplateTabs } from '../template-tabs'; | ||
|
||
export const PushTabs = (props: StepEditorProps) => { | ||
const { workflow, step } = props; | ||
const { dataSchema, uiSchema } = step.controls; | ||
const [tabsValue, setTabsValue] = useState('editor'); | ||
|
||
const isNovuCloud = workflow.origin === WorkflowOriginEnum.NOVU_CLOUD && uiSchema; | ||
const isExternal = workflow.origin === WorkflowOriginEnum.EXTERNAL; | ||
|
||
const editorContent = ( | ||
<> | ||
{isNovuCloud && <PushEditor uiSchema={uiSchema} />} | ||
{isExternal && <CustomStepControls dataSchema={dataSchema} origin={workflow.origin} />} | ||
</> | ||
); | ||
|
||
const previewContent = <>TODO</>; | ||
|
||
return ( | ||
<TemplateTabs | ||
editorContent={editorContent} | ||
previewContent={previewContent} | ||
tabsValue={tabsValue} | ||
onTabChange={setTabsValue} | ||
/> | ||
); | ||
}; |
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