Change workflow queries to use API to get global workflows (#1688)

This commit is contained in:
Shuchang Zheng
2025-02-01 03:06:09 +08:00
committed by GitHub
parent 5009355cb0
commit f38ba59bed
9 changed files with 137 additions and 69 deletions

View File

@@ -4,6 +4,7 @@ import { useCredentialGetter } from "@/hooks/useCredentialGetter";
import { useQuery } from "@tanstack/react-query";
import { WorkflowApiResponse } from "./types/workflowTypes";
import { apiPathPrefix } from "@/util/env";
import { useGlobalWorkflowsQuery } from "./hooks/useGlobalWorkflowsQuery";
type Props = {
workflowPermanentId: string;
@@ -11,6 +12,7 @@ type Props = {
function WorkflowTitle({ workflowPermanentId }: Props) {
const credentialGetter = useCredentialGetter();
const { data: globalWorkflows } = useGlobalWorkflowsQuery();
const {
data: workflow,
@@ -20,10 +22,18 @@ function WorkflowTitle({ workflowPermanentId }: Props) {
queryKey: ["workflow", workflowPermanentId],
queryFn: async () => {
const client = await getClient(credentialGetter);
const isGlobalWorkflow = globalWorkflows?.some(
(workflow) => workflow.workflow_permanent_id === workflowPermanentId,
);
const params = new URLSearchParams();
if (isGlobalWorkflow) {
params.set("template", "true");
}
return client
.get(`${apiPathPrefix}/workflows/${workflowPermanentId}`)
.get(`${apiPathPrefix}/workflows/${workflowPermanentId}`, { params })
.then((response) => response.data);
},
enabled: !!globalWorkflows && !!workflowPermanentId,
});
if (isLoading) {