Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ui/apps/console/openapi-ts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ if (!input) {
// generating from its URL produces a client missing the other editions'
// schemas. Use `npm run generate -w @shellhub/console`, which bundles the
// combined spec before invoking openapi-ts.
throw new Error("OPENAPI_SPEC_PATH is not set; run `npm run generate -w @shellhub/console`.");
throw new Error(
"OPENAPI_SPEC_PATH is not set; run `npm run generate -w @shellhub/console`.",
);
}

export default defineConfig({
Expand All @@ -23,6 +25,7 @@ export default defineConfig({
name: "@tanstack/react-query",
queryOptions: true,
mutationOptions: true,
includeInEntry: true,
},
],
});
2 changes: 1 addition & 1 deletion ui/apps/console/src/components/ConnectDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import { BROWSER_KEY_QUERY_KEY } from "@/hooks/useBrowserKey";
import { isRecordingSupported } from "../utils/recordings";
import { isAlreadyEnrolled } from "../utils/sshIdentity";
import { listSshIdentitiesOptions } from "../client/@tanstack/react-query.gen";
import { listSshIdentitiesOptions } from "../client";
import BrowserEnrollDialog from "./terminal/BrowserEnrollDialog";
import CopyButton from "./common/CopyButton";
import Drawer from "./common/Drawer";
Expand Down
12 changes: 9 additions & 3 deletions ui/apps/console/src/components/billing/BillingSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useNamespace } from "@/hooks/useNamespaces";
import { useOpenBillingPortal, useSubscription } from "@/hooks/useBilling";
import { useInvalidateByIds } from "@/hooks/useInvalidateQueries";
import { formatExpiry } from "@/utils/date";
import type { BillingStatus } from "@/client/types.gen";
import type { BillingStatus } from "@/client";
import { cn } from "@shellhub/design-system/cn";
import { Button } from "@shellhub/design-system/primitives";

