mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
Poll compute data to keep ui in sync - every 3s when state is transitioning - every 10s when idle ## To test - open compute - deploy compute instance via cli - check ui updates automatically while state changes (new -> active -> deleting -> removal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Compute data now refreshes automatically, with faster updates while instances are building or being deleted. * Added clearer manual refresh feedback in the compute interface. * **Improvements** * Improved compute table layout with fixed column sizing and truncated long instance names. * Region and resource columns remain responsive while maintaining consistent widths. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { queryOptions } from '@tanstack/react-query'
|
|
|
|
import { computeRefetchInterval, parseComputeInstance } from './compute.utils'
|
|
import { computeKeys } from './keys'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import { IS_PLATFORM } from '@/lib/constants'
|
|
import type { ResponseError } from '@/types'
|
|
|
|
export type ComputeVariables = { projectRef?: string }
|
|
export type ComputeError = ResponseError
|
|
|
|
async function getComputeInstances({ projectRef }: ComputeVariables, signal?: AbortSignal) {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
|
|
const { data, error } = await get('/v2/projects/{ref}/workers', {
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
})
|
|
|
|
if (error) return handleError(error)
|
|
return data.data.map((instance) => parseComputeInstance(instance))
|
|
}
|
|
|
|
export type ComputeData = Awaited<ReturnType<typeof getComputeInstances>>
|
|
|
|
export const computeQueryOptions = ({ projectRef }: ComputeVariables) =>
|
|
queryOptions({
|
|
queryKey: computeKeys.list(projectRef),
|
|
queryFn: ({ signal }) => getComputeInstances({ projectRef }, signal),
|
|
enabled: IS_PLATFORM && typeof projectRef !== 'undefined',
|
|
refetchOnWindowFocus: 'always',
|
|
refetchInterval: (query) => computeRefetchInterval(query.state.data),
|
|
})
|