Skip to content

Commit ea401d4

Browse files
committed
refactor(settings): remove orphan sandbox query module
1 parent 220fc37 commit ea401d4

2 files changed

Lines changed: 26 additions & 29 deletions

File tree

apps/sim/hooks/queries/sandbox-list.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

apps/sim/hooks/queries/sandboxes.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
import { createLogger } from '@sim/logger'
2-
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
2+
import { queryOptions, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
33
import { requestJson } from '@/lib/api/client/request'
44
import type { ContractBodyInput } from '@/lib/api/contracts'
55
import {
66
createSandboxContract,
77
deleteSandboxContract,
8+
listSandboxesContract,
89
type Sandbox,
910
type SandboxListResponse,
1011
updateSandboxContract,
1112
} from '@/lib/api/contracts'
12-
import { getSandboxListQueryOptions, sandboxKeys } from '@/hooks/queries/sandbox-list'
1313

1414
const logger = createLogger('SandboxQueries')
1515

1616
export type { Sandbox, SandboxListResponse }
1717

18+
export const sandboxKeys = {
19+
all: ['sandboxes'] as const,
20+
lists: () => [...sandboxKeys.all, 'list'] as const,
21+
list: (workspaceId?: string) => [...sandboxKeys.lists(), workspaceId ?? ''] as const,
22+
}
23+
24+
const SANDBOX_LIST_STALE_TIME = 30 * 1000
25+
1826
/** Poll cadence while any sandbox is still building; see {@link useSandboxes}. */
1927
export const SANDBOX_BUILD_POLL_INTERVAL = 3 * 1000
2028

@@ -25,6 +33,22 @@ export const SANDBOX_BUILD_POLL_INTERVAL = 3 * 1000
2533
*/
2634
const MAX_BUILD_POLLS = 350
2735

36+
async function fetchSandboxes(
37+
workspaceId: string,
38+
signal?: AbortSignal
39+
): Promise<SandboxListResponse> {
40+
return requestJson(listSandboxesContract, { params: { id: workspaceId }, signal })
41+
}
42+
43+
function getSandboxListQueryOptions(workspaceId: string) {
44+
return queryOptions({
45+
queryKey: sandboxKeys.list(workspaceId),
46+
queryFn: ({ signal }) => fetchSandboxes(workspaceId, signal),
47+
retryOnMount: true,
48+
staleTime: SANDBOX_LIST_STALE_TIME,
49+
})
50+
}
51+
2852
/** True while at least one sandbox has a build that has not reached a terminal state. */
2953
export function hasPendingBuild(sandboxes: readonly Sandbox[]): boolean {
3054
return sandboxes.some(

0 commit comments

Comments
 (0)