Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat(license-v2): enhance organization search and data structure

Victor Hugo dos Santos5ccbd9f8ba73
diff --git a/backend/src/ee/routes/v1/license-v2-router.ts b/backend/src/ee/routes/v1/license-v2-router.ts
index 7057019e12..fbe99a164c 100644
--- a/backend/src/ee/routes/v1/license-v2-router.ts
+++ b/backend/src/ee/routes/v1/license-v2-router.ts
@@ -294,7 +294,12 @@ export const registerLicenseV2Router = async (server: FastifyZodProvider) => {
"List the root organizations whose billing the caller may read. A self-hosted instance admin gets every organization on the instance, because one licence covers them all; everyone else gets only their own.",
params: z.object({ organizationId: z.string().trim().uuid() }),
querystring: z.object({
- search: z.string().trim().max(255).optional().describe("Match root organizations whose name contains this."),
+ search: z
+ .string()
+ .trim()
+ .max(255)
+ .optional()
+ .describe("Match root organizations whose name or slug contains this."),
limit: z.coerce.number().int().min(1).max(1000).default(100).describe("Maximum organizations to return."),
offset: z.coerce.number().int().min(0).default(0).describe("Number of organizations to skip.")
}),
@@ -303,7 +308,8 @@ export const registerLicenseV2Router = async (server: FastifyZodProvider) => {
organizations: z
.object({
id: z.string().describe("ID of the root organization."),
- name: z.string().describe("Display name of the root organization.")
+ name: z.string().describe("Display name of the root organization."),
+ slug: z.string().describe("Slug of the root organization.")
})
.array(),
totalCount: z.number().describe("Root organizations matching the search, across every page.")
diff --git a/backend/src/ee/services/license-v2/license-v2-authz.test.ts b/backend/src/ee/services/license-v2/license-v2-authz.test.ts
index ef3bd80acc..089f3244c0 100644
--- a/backend/src/ee/services/license-v2/license-v2-authz.test.ts
+++ b/backend/src/ee/services/license-v2/license-v2-authz.test.ts
@@ -32,7 +32,7 @@ const buildService = () => {
const service = licenseV2ServiceFactory({
envConfig: { isCloud: false, SITE_URL: "http://localhost" },
- orgDAL: { findById: vi.fn(async () => ({ id: OTHER_ORG, name: "Other" })) },
+ orgDAL: { findById: vi.fn(async () => ({ id: OTHER_ORG, name: "Other", slug: "other" })) },
permissionService: { getOrgPermission },
licenseDAL: {
countBillableOrgActors: vi.fn(async () => ({ users: 0, identities: 0 })),
@@ -48,7 +48,7 @@ const buildService = () => {
breakdownDAL: {
findOrgTreeNames: vi.fn(async () => []),
findProjectNames: vi.fn(async () => []),
- findAllRootOrgs: vi.fn(async () => ({ orgs: [{ id: ROOT_ORG, name: "Root" }], totalCount: 1 }))
+ findAllRootOrgs: vi.fn(async () => ({ orgs: [{ id: ROOT_ORG, name: "Root", slug: "root" }], totalCount: 1 }))
},
meteredFeatures: [],
licenseClient: {}
diff --git a/backend/src/ee/services/license-v2/license-v2-breakdown-dal.ts b/backend/src/ee/services/license-v2/license-v2-breakdown-dal.ts
index 9315639efc..2dfff0cdd1 100644
--- a/backend/src/ee/services/license-v2/license-v2-breakdown-dal.ts
+++ b/backend/src/ee/services/license-v2/license-v2-breakdown-dal.ts
@@ -7,7 +7,7 @@ import { orgTreeIds } from "@app/lib/knex";
export type TLicenseV2BreakdownDALFactory = ReturnType<typeof licenseV2BreakdownDALFactory>;
export type TScopeOrgRow = { id: string; name: string; isRoot: boolean };
-export type TRootOrgRow = { id: string; name: string };
+export type TRootOrgRow = { id: string; name: string; slug: string };
export type TScopeProjectRow = { id: string; name: string; orgId: string };
@@ -67,12 +67,13 @@ export const licenseV2BreakdownDALFactory = (db: TDbClient) => {
try {
const baseQuery = db.replicaNode()(TableName.Organization).whereNull("rootOrgId");
if (dto.search) {
- void baseQuery.whereILike("name", `%${sanitizeSqlLikeString(dto.search)}%`);
+ const term = `%${sanitizeSqlLikeString(dto.search)}%`;
+ void baseQuery.where((builder) => void builder.whereILike("name", term).orWhereILike("slug", term));
}
const [totalResult, orgs] = await Promise.all([
baseQuery.clone().count({ count: "*" }).first(),
- baseQuery.clone().orderBy("name", "asc").limit(dto.limit).offset(dto.offset).select("id", "name")
+ baseQuery.clone().orderBy("name", "asc").limit(dto.limit).offset(dto.offset).select("id", "name", "slug")
]);
return { orgs: orgs as TRootOrgRow[], totalCount: Number(totalResult?.count ?? 0) };
diff --git a/backend/src/ee/services/license-v2/license-v2-service.ts b/backend/src/ee/services/license-v2/license-v2-service.ts
index 60a677cc93..c9b397ddb3 100644
--- a/backend/src/ee/services/license-v2/license-v2-service.ts
+++ b/backend/src/ee/services/license-v2/license-v2-service.ts
@@ -1060,8 +1060,11 @@ export const licenseV2ServiceFactory = ({
throw new NotFoundError({ message: `Organization with ID '${orgId}' not found` });
}
- const matches = search ? organization.name.toLowerCase().includes(search.toLowerCase()) : true;
- const organizations = matches ? [{ id: organization.id, name: organization.name }] : [];
+ const term = search?.toLowerCase();
+ const matches = term
+ ? organization.name.toLowerCase().includes(term) || organization.slug.toLowerCase().includes(term)
+ : true;
+ const organizations = matches ? [{ id: organization.id, name: organization.name, slug: organization.slug }] : [];
return {
organizations: organizations.slice(offset, offset + limit),
totalCount: organizations.length
diff --git a/frontend/src/hooks/api/billingV2/queries.tsx b/frontend/src/hooks/api/billingV2/queries.tsx
index 6c4ad6c929..d432ec94ea 100644
--- a/frontend/src/hooks/api/billingV2/queries.tsx
+++ b/frontend/src/hooks/api/billingV2/queries.tsx
@@ -33,7 +33,8 @@ export const useGetBillingV2Overview = (orgId: string) => {
return overview;
},
- enabled: Boolean(orgId)
+ enabled: Boolean(orgId),
+ placeholderData: keepPreviousData
});
};
@@ -49,7 +50,8 @@ export const useGetBillingV2Catalog = (orgId: string) => {
return products;
},
- enabled: Boolean(orgId)
+ enabled: Boolean(orgId),
+ placeholderData: keepPreviousData
});
};
diff --git a/frontend/src/hooks/api/billingV2/types.ts b/frontend/src/hooks/api/billingV2/types.ts
index c04632a88f..9e4507b05e 100644
--- a/frontend/src/hooks/api/billingV2/types.ts
+++ b/frontend/src/hooks/api/billingV2/types.ts
@@ -399,6 +399,7 @@ export type BillingV2BreakdownScopeKind = "instance" | "organization";
export type BillingV2Organization = {
id: string;
name: string;
+ slug?: string;
};
export type BillingV2OrganizationsPage = {
diff --git a/frontend/src/hooks/index.ts b/frontend/src/hooks/index.ts
index fd2055b0ff..f632798a72 100644
--- a/frontend/src/hooks/index.ts
+++ b/frontend/src/hooks/index.ts
@@ -5,6 +5,7 @@ export {
export { useDebounce } from "./useDebounce";
export { useDiscardChangesGuard } from "./useDiscardChangesGuard";
export * from "./useGetProjectTypeFromRoute";
+export { useHeldLoading } from "./useHeldLoading";
export { useImplicitProduct } from "./useImplicitProduct";
export { useImplicitProjectId } from "./useImplicitProjectId";
export { useLastLogin } from "./useLastLogin";
diff --git a/frontend/src/hooks/useHeldLoading.ts b/frontend/src/hooks/useHeldLoading.ts
new file mode 100644
index 0000000000..30eaa0c3af
--- /dev/null
+++ b/frontend/src/hooks/useHeldLoading.ts
@@ -0,0 +1,28 @@
+import { useEffect, useRef, useState } from "react";
+
+// Holds a loading flag on screen for a legible minimum. A cached or local answer can arrive faster
+// than a skeleton can be read, which makes a reload look like a flicker rather than a reload; a
+// request slower than the minimum is unaffected.
+export const useHeldLoading = (isLoading: boolean, minMs = 500) => {
+ const [isHeld, setIsHeld] = useState(isLoading);
+ const startedAt = useRef(Date.now());
+
+ useEffect(() => {
+ if (isLoading) {
+ startedAt.current = Date.now();
+ setIsHeld(true);
+ return undefined;
+ }
+
+ const remaining = minMs - (Date.now() - startedAt.current);
+ if (remaining <= 0) {
+ setIsHeld(false);
+ return undefined;
+ }
+
+ const timer = setTimeout(() => setIsHeld(false), remaining);
+ return () => clearTimeout(timer);
+ }, [isLoading, minMs]);
+
+ return isLoading || isHeld;
+};
diff --git a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx
index bcdc6b6b64..e0003de620 100644
--- a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx
@@ -11,7 +11,8 @@ import {
useOrganization,
useOrgPermission
} from "@app/context";
-import { useDebounce } from "@app/hooks";
+import { isInfisicalCloud } from "@app/helpers/platform";
+import { useDebounce, useHeldLoading } from "@app/hooks";
import {
BillingV2BreakdownScopeKind,
useAddBillingV2PaymentMethod,
@@ -82,6 +83,7 @@ export const BillingV2Page = () => {
const {
data: serverOverview,
isPending,
+ isPlaceholderData,
isError,
refetch
} = useGetBillingV2Overview(selectedOrgId);
@@ -153,15 +155,15 @@ export const BillingV2Page = () => {
const isViewingOtherOrg = selectedOrgId !== orgId;
const canManageBilling = hasManageBillingPermission && !isViewingOtherOrg;
+ const isReloadingProducts = useHeldLoading(isPlaceholderData);
+
let subState: BillingV2RenderState = "loading";
if (isError) {
subState = "error";
- } else if (isRootOrgCountPending) {
+ } else if (isPending || isRootOrgCountPending) {
subState = "loading";
} else if (overview) {
subState = overview.subState;
- } else if (isPending) {
- subState = "loading";
}
const removeProd = removeProdId ? catalogById(catalog, removeProdId) : undefined;
@@ -227,7 +229,7 @@ export const BillingV2Page = () => {
};
// A managed (self-hosted licensed) org can't self-serve through Stripe; its plan is set by the license.
- const isManaged = overview?.mode === "managed";
+ const isManaged = overview ? overview.mode === "managed" : !isInfisicalCloud();
const pageDescription = isManaged
? "View your subscription, products, and usage. Your plan is managed through your license."
: "Manage your subscription, products, and payment. Payment is handled securely through Stripe.";
@@ -258,6 +260,7 @@ export const BillingV2Page = () => {
rootOrgs={pickerOrgs}
rootOrgCount={rootOrgCount}
isRootOrgsLoading={isRootOrgsFetching}
+ isReloadingProducts={isReloadingProducts}
selectedOrgId={breakdownScope === "instance" ? ALL_ORGS_VALUE : selectedOrgId}
onSelectOrg={(nextId) => {
if (nextId === ALL_ORGS_VALUE) {
diff --git a/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx b/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx
index 347740ce0d..d123ddebbd 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx
@@ -2,6 +2,7 @@ import { TriangleAlert } from "lucide-react";
import { Alert, AlertDescription, AlertTitle } from "@app/components/v3";
import { cn } from "@app/components/v3/utils";
+import { isInfisicalCloud } from "@app/helpers/platform";
import { BillingV2CatalogProduct, BillingV2Organization, BillingV2Overview } from "@app/hooks/api";
import { BillingV2RenderState } from "../billing-v2-view-types";
@@ -11,7 +12,7 @@ import { InvoicesCard } from "./cards/InvoicesCard";
import { PaymentCard } from "./cards/PaymentCard";
import { ProductsCard } from "./cards/ProductsCard";
import { ErrorPanel } from "./states/ErrorPanel";
-import { OverviewSkeleton } from "./states/OverviewSkeleton";
+import { BillingSectionSkeleton, StatTilesSkeleton } from "./states/OverviewSkeleton";
import { Banner } from "./Banner";
import { RootOrgFilter } from "./RootOrgFilter";
import { TrialBanners } from "./TrialBanners";
@@ -27,6 +28,7 @@ export type OverviewProps = {
rootOrgs: BillingV2Organization[];
rootOrgCount: number;
isRootOrgsLoading: boolean;
+ isReloadingProducts: boolean;
selectedOrgId: string;
onSelectOrg: (orgId: string) => void;
onSearchOrgs: (search: string) => void;
@@ -50,6 +52,7 @@ export const Overview = ({
rootOrgs,
rootOrgCount,
isRootOrgsLoading,
+ isReloadingProducts,
selectedOrgId,
onSelectOrg,
onSearchOrgs,
@@ -74,8 +77,18 @@ export const Overview = ({
if (subState === "loading") {
return (
<div className="flex flex-col gap-4">
- {orgFilter}
- <OverviewSkeleton />
+ <StatTilesSkeleton />
+ <ProductsCard
+ key="products"
+ catalog={catalog}
+ readOnly
+ orgFilter={orgFilter}
+ onManage={onUpgrade}
+ onSetCommitment={onSetCommitment}
+ onViewBreakdown={onViewBreakdown}
+ onContact={onContact}
+ />
+ {isInfisicalCloud() && <BillingSectionSkeleton />}
</div>
);
}
@@ -83,7 +96,8 @@ export const Overview = ({
if (subState === "error" || !overview) {
return (
<div className="flex flex-col gap-4">
- {orgFilter}
+ {/* The picker stays reachable so a failing organization is not a dead end. */}
+ {orgFilter && <div className="flex justify-end">{orgFilter}</div>}
<ErrorPanel onRetry={onRetry} />
</div>
);
@@ -157,11 +171,13 @@ export const Overview = ({
onUpdatePayment={onUpdatePayment}
onManageSubscription={onManageSubscription}
/>
- {orgFilter}
<ProductsCard
+ key="products"
overview={overview}
catalog={catalog}
readOnly={productsReadOnly}
+ orgFilter={orgFilter}
+ isReloading={isReloadingProducts}
onManage={onUpgrade}
onSetCommitment={onSetCommitment}
onViewBreakdown={onViewBreakdown}
@@ -198,11 +214,13 @@ export const Overview = ({
onContact={onContact}
/>
<BillingHeaderCard overview={overview} catalog={catalog} />
- {orgFilter}
<ProductsCard
+ key="products"
overview={overview}
catalog={catalog}
readOnly={productsReadOnly}
+ orgFilter={orgFilter}
+ isReloading={isReloadingProducts}
onManage={onUpgrade}
onSetCommitment={onSetCommitment}
onViewBreakdown={onViewBreakdown}
diff --git a/frontend/src/pages/organization/BillingV2Page/components/RootOrgFilter.tsx b/frontend/src/pages/organization/BillingV2Page/components/RootOrgFilter.tsx
index 676bcc684c..86788a878e 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/RootOrgFilter.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/RootOrgFilter.tsx
@@ -1,14 +1,6 @@
import { useState } from "react";
-import { Building2 } from "lucide-react";
-import {
- Card,
- CardContent,
- CardDescription,
- CardHeader,
- CardTitle,
- Combobox
-} from "@app/components/v3";
+import { Combobox } from "@app/components/v3";
import { BillingV2Organization } from "@app/hooks/api";
// The pinned row's id. Not a real organization, so it never collides with one and the page keys its
@@ -24,6 +16,13 @@ type RootOrgFilterProps = {
isLoading?: boolean;
};
+const OrgLabel = ({ org }: { org: BillingV2Organization }) => (
+ <span className="flex min-w-0 items-baseline gap-2">
+ <span className="truncate">{org.name}</span>
+ {org.slug && <span className="min-w-0 truncate text-xs text-muted">{org.slug}</span>}
+ </span>
+);
+
// Picks which root organization's usage the breakdown explains. A self-hosted licence covers every org
// in the instance, so the billed figure spans all of them and one org's page cannot account for it on
// its own. Cloud bills per root org, so this is not rendered there.
@@ -46,39 +45,28 @@ export const RootOrgFilter = ({
const selectedOrg = orgInPage ?? (lastSelected?.id === value ? lastSelected : null);
return (
- <Card>
- <CardHeader>
- <CardTitle>
- <Building2 className="size-4 text-org" />
- Organization
- </CardTitle>
- <CardDescription>
- This instance&apos;s licence covers every organization on it. Pick one to see the usage it
- contributes.
- </CardDescription>
- </CardHeader>
- <CardContent>
- <Combobox<BillingV2Organization>
- id="billing-root-org-filter"
- placeholder="Select an organization..."
- searchPlaceholder="Search organizations..."
- searchAriaLabel="Search root organizations"
- isLoading={isLoading}
- options={options}
- value={selectedOrg}
- getOptionGroup={(option) => (option.id === ALL_ORGS_VALUE ? "" : "Organizations")}
- onValueChange={(option) => onChange(option.id)}
- onSearchChange={onSearchChange}
- getOptionValue={(option) => option.id}
- getOptionLabel={(option) => option.name}
- emptyMessage="No organizations found"
- listFooter={
- totalCount > orgs.length
- ? `Showing ${orgs.length.toLocaleString()} of ${totalCount.toLocaleString()}. Type in the input to search.`
- : null
- }
- />
- </CardContent>
- </Card>
+ <Combobox<BillingV2Organization>
+ id="billing-root-org-filter"
+ className="w-[34rem] max-w-full"
+ placeholder="Select an organization..."
+ searchPlaceholder="Search organizations..."
+ searchAriaLabel="Search root organizations"
+ isLoading={isLoading}
+ options={options}
+ value={selectedOrg}
+ getOptionGroup={(option) => (option.id === ALL_ORGS_VALUE ? "" : "Organizations")}
+ onValueChange={(option) => onChange(option.id)}
+ onSearchChange={onSearchChange}
+ getOptionValue={(option) => option.id}
+ getOptionLabel={(option) => option.name}
+ renderOption={(option) => <OrgLabel org={option} />}
+ renderValue={(option) => <OrgLabel org={option} />}
+ emptyMessage="No organizations found"
+ listFooter={
+ totalCount > orgs.length
+ ? `Showing ${orgs.length.toLocaleString()} of ${totalCount.toLocaleString()}. Type in the input to search.`
+ : null
+ }
+ />
);
};
diff --git a/frontend/src/pages/organization/BillingV2Page/components/UsageBreakdownSheet.tsx b/frontend/src/pages/organization/BillingV2Page/components/UsageBreakdownSheet.tsx
index b0b78a1c58..de09fa8adb 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/UsageBreakdownSheet.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/UsageBreakdownSheet.tsx
@@ -1,12 +1,11 @@
import { useMemo, useState } from "react";
-import { ArrowDownAZ, ArrowDownWideNarrow, Box, Building2, Search } from "lucide-react";
+import { ArrowDownAZ, ArrowDownWideNarrow, Search } from "lucide-react";
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
- Badge,
Button,
Empty,
EmptyDescription,
@@ -15,6 +14,8 @@ import {
InputGroup,
InputGroupAddon,
InputGroupInput,
+ OrgIcon,
+ ProjectIcon,
Sheet,
SheetContent,
SheetDescription,
@@ -22,6 +23,7 @@ import {
SheetHeader,
SheetTitle,
Skeleton,
+ SubOrgIcon,
Tabs,
TabsList,
TabsTrigger
@@ -77,7 +79,7 @@ const CountShare = ({ count, total, unitLabel }: CountShareProps) => (
type MeterProps = { className: string; width: string; height?: string };
-const Meter = ({ className, width, height = "h-1.5" }: MeterProps) => (
+const Meter = ({ className, width, height = "h-[3px]" }: MeterProps) => (
<div className={cn("w-full overflow-hidden rounded-xs bg-background", height)}>
<div className={cn("animate-bar-grow h-full rounded-xs", className)} style={{ width }} />
</div>
@@ -94,17 +96,17 @@ const ScopeRow = ({ scope, scopedCount, unitLabel, hasProjectDetail }: ScopeRowP
const scopeTint = scope.isRoot ? "bg-org/85" : "bg-sub-org/85";
const orgLevelTint = "bg-neutral/85";
const canExpand = hasProjectDetail && scope.count > 0;
+ const ScopeIcon = scope.isRoot ? OrgIcon : SubOrgIcon;
const projectLabel = `${scope.projects.length} ${scope.projects.length === 1 ? "project" : "projects"}`;
const header = (
<div className="flex min-w-0 flex-1 flex-col gap-2">
<div className="flex items-center justify-between gap-3">
<span className="flex min-w-0 items-center gap-2 text-sm font-medium text-foreground">
- <Building2
+ <ScopeIcon
className={cn("size-3.5 shrink-0", scope.isRoot ? "text-org" : "text-sub-org")}
/>
<span className="truncate">{scope.name}</span>
- {scope.isRoot && <Badge variant="org">Root org</Badge>}
</span>
<CountShare count={scope.count} total={scopedCount} unitLabel={unitLabel} />
</div>
@@ -114,14 +116,19 @@ const ScopeRow = ({ scope, scopedCount, unitLabel, hasProjectDetail }: ScopeRowP
if (!canExpand) {
return (
- <div className="rounded-md border border-border bg-container p-3">
+ <div className="rounded-md border border-border p-3">
<div className="flex">{header}</div>
</div>
);
}
return (
- <Accordion type="single" collapsible>
+ <Accordion
+ variant="ghost"
+ type="single"
+ collapsible
+ className="rounded-md border border-border"
+ >
<AccordionItem value={scope.orgId}>
<AccordionTrigger className="px-3 py-3">{header}</AccordionTrigger>
<AccordionContent className="border-t border-border px-3 pt-3 pb-3.5">
@@ -141,7 +148,7 @@ const ScopeRow = ({ scope, scopedCount, unitLabel, hasProjectDetail }: ScopeRowP
<Meter
className={orgLevelTint}
width={pct(scope.orgLevelCount, scope.count)}
- height="h-1"
+ height="h-[2px]"
/>
</div>
)}
@@ -155,7 +162,7 @@ const ScopeRow = ({ scope, scopedCount, unitLabel, hasProjectDetail }: ScopeRowP
<div key={project.id} className="flex flex-col gap-1.5">
<div className="flex items-center justify-between gap-3">
<span className="flex min-w-0 items-center gap-2 text-xs text-accent">
- <Box className="size-3 shrink-0 text-project" />
+ <ProjectIcon className="size-3 shrink-0 text-project" />
<span className="truncate">{project.name}</span>
</span>
<CountShare count={project.count} total={scope.count} />
@@ -163,7 +170,7 @@ const ScopeRow = ({ scope, scopedCount, unitLabel, hasProjectDetail }: ScopeRowP
<Meter
className="bg-project/85"
width={pct(project.count, scope.count)}
- height="h-1"
+ height="h-[2px]"
/>
</div>
))}
@@ -225,7 +232,7 @@ const BreakdownBody = ({
return (
<div className="flex flex-col gap-4">
- <div className="flex flex-col gap-3 rounded-lg border border-border bg-card p-4">
+ <div className="flex flex-col gap-3 rounded-lg border border-border p-4">
<div className="flex items-baseline gap-2">
<span className="text-2xl font-semibold text-foreground tabular-nums">
{total.toLocaleString()}
@@ -266,14 +273,14 @@ const BreakdownBody = ({
</div>
{subOrgScopes.length > 0 && rootScope && (
- <div className="flex flex-col gap-3 rounded-lg border border-border bg-card p-4">
+ <div className="flex flex-col gap-3 rounded-lg border border-border p-4">
<div className="flex items-baseline gap-2">
<span className="text-2xl font-semibold text-foreground tabular-nums">
{scopedCount.toLocaleString()}
</span>
<span className="text-xs text-muted">{unitLabel}</span>
</div>
- <div className="flex h-2.5 w-full gap-0.5 overflow-hidden rounded-xs bg-background">
+ <div className="flex h-[5px] w-full gap-0.5 overflow-hidden rounded-xs bg-background">
<div
className="animate-bar-grow h-full rounded-xs bg-org/85"
style={{ width: pct(rootScope.count, scopedCount) }}
@@ -340,10 +347,7 @@ const BreakdownBody = ({
<span className="text-2xs tracking-wide text-muted uppercase">
Sub-organizations
</span>
- <span className="text-2xs text-muted">
- {visibleSubOrgs.length}{" "}
- {visibleSubOrgs.length === 1 ? "sub-organization" : "sub-organizations"}
- </span>
+ <span className="text-2xs text-muted tabular-nums">{visibleSubOrgs.length}</span>
</div>
{visibleSubOrgs.length === 0 ? (
diff --git a/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx b/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx
index 01b39a2ec7..f7b47b1094 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx
@@ -11,6 +11,7 @@ import {
CardDescription,
CardHeader,
CardTitle,
+ Skeleton,
Tooltip,
TooltipContent,
TooltipTrigger
@@ -20,6 +21,7 @@ import { useOrganization } from "@app/context";
import {
BillingV2CatalogProduct,
BillingV2Entitlement,
+ BillingV2EntitlementDim,
BillingV2Overview,
useRefreshBillingV2Entitlements
} from "@app/hooks/api";
@@ -205,7 +207,7 @@ const ActiveProductCard = ({
commitNudge && "mb-0"
)}
>
- <span className="text-xs text-muted">Break this down by organization usage</span>
+ <span className="text-xs text-muted">Usage across your organizations</span>
<span className="flex shrink-0 items-center gap-1 text-xs text-accent transition-colors group-hover:text-foreground">
View breakdown
<ChevronRight className="size-3.5" />
@@ -304,10 +306,72 @@ const AvailableProductTile = ({
);
};
+type ProductSkeletonRow = { key: string; hasBar: boolean };
+
+const skeletonRows = (dims: BillingV2EntitlementDim[]): ProductSkeletonRow[] =>
+ dims.map((dim) => ({ key: dim.key, hasBar: dimHasCeiling(dim) }));
+
+const UNKNOWN_PRODUCT_ROWS: ProductSkeletonRow[] = [
+ { key: "first", hasBar: true },
+ { key: "second", hasBar: true }
+];
+
+type ActiveProductCardSkeletonProps = {
+ rows: ProductSkeletonRow[];
+ hasBreakdown: boolean;
+ showAction: boolean;
+ className?: string;
+};
+
+const ActiveProductCardSkeleton = ({
+ rows,
+ hasBreakdown,
+ showAction,
+ className
+}: ActiveProductCardSkeletonProps) => (
+ <div
+ className={cn(
+ "flex flex-col gap-3 overflow-hidden rounded-lg border border-border bg-container p-4",
+ className
+ )}
+ >
+ <div className="flex items-center gap-3">
+ <Skeleton className="size-10 shrink-0 rounded-lg" />
+ <div className="flex min-w-0 flex-1 flex-col gap-2">
+ <Skeleton className="h-3.5 w-2/5" />
+ <Skeleton className="h-2.5 w-1/4" />
+ </div>
+ <Skeleton className="h-4 w-16 shrink-0" />
+ {showAction && <Skeleton className="h-8 w-20 shrink-0 rounded-md" />}
+ </div>
+ {rows.length > 0 && (
+ <div className="flex flex-col gap-3.5">
+ {rows.map((row) => (
+ <div key={row.key} className="flex flex-col gap-2">
+ <div className="flex items-center justify-between gap-2.5">
+ <Skeleton className="h-2.5 w-24" />
+ <Skeleton className="h-2.5 w-28" />
+ </div>
+ {row.hasBar && <Skeleton className="h-[5px] w-full rounded-xs" />}
+ </div>
+ ))}
+ </div>
+ )}
+ {hasBreakdown && (
+ <div className="-mx-4 mt-auto -mb-4 flex items-center justify-between gap-3 border-t border-border px-4 py-3">
+ <Skeleton className="h-2.5 w-44" />
+ <Skeleton className="h-2.5 w-24" />
+ </div>
+ )}
+ </div>
+);
+
type ProductsCardProps = {
- overview: BillingV2Overview;
+ overview?: BillingV2Overview;
catalog: BillingV2CatalogProduct[];
readOnly?: boolean;
+ orgFilter?: ReactNode;
+ isReloading?: boolean;
onManage: (id: string) => void;
onSetCommitment: (id: string) => void;
onViewBreakdown: (id: string) => void;
@@ -318,18 +382,21 @@ export const ProductsCard = ({
overview,
catalog,
readOnly,
+ orgFilter,
+ isReloading,
onManage,
onSetCommitment,
onViewBreakdown,
onContact
}: ProductsCardProps) => {
+ const entitlements = overview?.entitlements ?? {};
// A deprecated product stays visible to existing subscribers but is closed to new ones, so hide it
// from anyone who isn't already entitled to it (plan-level deprecation still shows the product).
const visible = [...catalog]
- .filter((prod) => !prod.deprecated || overview.entitlements[prod.id]?.entitled)
+ .filter((prod) => !prod.deprecated || entitlements[prod.id]?.entitled)
.sort(byDisplayOrder);
- const active = visible.filter((prod) => overview.entitlements[prod.id]?.entitled);
- const available = visible.filter((prod) => !overview.entitlements[prod.id]?.entitled);
+ const active = visible.filter((prod) => entitlements[prod.id]?.entitled);
+ const available = visible.filter((prod) => !entitlements[prod.id]?.entitled);
const { currentOrg } = useOrganization();
const refreshEntitlements = useRefreshBillingV2Entitlements();
@@ -353,32 +420,52 @@ export const ProductsCard = ({
Products
</CardTitle>
<CardDescription>Active products</CardDescription>
- {!readOnly && (
+ {(orgFilter || !readOnly) && (
<CardAction>
- <Tooltip>
- <TooltipTrigger asChild>
- <Button
- variant="outline"
- size="sm"
- isDisabled={refreshEntitlements.isPending}
- onClick={handleRefresh}
- >
- <RefreshCw />
- Refresh
- </Button>
- </TooltipTrigger>
- <TooltipContent>Plan changes may take a few minutes to take effect.</TooltipContent>
- </Tooltip>
+ <div className="flex items-center gap-2">
+ {orgFilter}
+ {!readOnly && (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button
+ variant="outline"
+ size="sm"
+ isDisabled={refreshEntitlements.isPending}
+ onClick={handleRefresh}
+ >
+ <RefreshCw />
+ Refresh
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>
+ Plan changes may take a few minutes to take effect.
+ </TooltipContent>
+ </Tooltip>
+ )}
+ </div>
</CardAction>
)}
</CardHeader>
<CardContent>
- {visible.length === 0 ? (
+ {!overview && (
+ <div className="flex flex-col gap-4">
+ {[0, 1].map((i) => (
+ <ActiveProductCardSkeleton
+ key={i}
+ rows={UNKNOWN_PRODUCT_ROWS}
+ hasBreakdown
+ showAction={false}
+ />
+ ))}
+ </div>
+ )}
+ {overview && visible.length === 0 && (
<CardEmpty
title="No products available"
description="Products will appear here once they're available."
/>
- ) : (
+ )}
+ {overview && visible.length > 0 && (
<>
{active.length === 0 && (
<CardEmpty
@@ -388,16 +475,27 @@ export const ProductsCard = ({
)}
<div className="flex flex-col gap-4">
{active.map((prod) => (
- <ActiveProductCard
- key={prod.id}
- prod={prod}
- entitlement={overview.entitlements[prod.id]}
- readOnly={readOnly}
- selfServe={overview.selfServe}
- onManage={onManage}
- onSetCommitment={onSetCommitment}
- onViewBreakdown={onViewBreakdown}
- />
+ <div key={prod.id} className="relative">
+ <div className={cn(isReloading && "invisible")} aria-hidden={isReloading}>
+ <ActiveProductCard
+ prod={prod}
+ entitlement={entitlements[prod.id]}
+ readOnly={readOnly}
+ selfServe={overview.selfServe}
+ onManage={onManage}
+ onSetCommitment={onSetCommitment}
+ onViewBreakdown={onViewBreakdown}
+ />
+ </div>
+ {isReloading && (
+ <ActiveProductCardSkeleton
+ className="absolute inset-0"
+ rows={skeletonRows(entitlements[prod.id]?.dimensions ?? [])}
+ hasBreakdown={breakdownableDimensions(entitlements[prod.id]).length > 0}
+ showAction={!readOnly && overview.selfServe}
+ />
+ )}
+ </div>
))}
{available.length > 0 && (
<>
diff --git a/frontend/src/pages/organization/BillingV2Page/components/shared.tsx b/frontend/src/pages/organization/BillingV2Page/components/shared.tsx
index 97604998d7..bd6261188f 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/shared.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/shared.tsx
@@ -209,7 +209,7 @@ export const DimensionMeter = ({ dim, color, hideLegend }: DimensionMeterProps)
return (
<div className="flex flex-col gap-1.5">
<div className="flex items-baseline justify-between gap-2.5 text-xs">
- <span className="text-muted">{dim.label}</span>
+ <span className="text-accent">{dim.label}</span>
<span className="text-muted tabular-nums">{right}</span>
</div>
{hasCeiling && (
diff --git a/frontend/src/pages/organization/BillingV2Page/components/states/OverviewSkeleton.tsx b/frontend/src/pages/organization/BillingV2Page/components/states/OverviewSkeleton.tsx
index 58ad9602e5..299c23e520 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/states/OverviewSkeleton.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/states/OverviewSkeleton.tsx
@@ -1,8 +1,7 @@
import { Card, CardAction, CardContent, CardHeader, CardTitle, Skeleton } from "@app/components/v3";
-// Loading placeholder mirroring the header row of stat tiles plus the products card.
-export const OverviewSkeleton = () => (
- <div className="flex flex-col gap-4">
+export const StatTilesSkeleton = () => (
+ <div className="flex flex-col gap-3">
<div className="flex flex-col gap-4 lg:flex-row">
{[0, 1, 2].map((i) => (
<Card key={i} className="flex-1 gap-2 p-4 shadow-none">
@@ -16,32 +15,56 @@ export const OverviewSkeleton = () => (
</CardHeader>
<CardContent className="flex flex-col gap-1.5">
<Skeleton className="h-5 w-2/3" />
- <Skeleton className="h-4 w-20" />
+ <div className="flex min-h-5 items-center">
+ <Skeleton className="h-3 w-24" />
+ </div>
</CardContent>
</Card>
))}
</div>
- <Card>
- <CardHeader>
- <CardTitle>
- <Skeleton className="h-4 w-32" />
- </CardTitle>
- </CardHeader>
- <CardContent className="flex flex-col">
- {[0, 1].map((i) => (
- <div
- key={i}
- className="flex items-center gap-4 border-t border-border py-4 first:border-t-0"
- >
- <Skeleton className="size-[38px] rounded-lg" />
- <div className="flex flex-1 flex-col gap-2">
- <Skeleton className="h-3.5 w-2/5" />
- <Skeleton className="h-2.5 w-1/4" />
- </div>
- <Skeleton className="h-3.5 w-20" />
- </div>
- ))}
- </CardContent>
- </Card>
+ <div className="flex items-start gap-2 px-1">
+ <Skeleton className="mt-[2px] size-3 shrink-0 rounded-full" />
+ <div className="flex flex-1 flex-col gap-1.5">
+ <Skeleton className="h-3 w-full" />
+ <Skeleton className="h-3 w-2/5" />
+ </div>
+ </div>
</div>
);
+
+type CardSkeletonProps = { rows: number; hasAction?: boolean };
+
+const CardSkeleton = ({ rows, hasAction = true }: CardSkeletonProps) => (
+ <Card className="h-full">
+ <CardHeader>
+ <CardTitle>
+ <Skeleton className="h-4 w-32" />
+ </CardTitle>
+ {hasAction && (
+ <CardAction>
+ <Skeleton className="h-8 w-24 rounded-md" />
+ </CardAction>
+ )}
+ </CardHeader>
+ <CardContent className="flex flex-col gap-3">
+ {Array.from({ length: rows }, (_, i) => i).map((row) => (
+ <div key={row} className="flex items-center justify-between gap-4">
+ <Skeleton className="h-3 w-40" />
+ <Skeleton className="h-3 w-20" />
+ </div>
+ ))}
+ </CardContent>
+ </Card>
+);
+
+export const BillingSectionSkeleton = () => (
+ <>
+ <div className="@container">
+ <div className="grid gap-4 @3xl:grid-cols-[2fr_3fr]">
+ <CardSkeleton rows={2} />
+ <CardSkeleton rows={3} />
+ </div>
+ </div>
+ <CardSkeleton rows={3} hasAction={false} />
+ </>
+);