-
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): test workflow functionality
- Loading branch information
Showing
37 changed files
with
2,362 additions
and
2,350 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
apps/api/src/app/workflows-v2/usecases/test-data/test-data.command.ts
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 { EnvironmentWithUserObjectCommand } from '@novu/application-generic'; | ||
import { IsDefined, IsString } from 'class-validator'; | ||
|
||
export class WorkflowTestDataCommand extends EnvironmentWithUserObjectCommand { | ||
@IsString() | ||
@IsDefined() | ||
identifierOrInternalId: string; | ||
} |
57 changes: 57 additions & 0 deletions
57
apps/api/src/app/workflows-v2/usecases/test-data/test-data.usecase.ts
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,57 @@ | ||
import { JSONSchema } from 'json-schema-to-ts'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { NotificationTemplateEntity } from '@novu/dal'; | ||
import { UserSessionData, WorkflowTestDataResponseDto } from '@novu/shared'; | ||
|
||
import { WorkflowTestDataCommand } from './test-data.command'; | ||
import { GetWorkflowByIdsUseCase } from '../get-workflow-by-ids/get-workflow-by-ids.usecase'; | ||
import { GetWorkflowByIdsCommand } from '../get-workflow-by-ids/get-workflow-by-ids.command'; | ||
|
||
const buildToFieldSchema = ({ user }: { user: UserSessionData }) => | ||
({ | ||
type: 'object', | ||
properties: { | ||
subscriberId: { type: 'string', default: user._id }, | ||
/* | ||
* TODO: the email and phone fields should be dynamic based on the workflow steps | ||
* if the workflow has has an email step, then email is required etc | ||
*/ | ||
email: { type: 'string', default: user.email ?? '', format: 'email' }, | ||
phone: { type: 'string', default: '' }, | ||
}, | ||
required: ['subscriberId', 'email', 'phone'], | ||
additionalProperties: false, | ||
}) as const satisfies JSONSchema; | ||
|
||
const buildPayloadSchema = () => | ||
({ | ||
type: 'object', | ||
description: 'Schema representing the workflow payload', | ||
properties: { | ||
/* | ||
* TODO: the properties should be dynamic based on the workflow variables | ||
*/ | ||
example: { type: 'string', description: 'Example field', default: 'payload.example' }, | ||
}, | ||
required: ['subscriberId', 'email', 'phone'], | ||
additionalProperties: false, | ||
}) as const satisfies JSONSchema; | ||
|
||
@Injectable() | ||
export class WorkflowTestDataUseCase { | ||
constructor(private getWorkflowByIdsUseCase: GetWorkflowByIdsUseCase) {} | ||
|
||
async execute(command: WorkflowTestDataCommand): Promise<WorkflowTestDataResponseDto> { | ||
const _workflowEntity: NotificationTemplateEntity | null = await this.getWorkflowByIdsUseCase.execute( | ||
GetWorkflowByIdsCommand.create({ | ||
...command, | ||
identifierOrInternalId: command.identifierOrInternalId, | ||
}) | ||
); | ||
|
||
return { | ||
to: buildToFieldSchema({ user: command.user }), | ||
payload: buildPayloadSchema(), | ||
}; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export const Code2: React.FC<React.SVGProps<SVGSVGElement>> = (props) => ( | ||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20" {...props}> | ||
<g clipPath="url(#a)"> | ||
<g clipPath="url(#b)"> | ||
<mask id="c" width="14" height="14" x="3" y="3" maskUnits="userSpaceOnUse" style={{ maskType: 'luminance' }}> | ||
<path fill="#fff" d="M17 3H3v14h14V3Z" /> | ||
</mask> | ||
<g fill="#7D52F4" fillRule="evenodd" clipRule="evenodd" mask="url(#c)"> | ||
<path d="M6.338 4.32c.5-.28 1.045-.37 1.412-.37a.55.55 0 1 1 0 1.1c-.216 0-.57.06-.875.23-.288.161-.515.408-.582.81-.052.31-.055.678-.059 1.116v.057c-.004.438-.01.94-.1 1.404-.09.467-.274.958-.683 1.327-.415.375-.984.556-1.7.556a.55.55 0 1 1 0-1.1c.533 0 .807-.132.962-.272.162-.146.274-.374.34-.72.068-.349.077-.753.08-1.205l.002-.088c.003-.406.006-.857.073-1.255.133-.797.613-1.3 1.13-1.59Z" /> | ||
<path d="M6.338 15.68c.5.28 1.045.37 1.412.37a.55.55 0 0 0 0-1.1c-.216 0-.57-.06-.875-.23-.288-.16-.515-.407-.582-.81-.052-.31-.055-.678-.059-1.116v-.056c-.004-.439-.01-.941-.1-1.404-.09-.467-.274-.958-.683-1.328-.415-.375-.984-.556-1.7-.556a.55.55 0 0 0 0 1.1c.533 0 .807.132.962.272.162.147.274.374.34.72.068.35.077.753.08 1.205l.002.089c.003.406.006.857.073 1.255.133.797.613 1.3 1.13 1.59ZM13.662 4.32c-.499-.28-1.045-.37-1.412-.37a.55.55 0 1 0 0 1.1c.217 0 .57.06.875.23.288.161.515.408.583.81.051.31.054.678.058 1.116v.057c.005.438.011.94.1 1.404.09.467.275.958.683 1.327.415.375.985.556 1.701.556a.55.55 0 0 0 0-1.1c-.533 0-.808-.132-.963-.272-.162-.146-.274-.374-.34-.72-.068-.349-.076-.753-.08-1.205l-.001-.088c-.003-.406-.007-.857-.073-1.255-.133-.797-.614-1.3-1.13-1.59Z" /> | ||
<path d="M13.662 15.68c-.499.28-1.045.37-1.412.37a.55.55 0 0 1 0-1.1c.217 0 .57-.06.875-.23.288-.16.515-.407.583-.81.051-.31.054-.678.058-1.116v-.056c.005-.439.011-.941.1-1.404.09-.467.275-.958.683-1.328.415-.375.985-.556 1.701-.556a.55.55 0 0 1 0 1.1c-.533 0-.808.132-.963.272-.162.147-.274.374-.34.72-.068.35-.076.753-.08 1.205l-.001.089c-.003.406-.007.857-.073 1.255-.133.797-.614 1.3-1.13 1.59ZM8.111 8.111a.55.55 0 0 1 .778 0l3 3a.55.55 0 1 1-.778.778l-3-3a.55.55 0 0 1 0-.778Z" /> | ||
<path d="M11.89 8.111a.55.55 0 0 0-.779 0l-3 3a.55.55 0 1 0 .778.778l3-3a.55.55 0 0 0 0-.778Z" /> | ||
</g> | ||
</g> | ||
</g> | ||
<defs> | ||
<clipPath id="a"> | ||
<path fill="#fff" d="M3 3h14v14H3z" /> | ||
</clipPath> | ||
<clipPath id="b"> | ||
<path fill="#fff" d="M3 3h14v14H3z" /> | ||
</clipPath> | ||
</defs> | ||
</svg> | ||
); |
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,60 @@ | ||
import * as React from 'react'; | ||
import * as AccordionPrimitive from '@radix-ui/react-accordion'; | ||
import { ChevronDownIcon } from '@radix-ui/react-icons'; | ||
|
||
import { cn } from '@/utils/ui'; | ||
|
||
const Accordion = AccordionPrimitive.Root; | ||
|
||
const AccordionItem = React.forwardRef< | ||
React.ElementRef<typeof AccordionPrimitive.Item>, | ||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item> | ||
>(({ className, ...props }, ref) => ( | ||
<AccordionPrimitive.Item | ||
ref={ref} | ||
className={cn('bg-neutral-alpha-50 flex flex-col gap-2 rounded-lg border border-neutral-200 p-2', className)} | ||
{...props} | ||
/> | ||
)); | ||
AccordionItem.displayName = 'AccordionItem'; | ||
|
||
type AccordionTriggerProps = React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger> & { | ||
withChevron?: boolean; | ||
}; | ||
|
||
const AccordionTrigger = React.forwardRef<React.ElementRef<typeof AccordionPrimitive.Trigger>, AccordionTriggerProps>( | ||
({ className, children, withChevron = true, ...props }, ref) => ( | ||
<AccordionPrimitive.Header className="flex"> | ||
<AccordionPrimitive.Trigger | ||
ref={ref} | ||
className={cn( | ||
'flex flex-1 items-center justify-between text-sm font-medium transition-all [&[data-state=open]>svg]:rotate-180', | ||
className | ||
)} | ||
{...props} | ||
> | ||
{children} | ||
{withChevron && ( | ||
<ChevronDownIcon className="text-muted-foreground h-4 w-4 shrink-0 transition-transform duration-200" /> | ||
)} | ||
</AccordionPrimitive.Trigger> | ||
</AccordionPrimitive.Header> | ||
) | ||
); | ||
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName; | ||
|
||
const AccordionContent = React.forwardRef< | ||
React.ElementRef<typeof AccordionPrimitive.Content>, | ||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content> | ||
>(({ className, children, ...props }, ref) => ( | ||
<AccordionPrimitive.Content | ||
ref={ref} | ||
className="data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm" | ||
{...props} | ||
> | ||
<div className={cn('pb-4 pt-0', className)}>{children}</div> | ||
</AccordionPrimitive.Content> | ||
)); | ||
AccordionContent.displayName = AccordionPrimitive.Content.displayName; | ||
|
||
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import { cn } from '@/utils/ui'; | ||
|
||
const Panel = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>( | ||
({ children, className, ...restDivProps }, ref) => { | ||
return ( | ||
<div | ||
ref={ref} | ||
className={cn('bg-neutral-alpha-50 flex flex-col gap-2 rounded-lg border border-neutral-200 p-2', className)} | ||
{...restDivProps} | ||
> | ||
{children} | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
const PanelHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>( | ||
({ children, ...restDivProps }, ref) => { | ||
return ( | ||
<div ref={ref} className="flex items-center gap-1 text-sm font-medium" {...restDivProps}> | ||
{children} | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
const PanelContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>( | ||
({ children, className, ...restDivProps }, ref) => { | ||
return ( | ||
<div | ||
ref={ref} | ||
className={cn('bg-background border-neutral-alpha-200 h-full rounded-lg border border-dashed p-3', className)} | ||
{...restDivProps} | ||
> | ||
{children} | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
export { Panel, PanelHeader, PanelContent }; |
16 changes: 12 additions & 4 deletions
16
apps/dashboard/src/components/primitives/sonner-helpers.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,11 +1,19 @@ | ||
import { ReactNode } from 'react'; | ||
import { ExternalToast, toast } from 'sonner'; | ||
import { SmallToast } from './sonner'; | ||
import { Toast, ToastProps } from './sonner'; | ||
import { ReactNode } from 'react'; | ||
|
||
export const smallToast = ({ children, options }: { children: ReactNode; options: ExternalToast }) => { | ||
return toast(<SmallToast>{children}</SmallToast>, { | ||
export const showToast = ({ | ||
options, | ||
children, | ||
...toastProps | ||
}: Omit<ToastProps, 'children'> & { | ||
options: ExternalToast; | ||
children: (args: { close: () => void }) => ReactNode; | ||
}) => { | ||
return toast.custom((id) => <Toast {...toastProps}>{children({ close: () => toast.dismiss(id) })}</Toast>, { | ||
duration: 5000, | ||
unstyled: true, | ||
closeButton: false, | ||
...options, | ||
}); | ||
}; |
Oops, something went wrong.