Skip to content

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

feat(insights): show unused access as a coloured percentage

Dimitris Staratzise0af06b45b1b
diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessCard.tsx b/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessCard.tsx
index 78caedafc1..77b35ae42e 100644
--- a/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessCard.tsx
+++ b/frontend/src/pages/secret-manager/InsightsPage/components/UnusedAccessCard.tsx
@@ -25,7 +25,10 @@ import {
TableCell,
TableHead,
TableHeader,
- TableRow
+ TableRow,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger
} from "@app/components/v3";
import { useProject, useSubscription } from "@app/context";
import { usePagination, useResetPageHelper } from "@app/hooks";
@@ -34,7 +37,9 @@ import { TUnusedAccessPrincipal, useGetUnusedAccess } from "@app/hooks/api/secre
import {
describeReadPeriod,
formatRemainingTtl,
- PRINCIPAL_TYPE_CONFIG
+ PRINCIPAL_TYPE_CONFIG,
+ unusedSharePercent,
+ unusedShareVariant
} from "./unusedAccessHelpers";
import { UnusedAccessPrincipalSheet } from "./UnusedAccessPrincipalSheet";
@@ -132,11 +137,23 @@ export const UnusedAccessCard = () => {
</div>
</TableCell>
<TableCell className="whitespace-nowrap">
- <span className="font-medium">{row.unreadCount}</span>
- <span className="text-muted">
- {" "}
- of {row.entitledCount} {row.entitledCount === 1 ? "secret" : "secrets"}
- </span>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <span>
+ <Badge
+ variant={unusedShareVariant(
+ unusedSharePercent(row.unreadCount, row.entitledCount)
+ )}
+ >
+ {unusedSharePercent(row.unreadCount, row.entitledCount)}%
+ </Badge>
+ </span>
+ </TooltipTrigger>
+ <TooltipContent>
+ Has not read {row.unreadCount} of the {row.entitledCount}{" "}
+ {row.entitledCount === 1 ? "secret" : "secrets"} it can access {readPeriod}
+ </TooltipContent>
+ </Tooltip>
</TableCell>
<TableCell>
<div className="flex flex-wrap gap-1">
diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/unusedAccessHelpers.ts b/frontend/src/pages/secret-manager/InsightsPage/components/unusedAccessHelpers.ts
index 217ab00d88..a820094cf9 100644
--- a/frontend/src/pages/secret-manager/InsightsPage/components/unusedAccessHelpers.ts
+++ b/frontend/src/pages/secret-manager/InsightsPage/components/unusedAccessHelpers.ts
@@ -18,6 +18,20 @@ export const describeReadPeriod = (trackingStartedAt: string, fullWindowFrom: st
? `since ${format(new Date(trackingStartedAt), "PP")}`
: "in the last 30 days";
+// The share of the secrets a principal can read that it has not read, as a whole percentage that only reads 0
+// or 100 when it is exactly that.
+export const unusedSharePercent = (unreadCount: number, entitledCount: number) => {
+ if (unreadCount >= entitledCount) return 100;
+ return Math.min(99, Math.max(1, Math.round((unreadCount / Math.max(1, entitledCount)) * 100)));
+};
+
+// Most of its access unread is the strongest sign a principal has access it does not need.
+export const unusedShareVariant = (percent: number) => {
+ if (percent >= 75) return "danger" as const;
+ if (percent >= 25) return "warning" as const;
+ return "success" as const;
+};
+
export const formatRemainingTtl = (seconds: number) => {
if (seconds < 60) {
const remainingSeconds = Math.max(1, seconds);