Skip to content

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

feat(usage): enhance usage counter query and loading states

Victor Hugo dos Santos7e8f3dfaf20e
diff --git a/backend/src/services/license-client/usage/usage-counter-dal.ts b/backend/src/services/license-client/usage/usage-counter-dal.ts
index 9ee4b09f28..42527a0ce8 100644
--- a/backend/src/services/license-client/usage/usage-counter-dal.ts
+++ b/backend/src/services/license-client/usage/usage-counter-dal.ts
@@ -365,9 +365,15 @@ export const usageCounterDALFactory = (db: TDbClient) => {
])
.select({
quotaKey: `${TableName.Certificate}.quotaKey`,
- orgId: `${TableName.Project}.orgId`,
- hasWildcard: `${TableName.Certificate}.hasWildcard`
- });
+ orgId: `${TableName.Project}.orgId`
+ })
+ // For each certificate row, it looks at all rows with the same quotaKey and sets hasWildcard to true if any of them is wildcard.
+ .select(
+ db.raw(`bool_or(??) OVER (PARTITION BY ??) as "hasWildcard"`, [
+ `${TableName.Certificate}.hasWildcard`,
+ `${TableName.Certificate}.quotaKey`
+ ])
+ );
const rows = (await db
.replicaNode()
diff --git a/frontend/src/components/v3/generic/Combobox/Combobox.stories.tsx b/frontend/src/components/v3/generic/Combobox/Combobox.stories.tsx
index a211740f4b..d8117d9eb4 100644
--- a/frontend/src/components/v3/generic/Combobox/Combobox.stories.tsx
+++ b/frontend/src/components/v3/generic/Combobox/Combobox.stories.tsx
@@ -200,7 +200,7 @@ const ServerSearchRender = () => {
onValueChange={setValue}
onClear={() => setValue(null)}
onSearchChange={setSearch}
- isLoading={isLoading}
+ isLoading={isLoading || search !== debouncedSearch}
getOptionValue={(option) => option.id}
getOptionLabel={(option) => option.name}
placeholder="Select organization..."
@@ -221,7 +221,8 @@ const ServerSearchRender = () => {
* Passing `onSearchChange` hands filtering to the caller: the internal matcher is switched off
* and `options` renders exactly as given. Use it when the option set is too large to send in
* full, so the popup shows one page of server results and typing fetches the next one. Debounce
- * the query on your side, and pair it with `isLoading` so the popup says it is still working.
+ * the query on your side, and pair it with `isLoading` so the popup says it is still working —
+ * cover the debounce window as well as the request, or the stale page reads as the answer.
*
* It also turns off the auto-highlight that local filtering uses: the list arrives after a debounce
* and a round trip, so highlighting the top match would put it on a row the user has not seen yet and
diff --git a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx
index e0003de620..c902186e0a 100644
--- a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx
@@ -76,6 +76,7 @@ export const BillingV2Page = () => {
search: debouncedOrgSearch,
limit: ORG_PAGE_SIZE
});
+ const isOrgSearchPending = isRootOrgsFetching || orgSearch !== debouncedOrgSearch;
const rootOrgs = orgPage?.organizations ?? [];
const { data: unsearchedOrgPage, isPending: isRootOrgCountPending } =
useGetBillingV2Organizations(orgId, { limit: ORG_PAGE_SIZE });
@@ -259,12 +260,13 @@ export const BillingV2Page = () => {
onViewBreakdown={onViewBreakdown}
rootOrgs={pickerOrgs}
rootOrgCount={rootOrgCount}
- isRootOrgsLoading={isRootOrgsFetching}
+ isRootOrgsLoading={isOrgSearchPending}
isReloadingProducts={isReloadingProducts}
selectedOrgId={breakdownScope === "instance" ? ALL_ORGS_VALUE : selectedOrgId}
onSelectOrg={(nextId) => {
if (nextId === ALL_ORGS_VALUE) {
setBreakdownScope("instance");
+ setSelectedOrgId(orgId);
return;
}
setBreakdownScope("organization");
diff --git a/frontend/src/pages/organization/BillingV2Page/components/UsageBreakdownSheet.tsx b/frontend/src/pages/organization/BillingV2Page/components/UsageBreakdownSheet.tsx
index de09fa8adb..0aa1878763 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/UsageBreakdownSheet.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/UsageBreakdownSheet.tsx
@@ -181,12 +181,74 @@ const ScopeRow = ({ scope, scopedCount, unitLabel, hasProjectDetail }: ScopeRowP
);
};
+const SUB_ORG_ROWS = ["row-a", "row-b", "row-c"];
+
+const ScopeRowSkeleton = () => (
+ <div className="flex flex-col gap-2 rounded-md border border-border p-3">
+ <div className="flex items-center justify-between gap-3">
+ <div className="flex h-5 min-w-0 items-center gap-2">
+ <Skeleton className="size-3.5 shrink-0 rounded-xs" />
+ <Skeleton className="h-3 w-32" />
+ </div>
+ <div className="flex h-4 items-center">
+ <Skeleton className="h-3 w-24" />
+ </div>
+ </div>
+ <Skeleton className="h-[3px] w-full rounded-xs" />
+ </div>
+);
+
const BreakdownSkeleton = () => (
<div className="flex flex-col gap-4">
- <Skeleton className="h-24 w-full" />
- <Skeleton className="h-28 w-full" />
- <Skeleton className="h-14 w-full" />
- <Skeleton className="h-14 w-full" />
+ <div className="flex flex-col gap-3 rounded-lg border border-border p-4">
+ <div className="flex h-8 items-center gap-2">
+ <Skeleton className="h-6 w-12" />
+ <Skeleton className="h-3 w-28" />
+ </div>
+ <div className="flex h-4 items-center gap-4">
+ <Skeleton className="h-3 w-28" />
+ <Skeleton className="h-3 w-32" />
+ </div>
+ </div>
+
+ <div className="flex flex-col gap-1 pt-1">
+ <div className="flex h-6 items-center">
+ <Skeleton className="h-4 w-44" />
+ </div>
+ <div className="flex h-4 items-center">
+ <Skeleton className="h-3 w-64" />
+ </div>
+ </div>
+
+ <div className="flex flex-col gap-3 rounded-lg border border-border p-4">
+ <div className="flex h-8 items-center gap-2">
+ <Skeleton className="h-6 w-12" />
+ <Skeleton className="h-3 w-28" />
+ </div>
+ <Skeleton className="h-[5px] w-full rounded-xs" />
+ <div className="flex h-4 items-center gap-5">
+ <Skeleton className="h-3 w-40" />
+ <Skeleton className="h-3 w-36" />
+ </div>
+ </div>
+
+ <ScopeRowSkeleton />
+
+ <div className="flex flex-col gap-2.5">
+ <div className="flex items-center gap-2">
+ <Skeleton className="h-9 flex-1 rounded-md" />
+ <Skeleton className="h-9 w-36 shrink-0 rounded-md" />
+ </div>
+ <div className="flex h-4 items-center justify-between gap-3 px-0.5">
+ <Skeleton className="h-2.5 w-32" />
+ <Skeleton className="h-2.5 w-6" />
+ </div>
+ <div className="flex flex-col gap-2">
+ {SUB_ORG_ROWS.map((row) => (
+ <ScopeRowSkeleton key={row} />
+ ))}
+ </div>
+ </div>
</div>
);
@@ -397,11 +459,13 @@ export const UsageBreakdownSheet = ({
const [activeKey, setActiveKey] = useState(dimensions[0]?.key ?? "");
const activeDim = dimensions.find((dim) => dim.key === activeKey) ?? dimensions[0];
+ const dimensionKey = activeDim?.key ?? null;
const {
data: breakdown,
isPending,
isError
- } = useGetBillingV2UsageBreakdown(orgId, activeDim?.key ?? null, scope);
+ } = useGetBillingV2UsageBreakdown(orgId, dimensionKey, scope);
+ const isLoading = isPending && Boolean(dimensionKey);
return (
<Sheet open onOpenChange={(open) => !open && onClose()}>
@@ -427,7 +491,18 @@ export const UsageBreakdownSheet = ({
</Tabs>
)}
- {isPending && <BreakdownSkeleton />}
+ {isLoading && <BreakdownSkeleton />}
+
+ {!dimensionKey && (
+ <Empty className="border">
+ <EmptyHeader>
+ <EmptyTitle>Nothing to break down</EmptyTitle>
+ <EmptyDescription>
+ This product no longer meters usage that can be traced to an organization.
+ </EmptyDescription>
+ </EmptyHeader>
+ </Empty>
+ )}
{isError && (
<Empty className="border">