mirror of
https://github.com/langgenius/dify.git
synced 2026-11-10 21:35:45 +08:00
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import type { GetWorkspacesCurrentSummaryResponse } from '@dify/contracts/api/console/workspaces/types.gen'
|
|
import type { QueryClient, QueryKey } from '@tanstack/react-query'
|
|
import { consoleQueryKey } from '@/test/console/operation-hooks'
|
|
|
|
export const currentWorkspaceQueryKey = consoleQueryKey('workspaces.current.summary.get')
|
|
|
|
const createCurrentWorkspaceFixture = (
|
|
overrides: Partial<GetWorkspacesCurrentSummaryResponse> = {},
|
|
): GetWorkspacesCurrentSummaryResponse => ({
|
|
id: 'workspace-1',
|
|
name: 'Workspace',
|
|
plan: null,
|
|
role: 'owner',
|
|
credits: null,
|
|
...overrides,
|
|
})
|
|
|
|
export const seedCurrentWorkspaceQuery = (
|
|
queryClient: QueryClient,
|
|
workspace: Partial<GetWorkspacesCurrentSummaryResponse> = {},
|
|
queryKey: QueryKey = currentWorkspaceQueryKey,
|
|
) => {
|
|
const data = createCurrentWorkspaceFixture(workspace)
|
|
queryClient.setQueryData(queryKey, data)
|
|
return data
|
|
}
|
|
|
|
export const ensureCurrentWorkspaceQuery = (
|
|
queryClient: QueryClient,
|
|
workspace: Partial<GetWorkspacesCurrentSummaryResponse> = {},
|
|
queryKey: QueryKey = currentWorkspaceQueryKey,
|
|
) => {
|
|
const existingWorkspace = queryClient.getQueryData<GetWorkspacesCurrentSummaryResponse>(queryKey)
|
|
if (existingWorkspace === undefined)
|
|
return seedCurrentWorkspaceQuery(queryClient, workspace, queryKey)
|
|
|
|
return existingWorkspace
|
|
}
|