Files
supabase/apps/studio/data/workflow-runs/workflow-runs-query.ts
T
Alaister YoungandJoshen Lim c6dc2c566e feat: workflow run logs (#29678)
* feat: workflow run logs

* progress

* adds logs modal

* remove menu item

* output raw text

* update parseAs

* accept text/plain

* cleanup ui

* feature flag new logs

* fix types

* fix condition

* cleanup spacing

* loading spacing

* cheeky console.log

* more log

* split logs properly

* add workflow logs to prod branches

* address some feedback

* Some UI tweaks

* More UI tweak

* More UI tweak

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-10-10 08:29:04 +00:00

38 lines
1.2 KiB
TypeScript

import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import type { ResponseError } from 'types'
import { workflowRunKeys } from './keys'
export type WorkflowRunsVariables = {
projectRef?: string
}
export async function getWorkflowRuns({ projectRef }: WorkflowRunsVariables, signal?: AbortSignal) {
if (!projectRef) throw new Error('projectRef is required')
const { data, error } = await get(`/platform/workflow-runs`, {
params: {
query: {
project_ref: projectRef,
},
},
signal,
})
if (error) handleError(error)
return data
}
export type WorkflowRunsData = Awaited<ReturnType<typeof getWorkflowRuns>>
export type WorkflowRunsError = ResponseError
export const useWorkflowRunsQuery = <TData = WorkflowRunsData>(
{ projectRef }: WorkflowRunsVariables,
{ enabled = true, ...options }: UseQueryOptions<WorkflowRunsData, WorkflowRunsError, TData> = {}
) =>
useQuery<WorkflowRunsData, WorkflowRunsError, TData>(
workflowRunKeys.list(projectRef),
({ signal }) => getWorkflowRuns({ projectRef }, signal),
{ enabled: enabled && typeof projectRef !== 'undefined', staleTime: 0, ...options }
)