-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: implement workflow chat interface * chore: rework params section in workflow form * feat: add params form to workflow invoke button * fix: load workflow directly when invoking * feat: move workflow param form to invoke button on inital trigger
- Loading branch information
1 parent
1faeb44
commit 6254fe3
Showing
12 changed files
with
331 additions
and
180 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
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,73 @@ | ||
import { ComponentProps, useState } from "react"; | ||
import useSWR from "swr"; | ||
|
||
import { WorkflowService } from "~/lib/service/api/workflowService"; | ||
|
||
import { RunWorkflowForm } from "~/components/chat/RunWorkflowForm"; | ||
import { Button, ButtonProps } from "~/components/ui/button"; | ||
import { | ||
Popover, | ||
PopoverContent, | ||
PopoverTrigger, | ||
} from "~/components/ui/popover"; | ||
|
||
type RunWorkflowProps = { | ||
onSubmit: (params?: Record<string, string>) => void; | ||
workflowId: string; | ||
popoverContentProps?: ComponentProps<typeof PopoverContent>; | ||
}; | ||
|
||
export function RunWorkflow({ | ||
workflowId, | ||
onSubmit, | ||
...props | ||
}: RunWorkflowProps & ButtonProps) { | ||
const [open, setOpen] = useState(false); | ||
|
||
const { data: workflow, isLoading } = useSWR( | ||
WorkflowService.getWorkflowById.key(workflowId), | ||
({ workflowId }) => WorkflowService.getWorkflowById(workflowId) | ||
); | ||
|
||
const params = workflow?.params; | ||
|
||
if (!params || isLoading) | ||
return ( | ||
<Button | ||
onClick={() => onSubmit()} | ||
{...props} | ||
disabled={props.disabled || isLoading} | ||
loading={isLoading || props.loading} | ||
> | ||
Run Workflow | ||
</Button> | ||
); | ||
|
||
return ( | ||
<Popover open={open} onOpenChange={setOpen}> | ||
<PopoverTrigger asChild> | ||
<Button | ||
{...props} | ||
disabled={props.disabled || open || isLoading} | ||
loading={props.loading || isLoading} | ||
onClick={() => setOpen((prev) => !prev)} | ||
> | ||
Run Workflow | ||
</Button> | ||
</PopoverTrigger> | ||
|
||
<PopoverContent | ||
{...props.popoverContentProps} | ||
className="min-w-full" | ||
> | ||
<RunWorkflowForm | ||
params={params} | ||
onSubmit={(params) => { | ||
setOpen(false); | ||
onSubmit(params); | ||
}} | ||
/> | ||
</PopoverContent> | ||
</Popover> | ||
); | ||
} |
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,44 @@ | ||
import { useMemo } from "react"; | ||
import { useForm } from "react-hook-form"; | ||
|
||
import { ControlledInput } from "~/components/form/controlledInputs"; | ||
import { Button } from "~/components/ui/button"; | ||
import { Form } from "~/components/ui/form"; | ||
|
||
type RunWorkflowFormProps = { | ||
params: Record<string, string>; | ||
onSubmit: (params: Record<string, string>) => void; | ||
}; | ||
|
||
export function RunWorkflowForm({ params, onSubmit }: RunWorkflowFormProps) { | ||
const defaultValues = useMemo(() => { | ||
return Object.keys(params).reduce( | ||
(acc, key) => { | ||
acc[key] = ""; | ||
return acc; | ||
}, | ||
{} as Record<string, string> | ||
); | ||
}, [params]); | ||
|
||
const form = useForm({ defaultValues }); | ||
const handleSubmit = form.handleSubmit(onSubmit); | ||
|
||
return ( | ||
<Form {...form}> | ||
<form onSubmit={handleSubmit} className="flex flex-col gap-2"> | ||
{Object.entries(params).map(([name, description]) => ( | ||
<ControlledInput | ||
key={name} | ||
control={form.control} | ||
name={name} | ||
label={name} | ||
description={description} | ||
/> | ||
))} | ||
|
||
<Button type="submit">Run Workflow</Button> | ||
</form> | ||
</Form> | ||
); | ||
} |
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.