mirror of
https://github.com/supabase/supabase.git
synced 2026-10-15 22:29:11 +03:00
* 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>
52 lines
1.4 KiB
TypeScript
52 lines
1.4 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 WorkflowRunLogsVariables = {
|
|
workflowRunId?: string
|
|
}
|
|
|
|
export async function getWorkflowRunLogs(
|
|
{ workflowRunId }: WorkflowRunLogsVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!workflowRunId) throw new Error('workflowRunId is required')
|
|
|
|
const { data, error } = await get(`/platform/workflow-runs/{workflow_run_id}/logs`, {
|
|
params: {
|
|
path: {
|
|
workflow_run_id: workflowRunId,
|
|
},
|
|
},
|
|
parseAs: 'text',
|
|
headers: {
|
|
Accept: 'text/plain',
|
|
},
|
|
signal,
|
|
})
|
|
if (error) handleError(error)
|
|
return data
|
|
.split('\n')
|
|
.flatMap((line) => line.split('\r'))
|
|
.join('\n')
|
|
.trim()
|
|
}
|
|
|
|
export type WorkflowRunLogsData = Awaited<ReturnType<typeof getWorkflowRunLogs>>
|
|
export type WorkflowRunLogsError = ResponseError
|
|
|
|
export const useWorkflowRunLogsQuery = <TData = WorkflowRunLogsData>(
|
|
{ workflowRunId }: WorkflowRunLogsVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseQueryOptions<WorkflowRunLogsData, WorkflowRunLogsError, TData> = {}
|
|
) =>
|
|
useQuery<WorkflowRunLogsData, WorkflowRunLogsError, TData>(
|
|
workflowRunKeys.list(workflowRunId),
|
|
({ signal }) => getWorkflowRunLogs({ workflowRunId }, signal),
|
|
{ enabled: enabled && typeof workflowRunId !== 'undefined', staleTime: 0, ...options }
|
|
)
|