UI for workflow templates (#1715)

Co-authored-by: Muhammed Salih Altun <muhammedsalihaltun@gmail.com>
This commit is contained in:
Shuchang Zheng
2025-02-04 21:40:55 +08:00
committed by GitHub
parent e2d3d7fec5
commit d34a403c8f
27 changed files with 673 additions and 330 deletions

View File

@@ -0,0 +1,35 @@
import { getClient } from "@/api/AxiosClient";
import { useCredentialGetter } from "@/hooks/useCredentialGetter";
import { useQuery } from "@tanstack/react-query";
import { Status, TaskApiResponse, WorkflowRunApiResponse } from "@/api/types";
type QueryReturnType = Array<TaskApiResponse | WorkflowRunApiResponse>;
type UseQueryOptions = Omit<
Parameters<typeof useQuery<QueryReturnType>>[0],
"queryKey" | "queryFn"
>;
type Props = {
page?: number;
statusFilters?: Array<Status>;
} & UseQueryOptions;
function useRunsQuery({ page = 1, statusFilters }: Props) {
const credentialGetter = useCredentialGetter();
return useQuery<Array<TaskApiResponse | WorkflowRunApiResponse>>({
queryKey: ["runs", { statusFilters }, page],
queryFn: async () => {
const client = await getClient(credentialGetter);
const params = new URLSearchParams();
params.append("page", String(page));
if (statusFilters) {
statusFilters.forEach((status) => {
params.append("status", status);
});
}
return client.get("/runs", { params }).then((res) => res.data);
},
});
}
export { useRunsQuery };