Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Centralize monitored-system availability presentation

rcourtmanb7366055d8d7
diff --git a/docs/release-control/v6/internal/subsystems/cloud-paid.md b/docs/release-control/v6/internal/subsystems/cloud-paid.md
index 3412bff344..96899c11ce 100644
--- a/docs/release-control/v6/internal/subsystems/cloud-paid.md
+++ b/docs/release-control/v6/internal/subsystems/cloud-paid.md
@@ -672,7 +672,14 @@ system counts once without the panel inventing a second counting model.
When canonical usage is not safe to read yet and the backend returns
`monitored_system_usage_unavailable` or entitlements mark the monitored-system
current count unavailable, the usage surface must render helper-owned
-verification copy instead of a synthetic `0 / limit` ledger total.
+verification copy instead of a synthetic `0 / limit` ledger total. The
+canonical `current_available` interpretation, unavailable reason mapping,
+plan-section usage summary, remaining-capacity copy, and upgrade-pressure
+urgency decision all belong to
+`frontend-modern/src/utils/monitoredSystemPresentation.ts`; Pro license panels,
+ledger panels, and shared warning-banner plumbing must consume that helper
+instead of rechecking entitlement availability or hard-coding `Verifying…`,
+`Unavailable`, or `0 / limit` formatting locally.
The entitlement payload builder must only mark monitored-system usage available
from an explicit canonical `MonitoredSystemsAvailable` signal supplied by the
runtime usage boundary. Deprecated compatibility aliases such as `Nodes`, or a
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index 5251a9ad3e..ea11f5606b 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -212,9 +212,10 @@ work extends shared components instead of creating new local variants.
unscoped billing screen. Monitored-system warning banners must also honor
canonical runtime usage availability before treating a limit as urgent:
when the backend marks `max_monitored_systems.current_available=false`,
- the shared banner model must suppress usage summaries, upgrade pressure,
- and upgrade-impression telemetry rather than rendering stale `current/limit`
- counts or paid-plan CTAs.
+ the shared banner model must consume the cloud-paid monitored-system
+ presentation helper and suppress usage summaries, upgrade pressure, and
+ upgrade-impression telemetry rather than rendering stale `current/limit`
+ counts or paid-plan CTAs from banner-local availability checks.
15. Keep assistant availability bootstrap on the shared app-shell boundary.
`frontend-modern/src/useAppRuntimeState.ts`,
`frontend-modern/src/App.tsx`,
diff --git a/frontend-modern/src/components/Settings/MonitoredSystemLedgerPanel.tsx b/frontend-modern/src/components/Settings/MonitoredSystemLedgerPanel.tsx
index 9c95e27699..445f21031e 100644
--- a/frontend-modern/src/components/Settings/MonitoredSystemLedgerPanel.tsx
+++ b/frontend-modern/src/components/Settings/MonitoredSystemLedgerPanel.tsx
@@ -24,6 +24,7 @@ import {
formatMonitoredSystemLedgerUnavailableMessage,
formatMonitoredSystemLatestIncludedSignalSentence,
formatMonitoredSystemSurfaceAttribution,
+ getMonitoredSystemLimitUnavailableReason,
getMonitoredSystemLedgerErrorState,
getMonitoredSystemLedgerDescription,
getMonitoredSystemLedgerHiddenState,
@@ -32,6 +33,7 @@ import {
getMonitoredSystemLedgerUnavailableState,
getMonitoredSystemCountingDetailsToggleLabel,
getMonitoredSystemLedgerPresentation,
+ isMonitoredSystemLimitUsageAvailable,
} from '@/utils/monitoredSystemPresentation';
import { MonitoredSystemDefinitionDisclosure } from '@/components/Commercial/MonitoredSystemDefinitionDisclosure';
import {
@@ -122,15 +124,15 @@ export function MonitoredSystemLedgerPanel(props: MonitoredSystemLedgerPanelProp
if (apiErrorCode(explanation.error) === 'monitored_system_usage_unavailable') {
return apiErrorDetailField(explanation.error, 'reason') ?? undefined;
}
- if (!ledger() && props.monitoredSystemLimit?.current_available === false) {
- return props.monitoredSystemLimit.current_unavailable_reason;
+ if (!ledger()) {
+ return getMonitoredSystemLimitUnavailableReason(props.monitoredSystemLimit);
}
return undefined;
};
const usageUnavailable = () =>
!ledger() &&
(apiErrorCode(explanation.error) === 'monitored_system_usage_unavailable' ||
- props.monitoredSystemLimit?.current_available === false);
+ !isMonitoredSystemLimitUsageAvailable(props.monitoredSystemLimit));
const genericError = () => Boolean(explanation.error) && !usageUnavailable();
const continuity = () => props.monitoredSystemContinuity ?? null;
const hasContinuityContext = () => {
diff --git a/frontend-modern/src/components/Settings/__tests__/ProLicensePanel.test.tsx b/frontend-modern/src/components/Settings/__tests__/ProLicensePanel.test.tsx
index ce7e5ce7b1..f09203e7e9 100644
--- a/frontend-modern/src/components/Settings/__tests__/ProLicensePanel.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/ProLicensePanel.test.tsx
@@ -350,7 +350,7 @@ describe('ProLicensePanel', () => {
});
expect(
- screen.getByText(/still collecting the first supplemental inventory baseline/i),
+ screen.getByText(/still collecting the first provider-owned inventory baseline/i),
).toBeInTheDocument();
expect(screen.getByText('Verifying…')).toBeInTheDocument();
expect(screen.getByText('Unavailable')).toBeInTheDocument();
diff --git a/frontend-modern/src/components/Settings/useProLicensePanelState.ts b/frontend-modern/src/components/Settings/useProLicensePanelState.ts
index 4edb1ac61d..5a252b0c56 100644
--- a/frontend-modern/src/components/Settings/useProLicensePanelState.ts
+++ b/frontend-modern/src/components/Settings/useProLicensePanelState.ts
@@ -45,6 +45,10 @@ import {
type SelfHostedBillingSection,
} from '@/utils/pricingHandoff';
import { buildSelfHostedCommercialPlanModel } from '@/utils/commercialBillingModel';
+import {
+ getMonitoredSystemLimitRemainingCapacity,
+ getMonitoredSystemLimitUsageSummary,
+} from '@/utils/monitoredSystemPresentation';
import { runStartProTrialAction } from '@/utils/trialStartAction';
import { resolveUpgradeDestination, type UpgradeDestination } from '@/utils/upgradeNavigation';
import { SELF_HOSTED_PRO_BILLING_PRESENTATION } from './selfHostedBillingPresentation';
@@ -241,27 +245,12 @@ export function useProLicensePanelState() {
const limitStatus = (key: string) => entitlements()?.limits?.find((entry) => entry.key === key);
const monitoredSystemLimitStatus = createMemo(() => limitStatus('max_monitored_systems'));
- const monitoredSystemUsageAvailable = createMemo(
- () => monitoredSystemLimitStatus()?.current_available !== false,
+ const monitoredSystemUsageSummary = createMemo(() =>
+ getMonitoredSystemLimitUsageSummary(monitoredSystemLimitStatus()),
+ );
+ const remainingSystemCapacity = createMemo(() =>
+ getMonitoredSystemLimitRemainingCapacity(monitoredSystemLimitStatus()),
);
- const monitoredSystemUsage = createMemo(() => monitoredSystemLimitStatus()?.current ?? 0);
- const monitoredSystemLimit = createMemo(() => monitoredSystemLimitStatus()?.limit ?? 0);
- const monitoredSystemUsageSummary = createMemo(() => {
- if (!monitoredSystemUsageAvailable()) {
- return 'Verifying…';
- }
- const limit = monitoredSystemLimit();
- if (limit > 0) {
- return `${monitoredSystemUsage()} / ${limit}`;
- }
- return monitoredSystemUsage();
- });
- const remainingSystemCapacity = createMemo(() => {
- if (!monitoredSystemUsageAvailable()) return 'Unavailable';
- const limit = monitoredSystemLimit();
- if (limit <= 0) return 'Unlimited';
- return Math.max(limit - monitoredSystemUsage(), 0);
- });
const monitoredSystemContinuity = createMemo(() => entitlements()?.monitored_system_continuity);
const monitoredSystemContinuityNotice = createMemo(() =>
getMonitoredSystemContinuityNotice(monitoredSystemContinuity(), monitoredSystemLimitStatus()),
diff --git a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
index 90adb01db9..8217bd950b 100644
--- a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
+++ b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
@@ -694,7 +694,9 @@ describe('shared primitive guardrails', () => {
expect(monitoredSystemLimitWarningBannerModelSource).toContain(
'isMonitoredSystemLimitUsageAvailable',
);
- expect(monitoredSystemLimitWarningBannerModelSource).toContain('current_available');
+ expect(monitoredSystemLimitWarningBannerModelSource).not.toContain(
+ 'current_available !== false',
+ );
expect(monitoredSystemLimitWarningBannerModelSource).toContain(
'SELF_HOSTED_PRO_BILLING_USAGE_COUNTING_RULES_HREF',
);
diff --git a/frontend-modern/src/components/shared/__tests__/MonitoredSystemLimitWarningBanner.test.tsx b/frontend-modern/src/components/shared/__tests__/MonitoredSystemLimitWarningBanner.test.tsx
index 24d25fd837..5e768ea708 100644
--- a/frontend-modern/src/components/shared/__tests__/MonitoredSystemLimitWarningBanner.test.tsx
+++ b/frontend-modern/src/components/shared/__tests__/MonitoredSystemLimitWarningBanner.test.tsx
@@ -155,7 +155,9 @@ describe('MonitoredSystemLimitWarningBanner', () => {
expect(monitoredSystemLimitWarningBannerModelSource).toContain(
'isMonitoredSystemLimitUsageAvailable',
);
- expect(monitoredSystemLimitWarningBannerModelSource).toContain('current_available');
+ expect(monitoredSystemLimitWarningBannerModelSource).not.toContain(
+ 'current_available !== false',
+ );
expect(monitoredSystemLimitWarningBannerModelSource).not.toContain('Upgrade to add more');
expect(monitoredSystemLimitWarningBannerModelSource).not.toContain('Install v6 collectors');
});
diff --git a/frontend-modern/src/components/shared/monitoredSystemLimitWarningBannerModel.ts b/frontend-modern/src/components/shared/monitoredSystemLimitWarningBannerModel.ts
index 728069d753..72714b6280 100644
--- a/frontend-modern/src/components/shared/monitoredSystemLimitWarningBannerModel.ts
+++ b/frontend-modern/src/components/shared/monitoredSystemLimitWarningBannerModel.ts
@@ -6,15 +6,16 @@ import {
getMonitoredSystemLimitInstallCollectorsLabel,
getMonitoredSystemLimitLearnMoreLabel,
getMonitoredSystemLimitUpgradeLabel,
+ isMonitoredSystemLimitUrgent as isCanonicalMonitoredSystemLimitUrgent,
+ isMonitoredSystemLimitUsageAvailable as isCanonicalMonitoredSystemLimitUsageAvailable,
+ type MonitoredSystemLimitUsageStatus,
type MonitoredSystemLegacyConnectionCounts,
} from '@/utils/monitoredSystemPresentation';
import { SELF_HOSTED_PRO_BILLING_USAGE_COUNTING_RULES_HREF } from '@/utils/pricingHandoff';
-type LimitState = {
+type LimitState = MonitoredSystemLimitUsageStatus & {
current: number;
limit: number;
- current_available?: boolean;
- current_unavailable_reason?: string;
state?: string;
};
@@ -28,13 +29,11 @@ export const MONITORED_SYSTEM_LIMIT_INSTALL_COLLECTORS_LABEL =
export const MONITORED_SYSTEM_LIMIT_UPGRADE_LABEL = getMonitoredSystemLimitUpgradeLabel();
export function isMonitoredSystemLimitUsageAvailable(limit: LimitState | undefined): boolean {
- return limit?.current_available !== false;
+ return isCanonicalMonitoredSystemLimitUsageAvailable(limit);
}
export function isMonitoredSystemLimitUrgent(limit: LimitState | undefined): boolean {
- if (!limit || !isMonitoredSystemLimitUsageAvailable(limit)) return false;
- const state = limit?.state;
- return state === 'warning' || state === 'enforced';
+ return isCanonicalMonitoredSystemLimitUrgent(limit);
}
export function shouldShowMonitoredSystemLimitBanner(limit: LimitState | undefined): boolean {
diff --git a/frontend-modern/src/utils/__tests__/licensePresentation.test.ts b/frontend-modern/src/utils/__tests__/licensePresentation.test.ts
index 49e70cec62..c5208d0e2a 100644
--- a/frontend-modern/src/utils/__tests__/licensePresentation.test.ts
+++ b/frontend-modern/src/utils/__tests__/licensePresentation.test.ts
@@ -187,6 +187,7 @@ describe('licensePresentation', () => {
),
).toMatchObject({
title: 'Migration continuity verification pending',
+ body: expect.stringContaining('first provider-owned inventory baseline'),
tone: expect.stringContaining('amber'),
});
expect(
diff --git a/frontend-modern/src/utils/__tests__/monitoredSystemPresentation.test.ts b/frontend-modern/src/utils/__tests__/monitoredSystemPresentation.test.ts
index c8426d2bf5..494552d504 100644
--- a/frontend-modern/src/utils/__tests__/monitoredSystemPresentation.test.ts
+++ b/frontend-modern/src/utils/__tests__/monitoredSystemPresentation.test.ts
@@ -1,9 +1,15 @@
import { describe, expect, it } from 'vitest';
+import proLicensePanelStateSource from '@/components/Settings/useProLicensePanelState.ts?raw';
+import monitoredSystemLedgerPanelSource from '@/components/Settings/MonitoredSystemLedgerPanel.tsx?raw';
+import monitoredSystemLimitWarningBannerModelSource from '@/components/shared/monitoredSystemLimitWarningBannerModel.ts?raw';
+import licensePresentationSource from '@/utils/licensePresentation.ts?raw';
+import monitoredSystemPresentationSource from '@/utils/monitoredSystemPresentation.ts?raw';
import {
formatMonitoredSystemAdmissionPreviewUnavailableMessage,
formatMonitoredSystemGroupedSourcesLabel,
formatMonitoredSystemLegacyConnectionBreakdown,
+ formatMonitoredSystemUsageUnavailableMessage,
getMonitoredSystemBriefSummary,
formatMonitoredSystemLimitSummary,
formatMonitoredSystemLedgerUnavailableMessage,
@@ -24,11 +30,16 @@ import {
getMonitoredSystemLedgerPolicyLoadingState,
getMonitoredSystemLedgerUnavailableState,
getMonitoredSystemLimitInstallCollectorsLabel,
+ getMonitoredSystemLimitRemainingCapacity,
getMonitoredSystemLimitLearnMoreLabel,
+ getMonitoredSystemLimitUnavailableReason,
getMonitoredSystemLimitUpgradeLabel,
+ getMonitoredSystemLimitUsageSummary,
getMonitoredSystemSourceLabel,
getMonitoredSystemStatusFallbackSummary,
getMonitoredSystemSurfaceTypeLabel,
+ isMonitoredSystemLimitUrgent,
+ isMonitoredSystemLimitUsageAvailable,
} from '@/utils/monitoredSystemPresentation';
describe('monitoredSystemPresentation', () => {
@@ -57,6 +68,7 @@ describe('monitoredSystemPresentation', () => {
continuityCapturePendingLabel: 'Pending',
continuityCaptureCapturedLabel: 'Captured',
usageVerifyingLabel: 'Verifying…',
+ remainingCapacityUnavailableLabel: 'Unavailable',
unlimitedLimitLabel: 'Unlimited',
loadingState: {
text: 'Loading monitored system usage…',
@@ -175,6 +187,29 @@ describe('monitoredSystemPresentation', () => {
);
});
+ it('keeps monitored-system usage availability on the shared presentation helper', () => {
+ expect(monitoredSystemPresentationSource).toContain(
+ 'export function isMonitoredSystemLimitUsageAvailable',
+ );
+ expect(monitoredSystemPresentationSource).toContain(
+ 'export function getMonitoredSystemLimitUsageSummary',
+ );
+ expect(monitoredSystemPresentationSource).toContain(
+ 'export function getMonitoredSystemLimitRemainingCapacity',
+ );
+
+ for (const source of [
+ licensePresentationSource,
+ monitoredSystemLedgerPanelSource,
+ monitoredSystemLimitWarningBannerModelSource,
+ proLicensePanelStateSource,
+ ]) {
+ expect(source).not.toContain('current_available !== false');
+ }
+ expect(proLicensePanelStateSource).not.toContain("'Verifying…'");
+ expect(proLicensePanelStateSource).not.toContain("'Unavailable'");
+ });
+
it('returns canonical monitored-system limit warning copy', () => {
expect(getMonitoredSystemLimitLearnMoreLabel()).toBe('Learn more');
expect(getMonitoredSystemLimitInstallCollectorsLabel()).toBe('Install v6 collectors');
@@ -204,6 +239,59 @@ describe('monitoredSystemPresentation', () => {
expect(formatMonitoredSystemOverflowSummary(undefined)).toBe('');
});
+ it('centralizes monitored-system limit availability and capacity presentation', () => {
+ const unavailableLimit = {
+ current: 0,
+ limit: 10,
+ current_available: false,
+ current_unavailable_reason: 'supplemental_inventory_unsettled',
+ state: 'enforced',
+ };
+
+ expect(isMonitoredSystemLimitUsageAvailable(unavailableLimit)).toBe(false);
+ expect(getMonitoredSystemLimitUnavailableReason(unavailableLimit)).toBe(
+ 'supplemental_inventory_unsettled',
+ );
+ expect(getMonitoredSystemLimitUsageSummary(unavailableLimit)).toBe('Verifying…');
+ expect(getMonitoredSystemLimitRemainingCapacity(unavailableLimit)).toBe('Unavailable');
+ expect(isMonitoredSystemLimitUrgent(unavailableLimit)).toBe(false);
+ expect(
+ formatMonitoredSystemUsageUnavailableMessage(unavailableLimit.current_unavailable_reason),
+ ).toBe(
+ 'Pulse is still collecting the first provider-owned inventory baseline. The monitored-system ledger will appear after that baseline completes.',
+ );
+
+ expect(
+ getMonitoredSystemLimitUsageSummary({
+ current: 7,
+ limit: 10,
+ current_available: true,
+ }),
+ ).toBe('7 / 10');
+ expect(
+ getMonitoredSystemLimitRemainingCapacity({
+ current: 7,
+ limit: 10,
+ current_available: true,
+ }),
+ ).toBe(3);
+ expect(
+ getMonitoredSystemLimitRemainingCapacity({
+ current: 7,
+ limit: 0,
+ current_available: true,
+ }),
+ ).toBe('Unlimited');
+ expect(
+ isMonitoredSystemLimitUrgent({
+ current: 9,
+ limit: 10,
+ current_available: true,
+ state: 'warning',
+ }),
+ ).toBe(true);
+ });
+
it('returns canonical monitored-system admission unavailable copy', () => {
expect(getMonitoredSystemAdmissionPreviewUnavailableTitle()).toBe(
'Monitored-system capacity is temporarily unavailable',
diff --git a/frontend-modern/src/utils/licensePresentation.ts b/frontend-modern/src/utils/licensePresentation.ts
index 1956e9792d..c59dcd67a7 100644
--- a/frontend-modern/src/utils/licensePresentation.ts
+++ b/frontend-modern/src/utils/licensePresentation.ts
@@ -1,11 +1,16 @@
import type { BillingState, HostedOrganizationSummary } from '@/api/billingAdmin';
import type {
CommercialMigrationStatus,
- EntitlementLimitStatus,
LicenseStatus,
MonitoredSystemContinuityStatus,
} from '@/api/license';
import { CLOUD_PLAN_LABELS } from '@/utils/cloudPlans';
+import {
+ formatMonitoredSystemUsageUnavailableMessage,
+ getMonitoredSystemLimitUnavailableReason,
+ isMonitoredSystemLimitUsageAvailable,
+ type MonitoredSystemLimitUsageStatus,
+} from '@/utils/monitoredSystemPresentation';
import { titleCaseDelimitedLabel } from '@/utils/textPresentation';
const TIER_LABELS: Record<string, string> = {
@@ -159,24 +164,11 @@ export const getGrandfatheredPriceContinuityNotice = (
};
};
-const monitoredSystemUnavailableReasonBody = (reason?: string): string => {
- switch ((reason || '').trim().toLowerCase()) {
- case 'supplemental_inventory_unsettled':
- return 'Pulse is still collecting the first supplemental inventory baseline for this installation. Current monitored-system usage will appear after that baseline completes.';
- case 'supplemental_inventory_rebuild_pending':
- return 'Pulse has collected supplemental inventory, but it is still rebuilding the canonical monitored-system ledger. Current usage will appear when that rebuild finishes.';
- case 'monitor_state_unavailable':
- default:
- return 'Pulse cannot currently verify monitored-system usage for this installation. Refresh after the monitoring runtime settles.';
- }
-};
-
export const getMonitoredSystemContinuityNotice = (
continuity?: MonitoredSystemContinuityStatus | null,
- limit?: Pick<EntitlementLimitStatus, 'current_available' | 'current_unavailable_reason'> | null,
+ limit?: MonitoredSystemLimitUsageStatus | null,
): LicenseInlineNotice | null => {
- const currentAvailable = limit?.current_available !== false;
- if (!currentAvailable) {
+ if (!isMonitoredSystemLimitUsageAvailable(limit)) {
const title =
continuity?.capture_pending === true
? 'Migration continuity verification pending'
@@ -184,7 +176,9 @@ export const getMonitoredSystemContinuityNotice = (
return {
tone: 'border-amber-200 dark:border-amber-900 bg-amber-50 dark:bg-amber-900 text-amber-900 dark:text-amber-100',
title,
- body: monitoredSystemUnavailableReasonBody(limit?.current_unavailable_reason),
+ body: formatMonitoredSystemUsageUnavailableMessage(
+ getMonitoredSystemLimitUnavailableReason(limit),
+ ),
};
}
diff --git a/frontend-modern/src/utils/monitoredSystemPresentation.ts b/frontend-modern/src/utils/monitoredSystemPresentation.ts
index 715904e0ea..13fa378508 100644
--- a/frontend-modern/src/utils/monitoredSystemPresentation.ts
+++ b/frontend-modern/src/utils/monitoredSystemPresentation.ts
@@ -1,4 +1,4 @@
-const normalizeMonitoredSystemValue = (value: string | undefined): string =>
+const normalizeMonitoredSystemValue = (value: string | null | undefined): string =>
value?.trim().toLowerCase() ?? '';
const titleCaseWords = (value: string): string =>
@@ -32,6 +32,7 @@ const MONITORED_SYSTEM_LEDGER_PRESENTATION = {
continuityCapturePendingLabel: 'Pending',
continuityCaptureCapturedLabel: 'Captured',
usageVerifyingLabel: 'Verifying…',
+ remainingCapacityUnavailableLabel: 'Unavailable',
unlimitedLimitLabel: 'Unlimited',
loadingState: {
text: 'Loading monitored system usage…',
@@ -102,6 +103,14 @@ export type MonitoredSystemLegacyConnectionCounts = {
kubernetes_clusters: number;
};
+export type MonitoredSystemLimitUsageStatus = {
+ current?: number | null;
+ limit?: number | null;
+ current_available?: boolean | null;
+ current_unavailable_reason?: string | null;
+ state?: string | null;
+};
+
export function getMonitoredSystemLedgerPresentation() {
return MONITORED_SYSTEM_LEDGER_PRESENTATION;
}
@@ -144,7 +153,7 @@ export function getMonitoredSystemLedgerHiddenState() {
return MONITORED_SYSTEM_LEDGER_PRESENTATION.hiddenState;
}
-export function formatMonitoredSystemLedgerUnavailableMessage(reason?: string): string {
+export function formatMonitoredSystemUsageUnavailableMessage(reason?: string | null): string {
switch (normalizeMonitoredSystemValue(reason)) {
case 'supplemental_inventory_unsettled':
return MONITORED_SYSTEM_LEDGER_PRESENTATION.unavailableState.unsettledMessage;
@@ -155,6 +164,61 @@ export function formatMonitoredSystemLedgerUnavailableMessage(reason?: string):
}
}
+export function formatMonitoredSystemLedgerUnavailableMessage(reason?: string | null): string {
+ return formatMonitoredSystemUsageUnavailableMessage(reason);
+}
+
+export function isMonitoredSystemLimitUsageAvailable(
+ limit?: MonitoredSystemLimitUsageStatus | null,
+): boolean {
+ return limit?.current_available !== false;
+}
+
+export function getMonitoredSystemLimitUnavailableReason(
+ limit?: MonitoredSystemLimitUsageStatus | null,
+): string | undefined {
+ if (isMonitoredSystemLimitUsageAvailable(limit)) return undefined;
+ return limit?.current_unavailable_reason?.trim() || undefined;
+}
+
+export function getMonitoredSystemLimitUsageSummary(
+ limit?: MonitoredSystemLimitUsageStatus | null,
+): string | number {
+ if (!isMonitoredSystemLimitUsageAvailable(limit)) {
+ return MONITORED_SYSTEM_LEDGER_PRESENTATION.usageVerifyingLabel;
+ }
+
+ const current = typeof limit?.current === 'number' ? limit.current : 0;
+ const planLimit = typeof limit?.limit === 'number' ? limit.limit : 0;
+ if (planLimit > 0) {
+ return `${current} / ${planLimit}`;
+ }
+ return current;
+}
+
+export function getMonitoredSystemLimitRemainingCapacity(
+ limit?: MonitoredSystemLimitUsageStatus | null,
+): string | number {
+ if (!isMonitoredSystemLimitUsageAvailable(limit)) {
+ return MONITORED_SYSTEM_LEDGER_PRESENTATION.remainingCapacityUnavailableLabel;
+ }
+
+ const current = typeof limit?.current === 'number' ? limit.current : 0;
+ const planLimit = typeof limit?.limit === 'number' ? limit.limit : 0;
+ if (planLimit <= 0) {
+ return MONITORED_SYSTEM_LEDGER_PRESENTATION.unlimitedLimitLabel;
+ }
+ return Math.max(planLimit - current, 0);
+}
+
+export function isMonitoredSystemLimitUrgent(
+ limit?: MonitoredSystemLimitUsageStatus | null,
+): boolean {
+ if (!limit || !isMonitoredSystemLimitUsageAvailable(limit)) return false;
+ const state = normalizeMonitoredSystemValue(limit.state ?? undefined);
+ return state === 'warning' || state === 'enforced';
+}
+
export function getMonitoredSystemCountingDetailsToggleLabel(expanded: boolean): string {
return expanded
? MONITORED_SYSTEM_LEDGER_PRESENTATION.countingDetailsExpandedLabel