Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ba32175
refactor(shared): machine size names in one place
saddlepaddle Nov 18, 2026
4e8e775
feat(cloud-usage): overview, Workspaces and Workspace pages to the de…
saddlepaddle Nov 18, 2026
f84b35c
refactor(cloud-usage): one empty state path on the Workspace page
saddlepaddle Nov 18, 2026
58a02eb
feat(cloud-usage): allowance in dollars, Workspaces filters, last end…
saddlepaddle Nov 18, 2026
f42e98c
fix(cloud-usage): members get the search box only, as in the design
saddlepaddle Nov 18, 2026
1ecc99b
feat(cloud-usage): rows per page on the Workspaces page
saddlepaddle Nov 18, 2026
cbaf749
feat(cloud-usage): say why an allowance value is missing
saddlepaddle Nov 18, 2026
668681a
fix(cloud-usage): review findings on the customer pages
saddlepaddle Nov 18, 2026
0379764
fix(cloud-usage): no clipped last tick; the beyond line has no group
saddlepaddle Nov 18, 2026
88ad3a1
fix(cloud-usage): usage past the billing lines under its own heading
saddlepaddle Nov 18, 2026
c50459b
fix(cloud-usage): desktop nav, future days, person chip
saddlepaddle Nov 18, 2026
a2207d8
test(cloud-usage): stories for every page state
saddlepaddle Nov 18, 2026
6a0478f
refactor(cloud-usage): usage without prices is a load failure
saddlepaddle Nov 18, 2026
ec20ca4
refactor(cloud): the allowance mapping in a module of its own
saddlepaddle Nov 18, 2026
5668923
fix(cloud-usage): review round 2 on the customer pages
saddlepaddle Nov 18, 2026
0f26c13
fix(cloud-usage): name the unbilled line for what it holds
saddlepaddle Nov 18, 2026
5e5e11e
fix(cloud-usage): review round 3 on the customer pages
saddlepaddle Nov 18, 2026
7c44f4a
fix(cloud-usage): review round 4 on the customer pages
saddlepaddle Nov 19, 2026
21cea76
fix(cloud-usage): desktop review round 4 on the customer pages
saddlepaddle Nov 19, 2026
f6b3ccc
fix(cloud-usage): round 5 on the allowance card
saddlepaddle Nov 19, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { cloudTrpc } from "renderer/lib/cloud-trpc";
/**
* The cloud usage flag is evaluated for the organization on the server, and
* this app's PostHog client has no organization group, so the router's answer
* is the flag: off, every cloud.* procedure is FORBIDDEN.
* is the flag: off, every cloud.* procedure is FORBIDDEN. Any other error
* leaves the pages reachable, so they can show it and offer a retry.
*/
export function useCloudUsageEnabled(): boolean {
const { isSuccess } = cloudTrpc.cloud.periods.list.useQuery(
const { isSuccess, error } = cloudTrpc.cloud.periods.list.useQuery(
{ limit: 1 },
{ staleTime: 5 * 60_000, refetchOnWindowFocus: false },
);
return isSuccess;
return isSuccess || (error !== null && error.data?.code !== "FORBIDDEN");
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
machineSpec,
offeredMachineSizes,
} from "@superset/shared/billing";
import { MACHINE_SIZE_NAMES } from "@superset/shared/machine-size-names";
import { useMemo } from "react";
import { useActiveOrganizationId } from "renderer/hooks/useActiveOrganizationId";
import { cloudTrpc } from "renderer/lib/cloud-trpc";
Expand All @@ -22,7 +23,7 @@ export function useMachineSizeOptions(): {
options: MachineSizeOption[];
defaultSize: MachineSize;
} {
const { t } = useLingui();
const { i18n, t } = useLingui();
const { formatNumber } = useFormat();
const organizationId = useActiveOrganizationId();
const { data } = cloudTrpc.cloudWorkspace.machineSizes.useQuery(
Expand All @@ -31,13 +32,6 @@ export function useMachineSizeOptions(): {
);
return useMemo(() => {
const sizes = data?.sizes.map((size) => size.name) ?? FALLBACK_SIZES;
const names: Record<MachineSize, string> = {
small: t({ message: "Small", context: "machine size" }),
medium: t({ message: "Medium", context: "machine size" }),
large: t({ message: "Large", context: "machine size" }),
xlarge: t({ message: "X-Large", context: "machine size" }),
"2xlarge": t({ message: "2X-Large", context: "machine size" }),
};

return {
defaultSize: data?.defaultSize ?? defaultMachineSize(sizes),
Expand All @@ -47,10 +41,10 @@ export function useMachineSizeOptions(): {
const memory = formatNumber(memoryGb);
return {
size,
name: names[size],
name: i18n._(MACHINE_SIZE_NAMES[size]),
spec: t({ message: `${vcpuCount} vCPU · ${memory} GB` }),
};
}),
};
}, [data, t, formatNumber]);
}, [data, i18n, t, formatNumber]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { PERIODS_INPUT, QueryStatus } from "@superset/ui/cloud-usage-page";
import { useNavigate } from "@tanstack/react-router";
import { type ReactNode, useEffect } from "react";
import { useOrganizationMembership } from "renderer/hooks/useOrganizationMembership";
import { cloudTrpc } from "renderer/lib/cloud-trpc";

/** Waits for the member's role, and leaves the cloud usage pages when the router says the flag is off. */
export function CloudUsageGate({
children,
}: {
children: (isAdmin: boolean) => ReactNode;
}) {
const navigate = useNavigate();
const { role, ...membership } = useOrganizationMembership();
const periods = cloudTrpc.cloud.periods.list.useQuery(PERIODS_INPUT);
const isDisabled = periods.error?.data?.code === "FORBIDDEN";

useEffect(() => {
if (isDisabled) navigate({ to: "/settings/account", replace: true });
}, [isDisabled, navigate]);

if (isDisabled) return null;
return (
<div className="p-6">
{role === undefined ? (
<QueryStatus
isError={membership.isError}
onRetry={membership.refetch}
/>
) : (
children(role === "owner" || role === "admin")
)}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { CloudUsageGate } from "./CloudUsageGate";
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { CloudUsageLink as LinkType } from "@superset/ui/cloud-usage-page";
import { Link } from "@tanstack/react-router";

export const CloudUsageLink: LinkType = ({ to, ...props }) => {
switch (to.view) {
case "overview":
return (
<Link
to="/settings/cloud-usage"
search={{ period: to.period }}
{...props}
/>
);
case "workspaces": {
const { view: _, ...search } = to;
return (
<Link
to="/settings/cloud-usage/workspaces"
search={search}
{...props}
/>
);
}
case "workspace":
return (
<Link
to="/settings/cloud-usage/workspaces/$workspaceId"
params={{ workspaceId: to.workspaceId }}
search={{ period: to.period }}
{...props}
/>
);
case "billing":
return <Link to="/settings/billing" {...props} />;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { CloudUsageLink } from "./CloudUsageLink";
Original file line number Diff line number Diff line change
@@ -1,95 +1,51 @@
import { Trans } from "@lingui/react/macro";
import { Button } from "@superset/ui/button";
import {
CloudUsagePage,
cloudUsageQueries,
PERIODS_INPUT,
QueryStatus,
selectedPeriod,
usageRange,
type WorkspaceRef,
} from "@superset/ui/cloud-usage-page";
import { Link, useNavigate } from "@tanstack/react-router";
import { useEffect, useState } from "react";
import { useOrganizationMembership } from "renderer/hooks/useOrganizationMembership";
import { cloudTrpc } from "renderer/lib/cloud-trpc";
import { useCloudUsagePeriod } from "../../hooks/useCloudUsagePeriod";
import { CloudUsageLink } from "../CloudUsageLink";

export function CloudUsageSettings() {
const navigate = useNavigate();
const { role, ...membership } = useOrganizationMembership();
const isAdmin = role === "owner" || role === "admin";
const periods = cloudTrpc.cloud.periods.list.useQuery(PERIODS_INPUT);
const [periodId, setPeriodId] = useState<string>();
const [workspace, setWorkspace] = useState<WorkspaceRef | null>(null);
const period = selectedPeriod(periods.data?.items, periodId);
interface CloudUsageSettingsProps {
isAdmin: boolean;
periodId: string | undefined;
}

export function CloudUsageSettings({
isAdmin,
periodId,
}: CloudUsageSettingsProps) {
const { periods, period, range } = useCloudUsagePeriod(periodId);
const queries = cloudUsageQueries({
range: usageRange(period),
range,
periodsLoaded: periods.isSuccess,
isAdmin,
workspaceId: workspace?.id,
});
const byDay = cloudTrpc.cloud.usage.query.useQuery(queries.byDay.input, {
enabled: queries.byDay.enabled,
});
const byPerson = cloudTrpc.cloud.usage.query.useQuery(
queries.byPerson.input,
{ enabled: queries.byPerson.enabled },
);
const workspaces = cloudTrpc.cloud.usage.query.useInfiniteQuery(
queries.workspaces.input,
{
getNextPageParam: (page) => page.nextCursor,
enabled: queries.workspaces.enabled,
enabled: queries.byPerson.enabled,
},
);
const boots = cloudTrpc.cloud.boots.list.useInfiniteQuery(
queries.boots.input,
const workspaces = cloudTrpc.cloud.usage.query.useQuery(
queries.topWorkspaces.input,
{
getNextPageParam: (page) => page.nextCursor,
enabled: queries.boots.enabled,
enabled: queries.topWorkspaces.enabled,
},
);
const isDisabled = periods.error?.data?.code === "FORBIDDEN";

useEffect(() => {
if (isDisabled) navigate({ to: "/settings/account", replace: true });
}, [isDisabled, navigate]);

if (isDisabled) return null;
if (role === undefined) {
return (
<div className="p-6">
<QueryStatus
isError={membership.isError}
onRetry={membership.refetch}
/>
</div>
);
}

return (
<div className="p-6">
<CloudUsagePage
isAdmin={isAdmin}
actions={
role === "owner" && (
<Button variant="outline" asChild>
<Link to="/settings/billing">
<Trans>Billing</Trans>
</Link>
</Button>
)
}
periods={periods}
period={period}
onPeriodChange={setPeriodId}
byDay={byDay}
byPerson={byPerson}
workspaces={workspaces}
workspace={workspace}
onWorkspaceChange={setWorkspace}
boots={boots}
/>
</div>
<CloudUsagePage
Link={CloudUsageLink}
isAdmin={isAdmin}
periods={periods}
period={period}
byDay={byDay}
byPerson={byPerson}
workspaces={workspaces}
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useCloudUsagePeriod } from "./useCloudUsagePeriod";
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {
PERIODS_INPUT,
selectedPeriod,
usageRange,
} from "@superset/ui/cloud-usage-page";
import { cloudTrpc } from "renderer/lib/cloud-trpc";

/** The billing periods, and the one the route's `period` names. */
export function useCloudUsagePeriod(periodId: string | undefined) {
const periods = cloudTrpc.cloud.periods.list.useQuery(PERIODS_INPUT);
const period = selectedPeriod(periods.data?.items, periodId);
return { periods, period, range: usageRange(period) };
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { createFileRoute } from "@tanstack/react-router";
import { useActiveOrganizationId } from "renderer/hooks/useActiveOrganizationId";
import { CloudUsageGate } from "./components/CloudUsageGate";
import { CloudUsageSettings } from "./components/CloudUsageSettings";
import { cloudUsageSearch } from "./utils/cloudUsageSearch";

export const Route = createFileRoute("/_authenticated/settings/cloud-usage/")({
component: CloudUsageSettingsPage,
validateSearch: cloudUsageSearch,
});

function CloudUsageSettingsPage() {
return <CloudUsageSettings key={useActiveOrganizationId()} />;
const { period } = Route.useSearch();
return (
<CloudUsageGate key={useActiveOrganizationId()}>
{(isAdmin) => <CloudUsageSettings isAdmin={isAdmin} periodId={period} />}
</CloudUsageGate>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {
type WorkspacesFilters,
workspacesFilters,
} from "@superset/ui/cloud-usage-page";

/** `period` is a period id; absent means the newest. The rest are the Workspaces page's filters. */
export function cloudUsageSearch(
search: Record<string, unknown>,
): { period?: string } & WorkspacesFilters {
const period = search.period;
return {
period:
typeof period === "string" && period.length > 0 ? period : undefined,
...workspacesFilters((key) => search[key]),
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { cloudUsageSearch } from "./cloudUsageSearch";
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { Trans } from "@lingui/react/macro";
import { FEATURE_FLAGS } from "@superset/shared/constants";
import { Button } from "@superset/ui/button";
import {
CloudWorkspacePage,
cloudUsageQueries,
} from "@superset/ui/cloud-usage-page";
import { Link } from "@tanstack/react-router";
import { useFeatureFlagEnabled } from "posthog-js/react";
import { LuArrowUpRight } from "react-icons/lu";
import { cloudTrpc } from "renderer/lib/cloud-trpc";
import { CloudUsageLink } from "../../../../components/CloudUsageLink";
import { useCloudUsagePeriod } from "../../../../hooks/useCloudUsagePeriod";

interface CloudWorkspaceSettingsProps {
workspaceId: string;
periodId: string | undefined;
}

export function CloudWorkspaceSettings({
workspaceId,
periodId,
}: CloudWorkspaceSettingsProps) {
const canOpen =
useFeatureFlagEnabled(FEATURE_FLAGS.CLOUD_WORKSPACES) === true;
const { periods, period, range } = useCloudUsagePeriod(periodId);
const queries = cloudUsageQueries({
range,
periodsLoaded: periods.isSuccess,
isAdmin: false,
workspaceId,
});
const workspace = cloudTrpc.cloud.usage.query.useQuery(
queries.workspace.input,
{
enabled: queries.workspace.enabled,
},
);
const allTime = cloudTrpc.cloud.usage.query.useQuery(
queries.workspaceAllTime.input,
{ enabled: queries.workspaceAllTime.enabled },
);
const boots = cloudTrpc.cloud.boots.list.useInfiniteQuery(
queries.boots.input,
{
getNextPageParam: (page) => page.nextCursor,
enabled: queries.boots.enabled,
},
);

return (
<CloudWorkspacePage
Link={CloudUsageLink}
periods={periods}
period={period}
workspace={workspace}
allTime={allTime}
boots={boots}
openWorkspace={
canOpen
? (id) => (
<Button variant="outline" size="sm" asChild>
<Link
to="/cloud-workspaces/$workspaceId"
params={{ workspaceId: id }}
>
<Trans>Open workspace</Trans>
<LuArrowUpRight />
</Link>
</Button>
)
: undefined
}
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { CloudWorkspaceSettings } from "./CloudWorkspaceSettings";
Loading
Loading