From db32fd6642c8562ccab7c366beb209e82b4f2e5b Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Thu, 29 Dec 2022 11:46:19 +0000 Subject: [PATCH] Redirect on successful test, show events in dropdown if > 1 --- .../workflows/$workflowSlug/index.tsx | 21 ++++++++++++++++++- .../$organizationSlug/test/$workflowSlug.ts | 13 ++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/apps/webapp/app/routes/__app/orgs/$organizationSlug/workflows/$workflowSlug/index.tsx b/apps/webapp/app/routes/__app/orgs/$organizationSlug/workflows/$workflowSlug/index.tsx index b01f2cde9..3319177da 100644 --- a/apps/webapp/app/routes/__app/orgs/$organizationSlug/workflows/$workflowSlug/index.tsx +++ b/apps/webapp/app/routes/__app/orgs/$organizationSlug/workflows/$workflowSlug/index.tsx @@ -7,6 +7,7 @@ import { ConnectionSelector } from "~/components/integrations/ConnectionSelector import { Panel } from "~/components/layout/Panel"; import { PanelHeader } from "~/components/layout/PanelHeader"; import { PrimaryButton } from "~/components/primitives/Buttons"; +import { Select } from "~/components/primitives/Select"; import { Body } from "~/components/primitives/text/Body"; import { Header1, Header2 } from "~/components/primitives/text/Headers"; import { TriggerBody } from "~/components/triggers/Trigger"; @@ -72,6 +73,7 @@ export default function Page() { )} @@ -82,12 +84,15 @@ export default function Page() { function Tester({ organizationSlug, workflowSlug, + eventNames, }: { organizationSlug: string; workflowSlug: string; + eventNames: string[]; }) { const testFetcher = useFetcher(); const [testContent, setTestContent] = useState(""); + const [eventName, setEventName] = useState(eventNames[0]); const submit = useCallback(() => { console.log({ @@ -96,6 +101,7 @@ function Tester({ testFetcher.submit( { + eventName, payload: testContent, }, { @@ -103,10 +109,23 @@ function Tester({ action: `/resources/run/${organizationSlug}/test/${workflowSlug}`, } ); - }, [organizationSlug, testContent, testFetcher, workflowSlug]); + }, [eventName, organizationSlug, testContent, testFetcher, workflowSlug]); return (
+ {eventNames.length > 1 ? ( + + ) : null} { try { const formData = await request.formData(); const body = Object.fromEntries(formData.entries()); - const { payload } = requestSchema.parse(body); + const { eventName, payload } = requestSchema.parse(body); const jsonPayload = JSON.parse(payload); @@ -61,7 +63,7 @@ export const action = async ({ request, params }: ActionArgs) => { await ingestService.call( { id: ulid(), - name: workflow.eventNames[0], + name: eventName, type: workflow.type, service: workflow.service, payload: jsonPayload, @@ -72,8 +74,11 @@ export const action = async ({ request, params }: ActionArgs) => { organization ); - //todo redirect to the runs page - return null; + return redirectWithSuccessMessage( + `/orgs/${organizationSlug}/workflows/${workflowSlug}/runs`, + request, + "Test event successfully sent" + ); } catch (error: any) { console.error(error); throw new Response(error.message, { status: 400 });