-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change workflow queries to use API to get global workflows (#1688)
- Loading branch information
1 parent
5009355
commit f38ba59
Showing
9 changed files
with
136 additions
and
68 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
24 changes: 24 additions & 0 deletions
24
skyvern-frontend/src/routes/workflows/hooks/useGlobalWorkflowsQuery.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,24 @@ | ||
import { getClient } from "@/api/AxiosClient"; | ||
import { useCredentialGetter } from "@/hooks/useCredentialGetter"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { WorkflowApiResponse } from "../types/workflowTypes"; | ||
|
||
function useGlobalWorkflowsQuery() { | ||
const credentialGetter = useCredentialGetter(); | ||
return useQuery({ | ||
queryKey: ["globalWorkflows"], | ||
queryFn: async () => { | ||
const client = await getClient(credentialGetter); | ||
const params = new URLSearchParams(); | ||
params.set("template", "true"); | ||
params.set("page_size", "100"); | ||
return client | ||
.get<Array<WorkflowApiResponse>>("/workflows", { | ||
params, | ||
}) | ||
.then((response) => response.data); | ||
}, | ||
}); | ||
} | ||
|
||
export { useGlobalWorkflowsQuery }; |
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
57 changes: 57 additions & 0 deletions
57
skyvern-frontend/src/routes/workflows/hooks/useWorkflowRunsQuery.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 { getClient } from "@/api/AxiosClient"; | ||
import { Status, WorkflowRunApiResponse } from "@/api/types"; | ||
import { useCredentialGetter } from "@/hooks/useCredentialGetter"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { useGlobalWorkflowsQuery } from "./useGlobalWorkflowsQuery"; | ||
|
||
type QueryReturnType = Array<WorkflowRunApiResponse>; | ||
type UseQueryOptions = Omit< | ||
Parameters<typeof useQuery<QueryReturnType>>[0], | ||
"queryKey" | "queryFn" | "enabled" | ||
>; | ||
|
||
type Props = { | ||
workflowPermanentId?: string; | ||
statusFilters?: Array<Status>; | ||
page: number; | ||
} & UseQueryOptions; | ||
|
||
function useWorkflowRunsQuery({ | ||
workflowPermanentId, | ||
statusFilters, | ||
page, | ||
...queryOptions | ||
}: Props) { | ||
const { data: globalWorkflows } = useGlobalWorkflowsQuery(); | ||
const credentialGetter = useCredentialGetter(); | ||
|
||
return useQuery<Array<WorkflowRunApiResponse>>({ | ||
queryKey: ["workflowRuns", { statusFilters }, workflowPermanentId], | ||
queryFn: async () => { | ||
const client = await getClient(credentialGetter); | ||
const params = new URLSearchParams(); | ||
const isGlobalWorkflow = globalWorkflows?.some( | ||
(workflow) => workflow.workflow_permanent_id === workflowPermanentId, | ||
); | ||
params.append("page", String(page)); | ||
if (isGlobalWorkflow) { | ||
params.append("template", "true"); | ||
} | ||
if (statusFilters) { | ||
statusFilters.forEach((status) => { | ||
params.append("status", status); | ||
}); | ||
} | ||
|
||
return client | ||
.get(`/workflows/${workflowPermanentId}/runs`, { | ||
params, | ||
}) | ||
.then((response) => response.data); | ||
}, | ||
enabled: !!workflowPermanentId && !!globalWorkflows, | ||
...queryOptions, | ||
}); | ||
} | ||
|
||
export { useWorkflowRunsQuery }; |
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