Files
supabase/apps/studio/data/actions/action-logs-query.ts
Han QiaoandCharis Lam d5d8d954cb feat: use new action status endpoint (#39159)
* feat: use new action status endpoint

* fix: flip incorrect conditionals

* chore: add step name to badge

* refactor(action-runs-query): cleaner types

* style(workflow logs): improve design of action run steps

---------

Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
2025-10-07 04:11:28 +08:00

37 lines
1.3 KiB
TypeScript

import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { operations } from 'data/api'
import { get, handleError } from 'data/fetchers'
import type { ResponseError } from 'types'
import { actionKeys } from './keys'
export type ActionLogsVariables = operations['v1-get-action-run-logs']['parameters']['path']
export async function getActionRunLogs(params: ActionLogsVariables, signal?: AbortSignal) {
const { data, error } = await get(`/v1/projects/{ref}/actions/{run_id}/logs`, {
params: { path: params },
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 ActionLogsData = Awaited<ReturnType<typeof getActionRunLogs>>
export type WorkflowRunLogsError = ResponseError
export const useActionRunLogsQuery = <TData = ActionLogsData>(
{ ref, run_id }: ActionLogsVariables,
{ enabled = true, ...options }: UseQueryOptions<ActionLogsData, WorkflowRunLogsError, TData> = {}
) =>
useQuery<ActionLogsData, WorkflowRunLogsError, TData>(
actionKeys.detail(ref, run_id),
({ signal }) => getActionRunLogs({ ref, run_id }, signal),
{ enabled: enabled && Boolean(ref) && Boolean(run_id), staleTime: 0, ...options }
)