Expand Down Expand Up @@ -157,7 +157,10 @@ function SectionRow({
function StatusBadge({ status }: { status: BillingStatus }) {
return (
<span
className={cn("inline-flex items-center px-2.5 py-1 text-2xs font-mono font-semibold rounded border", STATUS_CHIP[status])}
className={cn(
"inline-flex items-center px-2.5 py-1 text-2xs font-mono font-semibold rounded border",
STATUS_CHIP[status],
)}
>
{STATUS_LABEL[status]}
</span>
Expand Down Expand Up @@ -277,7 +280,10 @@ export default function BillingSection({ sectionId }: BillingSectionProps) {
<div
role="status"
aria-live="polite"
className={cn("flex items-start gap-3 px-5 py-3 border-b", BANNER_CLASSES[banner.tone])}
className={cn(
"flex items-start gap-3 px-5 py-3 border-b",
BANNER_CLASSES[banner.tone],
)}
>
<banner.Icon
aria-hidden="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen, waitFor } from "@testing-library/react";
import { createTestWrapper } from "@/tests/wrapper";
import type { GetLicenseResponse } from "@/client/types.gen";
import type { GetLicenseResponse } from "@/client";
import { defaultConfig } from "@/env";
import { useAuthStore } from "@/stores/authStore";

Expand All @@ -16,9 +16,6 @@ vi.mock("@/hooks/useAdminStats", () => ({
}));
vi.mock("@/client", () => ({
getLicense: vi.fn(),
}));

vi.mock("@/client/@tanstack/react-query.gen", () => ({
getLicenseQueryKey: vi.fn(() => ["getLicense"]),
}));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen, waitFor } from "@testing-library/react";
import { createTestWrapper } from "@/tests/wrapper";
import type { GetLicenseResponse } from "@/client/types.gen";
import type { GetLicenseResponse } from "@/client";
import { defaultConfig } from "@/env";
import { useAuthStore } from "@/stores/authStore";

Expand All @@ -12,9 +12,6 @@ vi.mock("@/hooks/useAdminLicense", () => ({
}));
vi.mock("@/client", () => ({
getLicense: vi.fn(),
}));

vi.mock("@/client/@tanstack/react-query.gen", () => ({
getLicenseQueryKey: vi.fn(() => ["getLicense"]),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from "react";
import { createTestWrapper } from "@/tests/wrapper";
import { defaultConfig } from "@/env";
import { useAuthStore } from "@/stores/authStore";
import type { GetLicenseResponse } from "@/client/types.gen";
import type { GetLicenseResponse } from "@/client";

// ── Dependency mocks ──────────────────────────────────────────────────────────

Expand All @@ -14,9 +14,6 @@ vi.mock("@/hooks/useAdminLicense", () => ({
}));
vi.mock("@/client", () => ({
getLicense: vi.fn(),
}));

vi.mock("@/client/@tanstack/react-query.gen", () => ({
getLicenseQueryKey: vi.fn(() => ["getLicense"]),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import { renderHookWithClient } from "@/tests/wrapper";
vi.mock("@/client", () => ({
getFirewallRulesAdmin: vi.fn(),
getFirewallRuleAdmin: vi.fn(),
}));

vi.mock("@/client/@tanstack/react-query.gen", () => ({
getFirewallRulesAdminQueryKey: vi.fn((opts: unknown) => [
{ _id: "getFirewallRulesAdmin" },
opts,
Expand Down
3 changes: 0 additions & 3 deletions ui/apps/console/src/hooks/__tests__/useAdminLicense.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import { useAuthStore } from "@/stores/authStore";
// ── Dependency mocks ──────────────────────────────────────────────────────────
vi.mock("@/client", () => ({
getLicense: vi.fn(),
}));

vi.mock("@/client/@tanstack/react-query.gen", () => ({
getLicenseQueryKey: vi.fn(() => ["getLicense"]),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ vi.mock("@/api/pagination", () => ({
paginatedQueryFn: vi.fn(),
}));

vi.mock("@/client/@tanstack/react-query.gen", () => ({
getSessionsAdminQueryKey: vi.fn(() => ["sessions-admin"]),
}));

vi.mock("@/client", () => ({
getSessionsAdmin: vi.fn(),
getSessionsAdminQueryKey: vi.fn(() => ["sessions-admin"]),
}));

import { useAuthStore } from "@/stores/authStore";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const mockDeleteFn = vi.fn();
const mockResetPasswordFn = vi.fn();
const mockInvalidate = vi.fn();

vi.mock("@/client/@tanstack/react-query.gen", () => ({
vi.mock("@/client", () => ({
createUserAdminMutation: vi.fn(() => ({ mutationFn: mockCreateFn })),
adminUpdateUserMutation: vi.fn(() => ({ mutationFn: mockUpdateFn })),
adminDeleteUserMutation: vi.fn(() => ({ mutationFn: mockDeleteFn })),
Expand Down
3 changes: 0 additions & 3 deletions ui/apps/console/src/hooks/__tests__/useAdminUsers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import { useAuthStore } from "@/stores/authStore";
vi.mock("@/client", () => ({
getUsers: vi.fn(),
getUser: vi.fn(),
}));

vi.mock("@/client/@tanstack/react-query.gen", () => ({
getUsersQueryKey: vi.fn((opts: unknown) => [{ _id: "getUsers" }, opts]),
getUserOptions: vi.fn((opts: unknown) => ({
queryKey: [{ _id: "getUser" }, opts],
Expand Down
7 changes: 2 additions & 5 deletions ui/apps/console/src/hooks/__tests__/useBilling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const mockGetSubscriptionFn = vi.fn();
const mockInvalidate = vi.fn();
const mockCreateBillingPortalSession = vi.fn();

vi.mock("@/client/@tanstack/react-query.gen", () => ({
vi.mock("@/client", () => ({
getCustomerOptions: vi.fn(() => ({
queryKey: [{ _id: "getCustomer" }],
queryFn: mockGetCustomerFn,
Expand All @@ -30,16 +30,13 @@ vi.mock("@/client/@tanstack/react-query.gen", () => ({
setDefaultPaymentMethodMutation: vi.fn(() => ({
mutationFn: mockSetDefault,
})),
createBillingPortalSession: (): unknown => mockCreateBillingPortalSession(),
}));

vi.mock("../useInvalidateQueries", () => ({
useInvalidateByIds: vi.fn(() => mockInvalidate),
}));

vi.mock("@/client", () => ({
createBillingPortalSession: (): unknown => mockCreateBillingPortalSession(),
}));

async function importHooks() {
return await import("../useBilling");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const mockMostUsedQueryFn = vi.fn();
const mockChoiceMutationFn = vi.fn();
const mockInvalidate = vi.fn();

vi.mock("@/client/@tanstack/react-query.gen", () => ({
vi.mock("@/client", () => ({
getDevicesMostUsedOptions: vi.fn(() => ({
queryKey: [{ _id: "getDevicesMostUsed" }],
queryFn: mockMostUsedQueryFn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const mockGenerateLinkFn = vi.fn();
const mockCancelFn = vi.fn();
const mockInvalidate = vi.fn();

vi.mock("@/client/@tanstack/react-query.gen", () => ({
vi.mock("@/client", () => ({
acceptInviteMutation: vi.fn(() => ({ mutationFn: mockAcceptFn })),
generateInvitationLinkMutation: vi.fn(() => ({
mutationFn: mockGenerateLinkFn,
Expand Down
27 changes: 12 additions & 15 deletions ui/apps/console/src/hooks/__tests__/useInvitations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ import {
} from "../useInvitations";
import type { MembershipInvitation } from "@/client";

const mockResolveFn = vi.fn();

vi.mock("@/client", () => ({
getMembershipInvitationList: vi.fn(),
getNamespaceMembershipInvitationList: vi.fn(),
}));

const mockResolveFn = vi.fn();

vi.mock("@/client/@tanstack/react-query.gen", () => ({
getMembershipInvitationListQueryKey: vi.fn((opts: unknown) => [
{ _id: "getMembershipInvitationList" },
opts,
Expand Down Expand Up @@ -66,8 +63,8 @@ describe("useNamespaceInvitations", () => {
const inv = makeInvitation({ status: "pending" });
mockFetchFn.mockResolvedValue({ data: [inv], totalCount: 1 });

const { result } = renderHookWithClient(
() => useNamespaceInvitations({ tenantId: "t1" }),
const { result } = renderHookWithClient(() =>
useNamespaceInvitations({ tenantId: "t1" }),
);

await waitFor(() => expect(result.current.isLoading).toBe(false));
Expand All @@ -77,8 +74,8 @@ describe("useNamespaceInvitations", () => {
it("returns totalCount from the paginated result", async () => {
mockFetchFn.mockResolvedValue({ data: [], totalCount: 7 });

const { result } = renderHookWithClient(
() => useNamespaceInvitations({ tenantId: "t1" }),
const { result } = renderHookWithClient(() =>
useNamespaceInvitations({ tenantId: "t1" }),
);

await waitFor(() => expect(result.current.isLoading).toBe(false));
Expand All @@ -88,8 +85,8 @@ describe("useNamespaceInvitations", () => {
it("defaults invitations to empty array while loading", () => {
mockFetchFn.mockReturnValue(new Promise(() => {}));

const { result } = renderHookWithClient(
() => useNamespaceInvitations({ tenantId: "t1" }),
const { result } = renderHookWithClient(() =>
useNamespaceInvitations({ tenantId: "t1" }),
);

expect(result.current.invitations).toEqual([]);
Expand All @@ -99,8 +96,8 @@ describe("useNamespaceInvitations", () => {
const err = new Error("fetch failed");
mockFetchFn.mockRejectedValue(err);

const { result } = renderHookWithClient(
() => useNamespaceInvitations({ tenantId: "t1" }),
const { result } = renderHookWithClient(() =>
useNamespaceInvitations({ tenantId: "t1" }),
);

await waitFor(() => expect(result.current.error).toBeTruthy());
Expand All @@ -112,8 +109,8 @@ describe("useNamespaceInvitations", () => {
it("does not fetch when enabled is false", () => {
mockFetchFn.mockResolvedValue({ data: [], totalCount: 0 });

renderHookWithClient(
() => useNamespaceInvitations({ tenantId: "t1", enabled: false }),
renderHookWithClient(() =>
useNamespaceInvitations({ tenantId: "t1", enabled: false }),
);

expect(mockFetchFn).not.toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import { useLatestAnnouncement } from "../useLatestAnnouncement";
import type { Announcement } from "@/client";

// Mock the generated query-option factories so we control what queryFn runs
vi.mock("@/client/@tanstack/react-query.gen", () => ({
vi.mock("@/client", () => ({
listAnnouncementsOptions: vi.fn(),
getAnnouncementOptions: vi.fn(),
}));

import { getConfig, defaultConfig } from "@/env";
import {
listAnnouncementsOptions,
getAnnouncementOptions,
} from "@/client/@tanstack/react-query.gen";
import { listAnnouncementsOptions, getAnnouncementOptions } from "@/client";

const mockGetConfig = vi.mocked(getConfig);
const mockListAnnouncementsOptions = vi.mocked(listAnnouncementsOptions);
Expand Down
3 changes: 0 additions & 3 deletions ui/apps/console/src/hooks/__tests__/usePublicKeys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import type { PublicKeyResponse } from "@/client";

vi.mock("@/client", () => ({
getPublicKeys: vi.fn(),
}));

vi.mock("@/client/@tanstack/react-query.gen", () => ({
getPublicKeysQueryKey: vi.fn((opts: unknown) => [
{ _id: "getPublicKeys" },
opts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { renderHookWithClient } from "@/tests/wrapper";

const mockGetNamespaceSupportFn = vi.fn();

vi.mock("@/client/@tanstack/react-query.gen", () => ({
vi.mock("@/client", () => ({
getNamespaceSupportOptions: vi.fn(() => ({
queryKey: [{ _id: "getNamespaceSupport" }],
queryFn: mockGetNamespaceSupportFn,
Expand Down Expand Up @@ -69,8 +69,8 @@ describe("useSupportIdentifier", () => {
mockGetNamespaceSupportFn.mockResolvedValue({ identifier: "abc123" });
const { useSupportIdentifier } = await importHook();

const { result } = renderHookWithClient(
() => useSupportIdentifier("tenant-123", true),
const { result } = renderHookWithClient(() =>
useSupportIdentifier("tenant-123", true),
);

await waitFor(() => expect(result.current.identifier).toBe("abc123"));
Expand All @@ -84,8 +84,8 @@ describe("useSupportIdentifier", () => {
mockGetNamespaceSupportFn.mockRejectedValue(new Error("network error"));
const { useSupportIdentifier } = await importHook();

const { result } = renderHookWithClient(
() => useSupportIdentifier("tenant-123", true),
const { result } = renderHookWithClient(() =>
useSupportIdentifier("tenant-123", true),
);

await waitFor(() => expect(result.current.isError).toBe(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useUploadLicense } from "../useUploadLicense";
const mockMutationFn = vi.fn();
const mockInvalidate = vi.fn();

vi.mock("@/client/@tanstack/react-query.gen", () => ({
vi.mock("@/client", () => ({
sendLicenseMutation: vi.fn(() => ({ mutationFn: mockMutationFn })),
}));

Expand Down
3 changes: 1 addition & 2 deletions ui/apps/console/src/hooks/useAccessPolicies.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useMemo } from "react";
import { useQuery } from "@tanstack/react-query";
import { listAccessPoliciesOptions } from "../client/@tanstack/react-query.gen";
import type { AccessPolicy } from "../client";
import { listAccessPoliciesOptions, type AccessPolicy } from "../client";

export function useAccessPolicies() {
const result = useQuery(listAccessPoliciesOptions());
Expand Down
2 changes: 1 addition & 1 deletion ui/apps/console/src/hooks/useAccessPolicyMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
createAccessPolicyMutation,
updateAccessPolicyMutation,
deleteAccessPolicyMutation,
} from "../client/@tanstack/react-query.gen";
} from "../client";
import { useInvalidateByIds } from "./useInvalidateQueries";

export function useCreateAccessPolicy() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { useMutation } from "@tanstack/react-query";
import {
approveUserMutation,
adminDeleteUserMutation,
} from "../client/@tanstack/react-query.gen";
import { approveUserMutation, adminDeleteUserMutation } from "../client";
import { useInvalidateByIds } from "./useInvalidateQueries";

// Approving clears the awaiting_approval flag; the account stays not-confirmed until the
Expand Down
2 changes: 1 addition & 1 deletion ui/apps/console/src/hooks/useAdminAccountRequests.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useQuery } from "@tanstack/react-query";
import {
getUsers as getUsersSdk,
getUsersQueryKey,
type GetUsersData,
type UserAdminResponse,
} from "../client";
import { getUsersQueryKey } from "../client/@tanstack/react-query.gen";
import { paginatedQueryFn, type PaginatedResult } from "../api/pagination";
import { useAuthStore } from "../stores/authStore";
import { isSdkError } from "../api/errors";
Expand Down
Loading
Loading