Files
supabase/apps/studio/data/workers/workers-query.ts
Jordi Enric abb7f3ede2 fix(workers): refresh Workers view FE-4323 (#49887)
## Problem

The Workers view can remain stale after a worker is deployed through the
CLI, because the dashboard has no deployment mutation to invalidate its
list query.

## Fix

Add a manual Refresh action to the Workers header and force the Workers
list query to refetch whenever the browser regains focus.

## How to test

- Open a project’s Workers view and select Refresh.
- Expected result: the list requests current worker data and renders it.
- Deploy a worker through the CLI, then return focus to the Workers
view.
- Expected result: the Workers list refreshes even when its cached data
is fresh.

Closes FE-4323.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
  - Added Refresh buttons to the Workers page and worker list.
- Refreshing displays the latest worker information and shows a loading
state while data is retrieved.
- Worker data now automatically refreshes when the browser window
regains focus.
- Added a Refresh action to unexpected-error messages, allowing failed
requests to be retried without leaving the page.
- **Bug Fixes**
- Improved recovery from failed worker data requests through in-page
retry support.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-02 13:42:57 +02:00

33 lines
1.1 KiB
TypeScript

import { queryOptions } from '@tanstack/react-query'
import { workersKeys } from './keys'
import { parseWorker } from './workers.utils'
import { get, handleError } from '@/data/fetchers'
import { IS_PLATFORM } from '@/lib/constants'
import type { ResponseError } from '@/types'
export type WorkersVariables = { projectRef?: string }
export type WorkersError = ResponseError
async function getWorkers({ projectRef }: WorkersVariables, 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((worker) => parseWorker(worker))
}
export type WorkersData = Awaited<ReturnType<typeof getWorkers>>
export const workersQueryOptions = ({ projectRef }: WorkersVariables) =>
queryOptions({
queryKey: workersKeys.list(projectRef),
queryFn: ({ signal }) => getWorkers({ projectRef }, signal),
enabled: IS_PLATFORM && typeof projectRef !== 'undefined',
refetchOnWindowFocus: 'always',
})