Path: blob/main/components/dashboard/src/data/organizations/org-workspace-classes-query.ts
2501 views
/**1* Copyright (c) 2023 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { useQuery, useQueryClient } from "@tanstack/react-query";7import { organizationClient } from "../../service/public-api";8import { useCallback } from "react";9import { useCurrentOrg } from "./orgs-query";10import { WorkspaceClass } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";11import { noPersistence } from "../setup";1213export function useOrgWorkspaceClassesQueryInvalidator() {14const organizationId = useCurrentOrg().data?.id;15const queryClient = useQueryClient();16return useCallback(() => {17queryClient.invalidateQueries(getQueryKey(organizationId));18}, [organizationId, queryClient]);19}2021export function useOrgWorkspaceClassesQuery() {22const organizationId = useCurrentOrg().data?.id;23return useQuery<WorkspaceClass[], Error>(24getQueryKey(organizationId),25async () => {26if (!organizationId) {27throw new Error("No org selected.");28}2930const settings = await organizationClient.listOrganizationWorkspaceClasses({ organizationId });31return settings.workspaceClasses || [];32},33{34enabled: !!organizationId,35},36);37}3839function getQueryKey(organizationId?: string) {40// We don't persistence listOrganizationWorkspaceClasses because org settings updated by owner will not notify members to invalidate listOrganizationWorkspaceClasses41// TODO: Or we need to handle special ErrorCodes from server somewhere42// i.e. CreateAndStartWorkspace respond selected workspace class is not allowed43return noPersistence(["listOrganizationWorkspaceClasses", organizationId || "undefined"]);44}454647