Files
supabase/apps/studio/data/compute/compute-instance-query.ts
T
Francesco Sansalvadore d513d013c5 chore(studio): poll state to keep ui in sync (#50216)
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 -->
2026-09-10 17:11:49 +02:00

37 lines
1.4 KiB
TypeScript

import { queryOptions } from '@tanstack/react-query'
import { computeInstanceRefetchInterval, 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 ComputeInstanceVariables = { projectRef?: string; name?: string }
export type ComputeInstanceError = ResponseError
async function getComputeInstance(
{ projectRef, name }: ComputeInstanceVariables,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
if (!name) throw new Error('name is required')
const { data, error } = await get('/v2/projects/{ref}/workers/{name}', {
params: { path: { ref: projectRef, name } },
signal,
})
if (error) return handleError(error)
return parseComputeInstance(data.data)
}
export type ComputeInstanceData = Awaited<ReturnType<typeof getComputeInstance>>
export const computeInstanceQueryOptions = ({ projectRef, name }: ComputeInstanceVariables) =>
queryOptions({
queryKey: computeKeys.detail(projectRef, name),
queryFn: ({ signal }) => getComputeInstance({ projectRef, name }, signal),
enabled: IS_PLATFORM && typeof projectRef !== 'undefined' && typeof name !== 'undefined',
refetchInterval: (query) => computeInstanceRefetchInterval(query.state.data),
})