-
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 4479 workflow editor configure workflow drawer (#…
- Loading branch information
1 parent
af72058
commit f8fcc82
Showing
9 changed files
with
303 additions
and
32 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
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,45 @@ | ||
import { useState } from 'react'; | ||
import { RiFileCopyLine } from 'react-icons/ri'; | ||
import { Button } from './button'; | ||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from './tooltip'; | ||
|
||
type CopyButtonProps = { | ||
content: string; | ||
className?: string; | ||
}; | ||
|
||
export const CopyButton: React.FC<CopyButtonProps> = ({ content, className }) => { | ||
const [isCopied, setIsCopied] = useState(false); | ||
|
||
const copyToClipboard = async (e: React.MouseEvent<HTMLButtonElement>) => { | ||
e.preventDefault(); | ||
try { | ||
await navigator.clipboard.writeText(content); | ||
setIsCopied(true); | ||
setTimeout(() => setIsCopied(false), 1500); | ||
} catch (err) { | ||
console.error('Failed to copy text: ', err); | ||
} | ||
}; | ||
|
||
return ( | ||
<TooltipProvider> | ||
<Tooltip> | ||
<TooltipTrigger asChild> | ||
<Button | ||
variant="outline" | ||
size="icon" | ||
className={className} | ||
onClick={copyToClipboard} | ||
aria-label="Copy to clipboard" | ||
> | ||
<RiFileCopyLine className="h-4 w-4" /> | ||
</Button> | ||
</TooltipTrigger> | ||
<TooltipContent> | ||
<p>{isCopied ? 'Copied!' : 'Click to copy'}</p> | ||
</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
); | ||
}; |
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,26 @@ | ||
import * as React from 'react'; | ||
import * as SwitchPrimitives from '@radix-ui/react-switch'; | ||
import { cn } from '@/utils/ui'; | ||
|
||
const Switch = React.forwardRef< | ||
React.ElementRef<typeof SwitchPrimitives.Root>, | ||
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root> | ||
>(({ className, ...props }, ref) => ( | ||
<SwitchPrimitives.Root | ||
className={cn( | ||
'focus-visible:ring-ring focus-visible:ring-offset-background data-[state=checked]:bg-primary data-[state=unchecked]:bg-input peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50', | ||
className | ||
)} | ||
{...props} | ||
ref={ref} | ||
> | ||
<SwitchPrimitives.Thumb | ||
className={cn( | ||
'bg-background before:bg-primary data-[state=unchecked]:before:bg-input pointer-events-none flex h-4 w-4 items-center justify-center rounded-full shadow-lg ring-0 transition-transform before:h-1.5 before:w-1.5 before:rounded-full data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0' | ||
)} | ||
/> | ||
</SwitchPrimitives.Root> | ||
)); | ||
Switch.displayName = SwitchPrimitives.Root.displayName; | ||
|
||
export { Switch }; |
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
124 changes: 124 additions & 0 deletions
124
apps/dashboard/src/components/workflow-editor/configure-workflow.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,124 @@ | ||
import { useFormContext } from 'react-hook-form'; | ||
import { RouteFill } from '../icons'; | ||
import { Input, InputField } from '../primitives/input'; | ||
import { RiArrowRightSLine, RiSettingsLine } from 'react-icons/ri'; | ||
import * as z from 'zod'; | ||
import { Separator } from '../primitives/separator'; | ||
import { TagInput } from '../primitives/tag-input'; | ||
import { Textarea } from '../primitives/textarea'; | ||
import { formSchema } from './schema'; | ||
import { useTagsQuery } from '@/hooks/use-tags-query'; | ||
import { Button } from '../primitives/button'; | ||
import { CopyButton } from '../primitives/copy-button'; | ||
import { FormControl, FormField, FormItem, FormLabel, FormMessage } from '../primitives/form/form'; | ||
import { Switch } from '../primitives/switch'; | ||
|
||
export function ConfigureWorkflow() { | ||
const tagsQuery = useTagsQuery(); | ||
|
||
const { control } = useFormContext<z.infer<typeof formSchema>>(); | ||
return ( | ||
<aside className="text-foreground-950 flex h-full w-[300px] max-w-[350px] flex-col border-l pb-5 pt-3.5 [&_input]:text-xs [&_input]:text-neutral-600 [&_label]:text-xs [&_label]:font-medium [&_textarea]:text-xs [&_textarea]:text-neutral-600"> | ||
<div className="flex items-center gap-2.5 px-3 pb-3.5 text-sm font-medium"> | ||
<RouteFill /> | ||
<span>Configure workflow</span> | ||
</div> | ||
<Separator /> | ||
<FormField | ||
control={control} | ||
name="active" | ||
render={({ field }) => ( | ||
<FormItem className="flex items-center justify-between gap-2.5 space-y-0 px-3 py-2"> | ||
<div className="flex items-center gap-4"> | ||
<div | ||
className="bg-success/60 data-[active=false]:shadow-neutral-alpha-100 ml-2 h-1.5 w-1.5 rounded-full [--pulse-color:var(--success)] data-[active=true]:animate-[pulse-shadow_1s_ease-in-out_infinite] data-[active=false]:bg-neutral-300 data-[active=false]:shadow-[0_0px_0px_5px_var(--neutral-alpha-200),0_0px_0px_9px_var(--neutral-alpha-100)]" | ||
data-active={field.value} | ||
/> | ||
<FormLabel>Active Workflow</FormLabel> | ||
</div> | ||
<FormControl> | ||
<Switch checked={field.value} onCheckedChange={field.onChange} /> | ||
</FormControl> | ||
</FormItem> | ||
)} | ||
/> | ||
<Separator /> | ||
<div className="flex flex-col gap-4 p-3"> | ||
<FormField | ||
control={control} | ||
name="name" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Workflow Name</FormLabel> | ||
<FormControl> | ||
<InputField> | ||
<Input placeholder="Untitled" {...field} /> | ||
</InputField> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={control} | ||
name="workflowId" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Workflow Identifier</FormLabel> | ||
<FormControl> | ||
<InputField className="flex overflow-hidden pr-0"> | ||
<Input placeholder="Untitled" {...field} /> | ||
<CopyButton | ||
content={field.value} | ||
className="rounded-md rounded-s-none border-b-0 border-r-0 border-t-0 text-neutral-400" | ||
/> | ||
</InputField> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={control} | ||
name="description" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Description</FormLabel> | ||
<FormControl> | ||
<Textarea placeholder="Description of what this workflow does" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={control} | ||
name="tags" | ||
render={({ field }) => ( | ||
<FormItem className="group" tabIndex={-1}> | ||
<div className="flex items-center gap-1"> | ||
<FormLabel>Tags</FormLabel> | ||
</div> | ||
<FormControl className="text-xs text-neutral-600"> | ||
<TagInput | ||
{...field} | ||
value={field.value ?? []} | ||
suggestions={tagsQuery.data?.data.map((tag) => tag.name) || []} | ||
showAddButton | ||
/> | ||
</FormControl> | ||
</FormItem> | ||
)} | ||
/> | ||
</div> | ||
<Separator /> | ||
<div className="px-3 py-4"> | ||
<Button variant="outline" className="flex w-full justify-start gap-1.5 text-xs font-medium" type="button"> | ||
<RiSettingsLine className="h-4 w-4 text-neutral-600" /> | ||
Configure channel preferences <RiArrowRightSLine className="ml-auto h-4 w-4 text-neutral-600" /> | ||
</Button> | ||
</div> | ||
<Separator /> | ||
</aside> | ||
); | ||
} |
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.