(
workspaceId?: string,
scope: TableQueryScope = 'active',
options?: {
/** Poll cadence, or a predicate over the current list that returns a cadence (or `false`). */
refetchInterval?: number | false | ((tables: TableDefinition[] | undefined) => number | false)
}
)
| 209 | * Fetch all tables for a workspace. |
| 210 | */ |
| 211 | export function useTablesList( |
| 212 | workspaceId?: string, |
| 213 | scope: TableQueryScope = 'active', |
| 214 | options?: { |
| 215 | /** Poll cadence, or a predicate over the current list that returns a cadence (or `false`). */ |
| 216 | refetchInterval?: number | false | ((tables: TableDefinition[] | undefined) => number | false) |
| 217 | } |
| 218 | ) { |
| 219 | const refetchInterval = options?.refetchInterval |
| 220 | return useQuery({ |
| 221 | queryKey: tableKeys.list(workspaceId, scope), |
| 222 | queryFn: async ({ signal }) => { |
| 223 | if (!workspaceId) throw new Error('Workspace ID required') |
| 224 | |
| 225 | const response = await requestJson(listTablesContract, { |
| 226 | query: { workspaceId, scope }, |
| 227 | signal, |
| 228 | }) |
| 229 | return response.data.tables |
| 230 | }, |
| 231 | enabled: Boolean(workspaceId), |
| 232 | staleTime: 30 * 1000, |
| 233 | placeholderData: keepPreviousData, |
| 234 | refetchInterval: |
| 235 | typeof refetchInterval === 'function' |
| 236 | ? (query) => refetchInterval(query.state.data) |
| 237 | : (refetchInterval ?? false), |
| 238 | }) |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Fetch a single table by id. |
no test coverage detected