feat(dashboard): Migrate to new hooks and API client (#6963)

This commit is contained in:
Kasper Fabricius Kristensen
2024-04-05 18:27:08 +02:00
committed by GitHub
parent 5ba74ec5fc
commit 8a5c6928f7
195 changed files with 3919 additions and 6028 deletions

View File

@@ -0,0 +1,55 @@
import { QueryKey, UseQueryOptions, useQuery } from "@tanstack/react-query"
import { client } from "../../lib/client"
import { queryKeysFactory } from "../../lib/query-key-factory"
import {
WorkflowExecutionListRes,
WorkflowExecutionRes,
} from "../../types/api-responses"
const WORKFLOW_EXECUTIONS_QUERY_KEY = "workflow_executions" as const
const workflowExecutionsQueryKeys = queryKeysFactory(
WORKFLOW_EXECUTIONS_QUERY_KEY
)
export const useWorkflowExecutions = (
query?: Record<string, any>,
options?: Omit<
UseQueryOptions<
WorkflowExecutionListRes,
Error,
WorkflowExecutionListRes,
QueryKey
>,
"queryKey" | "queryFn"
>
) => {
const { data, ...rest } = useQuery({
queryFn: () => client.workflowExecutions.list(query),
queryKey: workflowExecutionsQueryKeys.list(query),
...options,
})
return { ...data, ...rest }
}
export const useWorkflowExecution = (
id: string,
query?: Record<string, any>,
options?: Omit<
UseQueryOptions<
WorkflowExecutionRes,
Error,
WorkflowExecutionRes,
QueryKey
>,
"queryKey" | "queryFn"
>
) => {
const { data, ...rest } = useQuery({
queryFn: () => client.workflowExecutions.retrieve(id, query),
queryKey: workflowExecutionsQueryKeys.detail(id),
...options,
})
return { ...data, ...rest }
}