-
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): Delay step custom controls (#7242)
- Loading branch information
Showing
5 changed files
with
55 additions
and
38 deletions.
There are no files selected for viewing
65 changes: 33 additions & 32 deletions
65
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 |
---|---|---|
@@ -1,51 +1,52 @@ | ||
import { useState } from 'react'; | ||
import { ComponentProps, 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'; | ||
import { WorkflowOriginEnum } from '@/utils/enums'; | ||
import { InAppTabsSection } from '@/components/workflow-editor/steps/in-app/in-app-tabs-section'; | ||
import { cn } from '@/utils/ui'; | ||
|
||
export function CustomStepControls({ | ||
dataSchema, | ||
origin, | ||
}: { | ||
type CustomStepControlsProps = ComponentProps<typeof Collapsible> & { | ||
dataSchema: ControlsMetadata['dataSchema']; | ||
origin: WorkflowOriginEnum; | ||
}) { | ||
}; | ||
export const CustomStepControls = (props: CustomStepControlsProps) => { | ||
const { className, dataSchema, origin, ...rest } = props; | ||
const [isEditorOpen, setIsEditorOpen] = useState(true); | ||
|
||
if (!dataSchema?.properties || origin !== WorkflowOriginEnum.EXTERNAL) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<InAppTabsSection> | ||
<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 step controls</span> | ||
</div> | ||
<Collapsible | ||
open={isEditorOpen} | ||
onOpenChange={setIsEditorOpen} | ||
className={cn( | ||
'bg-neutral-alpha-50 border-neutral-alpha-200 flex w-full flex-col gap-2 rounded-lg border p-2 text-sm', | ||
className | ||
)} | ||
{...rest} | ||
> | ||
<CollapsibleTrigger className="flex w-full items-center justify-between"> | ||
<div className="flex items-center gap-1"> | ||
<RiInputField className="text-feature size-5" /> | ||
<span className="font-medium">Custom step controls</span> | ||
</div> | ||
|
||
{isEditorOpen ? ( | ||
<RiArrowUpSLine className="text-neutral-alpha-400 size-5" /> | ||
) : ( | ||
<RiArrowDownSLine className="text-neutral-alpha-400 size-5" /> | ||
)} | ||
</CollapsibleTrigger> | ||
{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 p-3"> | ||
<JsonForm schema={(dataSchema as RJSFSchema) || {}} /> | ||
</div> | ||
</CollapsibleContent> | ||
</Collapsible> | ||
</InAppTabsSection> | ||
<CollapsibleContent> | ||
<div className="bg-background rounded-md border border-dashed p-3"> | ||
<JsonForm schema={(dataSchema as RJSFSchema) || {}} /> | ||
</div> | ||
</CollapsibleContent> | ||
</Collapsible> | ||
); | ||
} | ||
}; |
14 changes: 11 additions & 3 deletions
14
apps/dashboard/src/components/workflow-editor/steps/delay/delay-control-values.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 |
---|---|---|
@@ -1,20 +1,28 @@ | ||
import { UiSchemaGroupEnum } from '@novu/shared'; | ||
import { getComponentByType } from '@/components/workflow-editor/steps/component-utils'; | ||
import { useStep } from '@/components/workflow-editor/steps/step-provider'; | ||
import { CustomStepControls } from '@/components/workflow-editor/steps/controls/custom-step-controls'; | ||
import { useWorkflow } from '@/components/workflow-editor/workflow-provider'; | ||
|
||
const amountKey = 'amount'; | ||
const unitKey = 'unit'; | ||
const typeKey = 'type'; | ||
|
||
export const DelayControlValues = () => { | ||
const { step } = useStep(); | ||
const { uiSchema } = step?.controls ?? {}; | ||
const { workflow } = useWorkflow(); | ||
const { uiSchema, dataSchema } = step?.controls ?? {}; | ||
|
||
if (!uiSchema || uiSchema?.group !== UiSchemaGroupEnum.DELAY) { | ||
if (!uiSchema || !workflow || uiSchema?.group !== UiSchemaGroupEnum.DELAY) { | ||
return null; | ||
} | ||
|
||
const { [amountKey]: amount, [typeKey]: type, [unitKey]: unit } = uiSchema.properties ?? {}; | ||
|
||
return amount && type && unit && getComponentByType({ component: amount.component }); | ||
return ( | ||
<> | ||
{amount && type && unit && getComponentByType({ component: amount.component })} | ||
<CustomStepControls className="text-xs" dataSchema={dataSchema} origin={workflow.origin} /> | ||
</> | ||
); | ||
}; |
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
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