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.

refactor(recovery): normalize platform-first frontend models

rcourtman77712cda1f1d
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index 4dc1238f55..dbaba7a80c 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -694,6 +694,12 @@ Recovery frontend decode and derived option builders must treat payload
to legacy `provider` / `providers` aliases for compatibility, so route,
filter, and table state do not keep backend-era vocabulary alive as the
default client model.
+That normalization belongs at the shared recovery transport boundary in
+`frontend-modern/src/hooks/useRecoveryPoints.ts` and
+`frontend-modern/src/hooks/useRecoveryRollups.ts`, not in individual tables,
+drawers, or summary cards. Recovery components should receive canonical
+platform-first runtime models rather than re-deriving legacy alias fallback
+locally.
Recovery section owners under `frontend-modern/src/components/Recovery/` must
consume that shared `platform` filter surface directly. They must not keep
recovery-local `provider` route/query vocabulary alive behind renamed labels,
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index d4c979500c..bb6bd7eff8 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -403,6 +403,11 @@ implementation detail: `frontend-modern/src/hooks/useRecoveryPoints.ts`,
`frontend-modern/src/hooks/useRecoveryRollups.ts` must stay on the explicit
`recovery-product-surface` proof path instead of inheriting release-control
coverage only through `frontend-modern/src/pages/RecoveryRoute.tsx`.
+Those same hooks now also own recovery transport normalization at the frontend
+boundary: raw compatibility fields such as `provider` / `providers` may be
+accepted from older `/api/recovery/*` payloads, but the runtime values they
+return to the rest of the recovery UI must be canonical `platform` /
+`platforms` models.
That same rule applies to the dashboard recovery entry points too:
`frontend-modern/src/hooks/useDashboardRecovery.ts`,
`frontend-modern/src/pages/Dashboard.tsx`,
diff --git a/frontend-modern/src/components/Recovery/Recovery.tsx b/frontend-modern/src/components/Recovery/Recovery.tsx
index e2a66b27e1..bd56c77a6e 100644
--- a/frontend-modern/src/components/Recovery/Recovery.tsx
+++ b/frontend-modern/src/components/Recovery/Recovery.tsx
@@ -110,10 +110,10 @@ const Recovery: Component = () => {
const resourceIndex = resourcesById();
const result = rollups().filter((rollup) => {
- const providers = getRecoveryRollupPlatforms(rollup)
+ const platforms = getRecoveryRollupPlatforms(rollup)
.map((entry) => String(entry || '').trim())
.filter(Boolean);
- if (platform && !providers.includes(platform)) return false;
+ if (platform && !platforms.includes(platform)) return false;
const rollupItemType = normalizeRecoveryItemTypeQueryValue(
rollup.display?.itemType || rollup.display?.subjectType || rollup.subjectRef?.type,
);
@@ -128,7 +128,7 @@ const Recovery: Component = () => {
rollup.subjectRef?.type || '',
rollup.subjectRef?.namespace || '',
rollup.subjectRef?.name || '',
- providers.join(' '),
+ platforms.join(' '),
rollup.lastOutcome || '',
]
.filter(Boolean)
diff --git a/frontend-modern/src/components/Recovery/RecoveryHistoryTable.tsx b/frontend-modern/src/components/Recovery/RecoveryHistoryTable.tsx
index 959346c693..595afa955a 100644
--- a/frontend-modern/src/components/Recovery/RecoveryHistoryTable.tsx
+++ b/frontend-modern/src/components/Recovery/RecoveryHistoryTable.tsx
@@ -169,7 +169,7 @@ export const RecoveryHistoryTable: Component<RecoveryHistoryTableProps> = (props
? formatRecoveryTimeOnly(tsMs)
: '—';
const subjectType = getRecoverySubjectTypeLabel(point);
- const provider = normalizeSourcePlatformQueryValue(getRecoveryPointPlatform(point));
+ const platform = normalizeSourcePlatformQueryValue(getRecoveryPointPlatform(point));
const mode =
normalizeRecoveryModeQueryValue(String(point.mode || '').toLowerCase()) ||
'local';
@@ -294,13 +294,13 @@ export const RecoveryHistoryTable: Component<RecoveryHistoryTableProps> = (props
</TableCell>
);
case 'source': {
- const badge = getSourcePlatformBadge(provider);
+ const badge = getSourcePlatformBadge(platform);
return (
<TableCell class="whitespace-nowrap px-3 py-0.5 text-center">
<span
class={`${badge?.classes || ''} inline-flex min-w-[3.25rem] justify-center px-1.5 py-px text-[9px] font-medium`}
>
- {badge?.label || getSourcePlatformLabel(provider)}
+ {badge?.label || getSourcePlatformLabel(platform)}
</span>
</TableCell>
);
diff --git a/frontend-modern/src/components/Recovery/RecoveryPointDetails.tsx b/frontend-modern/src/components/Recovery/RecoveryPointDetails.tsx
index a38e5330fc..f062cf77ea 100644
--- a/frontend-modern/src/components/Recovery/RecoveryPointDetails.tsx
+++ b/frontend-modern/src/components/Recovery/RecoveryPointDetails.tsx
@@ -72,18 +72,16 @@ const usageBarColorClass = (usagePercent: number): string => {
export const RecoveryPointDetails: Component<RecoveryPointDetailsProps> = (props) => {
const { state } = useWebSocket();
const point = () => props.point;
- const providerKey = createMemo(() =>
+ const platformKey = createMemo(() =>
normalizeSourcePlatformQueryValue(getRecoveryPointPlatform(point())),
);
- const providerLabel = createMemo(() =>
- getSourcePlatformLabel(providerKey() || getRecoveryPointPlatform(point())),
+ const platformLabel = createMemo(() =>
+ getSourcePlatformLabel(platformKey() || getRecoveryPointPlatform(point())),
);
- const providerBadge = createMemo(() =>
- getSourcePlatformBadge(providerKey() || getRecoveryPointPlatform(point())),
- );
- const isPbsProvider = createMemo(
- () => providerKey() === 'proxmox-pbs',
+ const platformBadge = createMemo(() =>
+ getSourcePlatformBadge(platformKey() || getRecoveryPointPlatform(point())),
);
+ const isPbsProvider = createMemo(() => platformKey() === 'proxmox-pbs');
const pbsComment = createMemo(() => {
const value = point().details?.comment;
@@ -128,7 +126,7 @@ export const RecoveryPointDetails: Component<RecoveryPointDetailsProps> = (props
},
);
- const hasProviderDetails = createMemo(
+ const hasPlatformDetails = createMemo(
() =>
isPbsProvider() &&
(pbsComment().length > 0 ||
@@ -164,7 +162,7 @@ export const RecoveryPointDetails: Component<RecoveryPointDetailsProps> = (props
pairs.push({ k: 'ID', v: p.id });
if (itemType && itemType !== 'Unknown') pairs.push({ k: 'Item Type', v: itemType });
- pairs.push({ k: 'Platform', v: providerLabel() || 'n/a' });
+ pairs.push({ k: 'Platform', v: platformLabel() || 'n/a' });
for (const entry of getRecoveryPointLocationEntries(p)) {
pairs.push({ k: entry.label, v: entry.value });
}
@@ -277,7 +275,7 @@ export const RecoveryPointDetails: Component<RecoveryPointDetailsProps> = (props
</div>
</div>
- <Show when={hasProviderDetails()}>
+ <Show when={hasPlatformDetails()}>
<div class="rounded border border-border bg-surface p-3">
<div class="flex flex-wrap items-start justify-between gap-3">
<div>
@@ -288,7 +286,7 @@ export const RecoveryPointDetails: Component<RecoveryPointDetailsProps> = (props
Platform-specific recovery metadata, verification state, and target health.
</div>
</div>
- <Show when={providerBadge()}>
+ <Show when={platformBadge()}>
{(badge) => (
<span class={badge().classes} title={badge().title}>
{badge().label}
diff --git a/frontend-modern/src/components/Recovery/RecoveryProtectedInventorySection.tsx b/frontend-modern/src/components/Recovery/RecoveryProtectedInventorySection.tsx
index 3ed5420069..8eaef708d7 100644
--- a/frontend-modern/src/components/Recovery/RecoveryProtectedInventorySection.tsx
+++ b/frontend-modern/src/components/Recovery/RecoveryProtectedInventorySection.tsx
@@ -134,11 +134,11 @@ export const RecoveryProtectedInventorySection: Component<
}
case 'source': {
const leftSource = getRecoveryRollupPlatforms(left)
- .map((provider) => getSourcePlatformLabel(String(provider)))
+ .map((platform) => getSourcePlatformLabel(String(platform)))
.sort()
.join(',');
const rightSource = getRecoveryRollupPlatforms(right)
- .map((provider) => getSourcePlatformLabel(String(provider)))
+ .map((platform) => getSourcePlatformLabel(String(platform)))
.sort()
.join(',');
return multiplier * leftSource.localeCompare(rightSource);
@@ -369,8 +369,8 @@ export const RecoveryProtectedInventorySection: Component<
const attemptMs = rollup.lastAttemptAt ? Date.parse(rollup.lastAttemptAt) : 0;
const successMs = rollup.lastSuccessAt ? Date.parse(rollup.lastSuccessAt) : 0;
const outcome = normalizeRecoveryOutcome(rollup.lastOutcome);
- const providers = getRecoveryRollupPlatforms(rollup)
- .map((provider) => String(provider || '').trim())
+ const platforms = getRecoveryRollupPlatforms(rollup)
+ .map((platform) => String(platform || '').trim())
.filter(Boolean)
.sort((left, right) =>
getSourcePlatformLabel(left).localeCompare(getSourcePlatformLabel(right)),
@@ -437,12 +437,12 @@ export const RecoveryProtectedInventorySection: Component<
<TableCell class="hidden lg:table-cell whitespace-nowrap px-3 py-0.5">
<div class="flex flex-wrap gap-1.5">
- <For each={providers}>
- {(provider) => {
- const badge = getSourcePlatformBadge(provider);
+ <For each={platforms}>
+ {(platform) => {
+ const badge = getSourcePlatformBadge(platform);
return (
<span class={badge?.classes || ''}>
- {badge?.label || getSourcePlatformLabel(provider)}
+ {badge?.label || getSourcePlatformLabel(platform)}
</span>
);
}}
diff --git a/frontend-modern/src/components/Recovery/__tests__/Recovery.test.tsx b/frontend-modern/src/components/Recovery/__tests__/Recovery.test.tsx
index cbbdf3608e..712b677b0f 100644
--- a/frontend-modern/src/components/Recovery/__tests__/Recovery.test.tsx
+++ b/frontend-modern/src/components/Recovery/__tests__/Recovery.test.tsx
@@ -310,6 +310,43 @@ describe('Recovery', () => {
expect(screen.getByText('Platform Mix')).toBeInTheDocument();
});
+ it('normalizes legacy provider-shaped recovery payloads before rendering', async () => {
+ rollupsPayload.push({
+ rollupId: 'ext:legacy-provider-rollup',
+ subjectRef: { type: 'truenas-dataset', name: 'tank/legacy', id: 'tank/legacy' },
+ lastAttemptAt: '2026-02-12T08:00:00.000Z',
+ lastSuccessAt: '2026-02-12T08:00:00.000Z',
+ lastOutcome: 'success',
+ providers: ['truenas'],
+ });
+ pointsByRollupId['ext:legacy-provider-rollup'] = [
+ {
+ id: 'legacy-point',
+ provider: 'truenas',
+ kind: 'snapshot',
+ mode: 'snapshot',
+ outcome: 'success',
+ completedAt: '2026-02-12T08:00:00.000Z',
+ display: { itemType: 'dataset', subjectType: 'truenas-dataset' },
+ },
+ ];
+
+ try {
+ render(() => <Recovery />);
+
+ expect(await screen.findByText('tank/legacy')).toBeInTheDocument();
+ expect(screen.getAllByText('TrueNAS').length).toBeGreaterThan(0);
+
+ fireEvent.click(screen.getByText('tank/legacy'));
+
+ expect(await screen.findByText('Recovery Events')).toBeInTheDocument();
+ expect(screen.getAllByText('TrueNAS').length).toBeGreaterThan(0);
+ } finally {
+ rollupsPayload.pop();
+ delete pointsByRollupId['ext:legacy-provider-rollup'];
+ }
+ });
+
it('keeps recovery history width aligned with canonical column specs', async () => {
render(() => <Recovery />);
diff --git a/frontend-modern/src/features/recovery/useRecoverySurfaceState.ts b/frontend-modern/src/features/recovery/useRecoverySurfaceState.ts
index a38f12ca81..e4b325d299 100644
--- a/frontend-modern/src/features/recovery/useRecoverySurfaceState.ts
+++ b/frontend-modern/src/features/recovery/useRecoverySurfaceState.ts
@@ -331,8 +331,8 @@ export function useRecoverySurfaceState() {
const platformOptions = createMemo(() => {
const platforms = new Set<string>();
for (const rollup of rollups()) {
- for (const provider of getRecoveryRollupPlatforms(rollup)) {
- const normalized = normalizeSourcePlatformQueryValue(String(provider || '').trim());
+ for (const platform of getRecoveryRollupPlatforms(rollup)) {
+ const normalized = normalizeSourcePlatformQueryValue(String(platform || '').trim());
if (normalized) platforms.add(normalized);
}
}
diff --git a/frontend-modern/src/hooks/useRecoveryPoints.ts b/frontend-modern/src/hooks/useRecoveryPoints.ts
index d51f339741..7dfc8e9f98 100644
--- a/frontend-modern/src/hooks/useRecoveryPoints.ts
+++ b/frontend-modern/src/hooks/useRecoveryPoints.ts
@@ -1,6 +1,11 @@
import { Accessor, createMemo, createResource, onCleanup } from 'solid-js';
import { apiFetchJSON } from '@/utils/apiClient';
-import type { RecoveryPoint, RecoveryPointsResponse } from '@/types/recovery';
+import type {
+ RecoveryPoint,
+ RecoveryPointsResponse,
+ RecoveryPointsTransportResponse,
+} from '@/types/recovery';
+import { normalizeRecoveryPointsResponse } from '@/utils/recoveryPlatformModel';
const RECOVERY_POINTS_URL = '/api/recovery/points';
const DEFAULT_LIMIT = 200;
@@ -112,7 +117,8 @@ async function fetchRecoveryPointsResponse(
query: RecoveryPointsQuery | undefined,
): Promise<RecoveryPointsResponse> {
const url = buildURL(query);
- return apiFetchJSON<RecoveryPointsResponse>(url);
+ const response = await apiFetchJSON<RecoveryPointsTransportResponse>(url);
+ return normalizeRecoveryPointsResponse(response);
}
export function useRecoveryPoints(query?: Accessor<RecoveryPointsQuery | null | undefined>) {
diff --git a/frontend-modern/src/hooks/useRecoveryRollups.ts b/frontend-modern/src/hooks/useRecoveryRollups.ts
index 0bb7b8f616..e9e18850cf 100644
--- a/frontend-modern/src/hooks/useRecoveryRollups.ts
+++ b/frontend-modern/src/hooks/useRecoveryRollups.ts
@@ -1,6 +1,7 @@
import { createResource, onCleanup } from 'solid-js';
import { apiFetchJSON } from '@/utils/apiClient';
-import type { ProtectionRollup, RecoveryRollupsResponse } from '@/types/recovery';
+import type { ProtectionRollup, RecoveryRollupsTransportResponse } from '@/types/recovery';
+import { normalizeRecoveryRollupsResponse } from '@/utils/recoveryPlatformModel';
const RECOVERY_ROLLUPS_URL = '/api/recovery/rollups';
const PAGE_LIMIT = 500;
@@ -90,8 +91,9 @@ async function fetchRecoveryRollups(
for (let page = 1; page <= MAX_PAGES; page += 1) {
const url = buildURL(page, PAGE_LIMIT, query);
- const resp = await apiFetchJSON<RecoveryRollupsResponse>(url);
- rollups.push(...(resp?.data || []));
+ const response = await apiFetchJSON<RecoveryRollupsTransportResponse>(url);
+ const resp = normalizeRecoveryRollupsResponse(response);
+ rollups.push(...resp.data);
if (!resp?.meta || (resp.data || []).length < PAGE_LIMIT || page >= resp.meta.totalPages) {
break;
}
diff --git a/frontend-modern/src/types/recovery.ts b/frontend-modern/src/types/recovery.ts
index 9cf52c0a02..e4182575e1 100644
--- a/frontend-modern/src/types/recovery.ts
+++ b/frontend-modern/src/types/recovery.ts
@@ -1,5 +1,4 @@
export type RecoveryPlatform = string;
-export type RecoveryProvider = RecoveryPlatform;
export type RecoveryKind = 'snapshot' | 'backup' | 'other' | (string & {});
export type RecoveryMode = 'snapshot' | 'local' | 'remote' | (string & {});
export type RecoveryOutcome =
@@ -37,7 +36,6 @@ export interface RecoveryPointDisplay {
export interface RecoveryPoint {
id: string;
platform?: RecoveryPlatform;
- provider?: RecoveryProvider;
kind: RecoveryKind;
mode: RecoveryMode;
outcome: RecoveryOutcome;
@@ -65,14 +63,25 @@ export interface RecoveryPoint {
display?: RecoveryPointDisplay | null;
}
+export interface RecoveryPointTransport extends RecoveryPoint {
+ provider?: RecoveryPlatform;
+}
+
+export interface RecoveryResponseMeta {
+ page: number;
+ limit: number;
+ total: number;
+ totalPages: number;
+}
+
export interface RecoveryPointsResponse {
data: RecoveryPoint[];
- meta: {
- page: number;
- limit: number;
- total: number;
- totalPages: number;
- };
+ meta: RecoveryResponseMeta;
+}
+
+export interface RecoveryPointsTransportResponse {
+ data: RecoveryPointTransport[];
+ meta: RecoveryResponseMeta;
}
export interface ProtectionRollup {
@@ -86,17 +95,20 @@ export interface ProtectionRollup {
lastOutcome: RecoveryOutcome;
platforms?: RecoveryPlatform[];
- providers?: RecoveryProvider[];
+}
+
+export interface ProtectionRollupTransport extends ProtectionRollup {
+ providers?: RecoveryPlatform[];
}
export interface RecoveryRollupsResponse {
data: ProtectionRollup[];
- meta: {
- page: number;
- limit: number;
- total: number;
- totalPages: number;
- };
+ meta: RecoveryResponseMeta;
+}
+
+export interface RecoveryRollupsTransportResponse {
+ data: ProtectionRollupTransport[];
+ meta: RecoveryResponseMeta;
}
export interface RecoveryPointsSeriesBucket {
diff --git a/frontend-modern/src/utils/__tests__/recoveryEmptyStatePresentation.test.ts b/frontend-modern/src/utils/__tests__/recoveryEmptyStatePresentation.test.ts
index 0c0922d743..c3df56d063 100644
--- a/frontend-modern/src/utils/__tests__/recoveryEmptyStatePresentation.test.ts
+++ b/frontend-modern/src/utils/__tests__/recoveryEmptyStatePresentation.test.ts
@@ -48,7 +48,7 @@ describe('recoveryEmptyStatePresentation', () => {
it('returns the recovery-history filter empty state copy', () => {
expect(getRecoveryHistoryEmptyState()).toEqual({
title: 'No recovery history matches your filters',
- description: 'Adjust your search, provider, method, status, or verification filters.',
+ description: 'Adjust your search, platform, method, status, or verification filters.',
});
});
});
diff --git a/frontend-modern/src/utils/__tests__/recoveryPlatformModel.test.ts b/frontend-modern/src/utils/__tests__/recoveryPlatformModel.test.ts
index 18e6fd50fb..15265243dc 100644
--- a/frontend-modern/src/utils/__tests__/recoveryPlatformModel.test.ts
+++ b/frontend-modern/src/utils/__tests__/recoveryPlatformModel.test.ts
@@ -3,6 +3,10 @@ import { describe, expect, it } from 'vitest';
import {
getRecoveryPointPlatform,
getRecoveryRollupPlatforms,
+ normalizeRecoveryPoint,
+ normalizeRecoveryPointsResponse,
+ normalizeRecoveryRollup,
+ normalizeRecoveryRollupsResponse,
} from '@/utils/recoveryPlatformModel';
describe('recoveryPlatformModel', () => {
@@ -35,4 +39,84 @@ describe('recoveryPlatformModel', () => {
}),
).toEqual(['proxmox-pbs', 'kubernetes']);
});
+
+ it('normalizes legacy recovery transport records into canonical runtime models', () => {
+ expect(
+ normalizeRecoveryPoint({
+ id: 'point-1',
+ provider: 'proxmox-pbs',
+ kind: 'backup',
+ mode: 'remote',
+ outcome: 'success',
+ }),
+ ).toEqual({
+ id: 'point-1',
+ platform: 'proxmox-pbs',
+ kind: 'backup',
+ mode: 'remote',
+ outcome: 'success',
+ });
+
+ expect(
+ normalizeRecoveryRollup({
+ rollupId: 'rollup-1',
+ lastOutcome: 'success',
+ providers: ['proxmox-pbs', 'kubernetes'],
+ }),
+ ).toEqual({
+ rollupId: 'rollup-1',
+ lastOutcome: 'success',
+ platforms: ['proxmox-pbs', 'kubernetes'],
+ });
+ });
+
+ it('normalizes recovery transport responses to platform-first data', () => {
+ expect(
+ normalizeRecoveryPointsResponse({
+ data: [
+ {
+ id: 'point-1',
+ provider: 'truenas',
+ kind: 'snapshot',
+ mode: 'snapshot',
+ outcome: 'success',
+ },
+ ],
+ meta: { page: 1, limit: 100, total: 1, totalPages: 1 },
+ }),
+ ).toEqual({
+ data: [
+ {
+ id: 'point-1',
+ platform: 'truenas',
+ kind: 'snapshot',
+ mode: 'snapshot',
+ outcome: 'success',
+ },
+ ],
+ meta: { page: 1, limit: 100, total: 1, totalPages: 1 },
+ });
+
+ expect(
+ normalizeRecoveryRollupsResponse({
+ data: [
+ {
+ rollupId: 'rollup-1',
+ lastOutcome: 'warning',
+ providers: ['truenas'],
+ },
+ ],
+ meta: { page: 1, limit: 100, total: 1, totalPages: 1 },
+ }),
+ ).toEqual({
+ data: [
+ {
+ rollupId: 'rollup-1',
+ lastOutcome: 'warning',
+ platforms: ['truenas'],
+ },
+ ],
+ meta: { page: 1, limit: 100, total: 1, totalPages: 1 },
+ });
+ });
});
diff --git a/frontend-modern/src/utils/recoveryEmptyStatePresentation.ts b/frontend-modern/src/utils/recoveryEmptyStatePresentation.ts
index f96eb1f81e..6fb7b13955 100644
--- a/frontend-modern/src/utils/recoveryEmptyStatePresentation.ts
+++ b/frontend-modern/src/utils/recoveryEmptyStatePresentation.ts
@@ -32,7 +32,7 @@ export function getRecoveryActivityEmptyState() {
export function getRecoveryHistoryEmptyState() {
return {
title: 'No recovery history matches your filters',
- description: 'Adjust your search, provider, method, status, or verification filters.',
+ description: 'Adjust your search, platform, method, status, or verification filters.',
} as const;
}
diff --git a/frontend-modern/src/utils/recoveryPlatformModel.ts b/frontend-modern/src/utils/recoveryPlatformModel.ts
index 578fb41eb6..7161a95002 100644
--- a/frontend-modern/src/utils/recoveryPlatformModel.ts
+++ b/frontend-modern/src/utils/recoveryPlatformModel.ts
@@ -1,14 +1,34 @@
-import type { ProtectionRollup, RecoveryPoint } from '@/types/recovery';
+import type {
+ ProtectionRollup,
+ ProtectionRollupTransport,
+ RecoveryPoint,
+ RecoveryPointsResponse,
+ RecoveryPointsTransportResponse,
+ RecoveryPointTransport,
+ RecoveryResponseMeta,
+ RecoveryRollupsResponse,
+ RecoveryRollupsTransportResponse,
+} from '@/types/recovery';
const toTrimmedString = (value: unknown): string =>
typeof value === 'string' ? value.trim() : '';
+interface RecoveryPointPlatformLike {
+ platform?: string | null;
+ provider?: string | null;
+}
+
+interface RecoveryRollupPlatformsLike {
+ platforms?: string[] | null;
+ providers?: string[] | null;
+}
+
export const getRecoveryPointPlatform = (
- point: Pick<RecoveryPoint, 'platform' | 'provider'> | null | undefined,
+ point: RecoveryPointPlatformLike | null | undefined,
): string => toTrimmedString(point?.platform) || toTrimmedString(point?.provider);
export const getRecoveryRollupPlatforms = (
- rollup: Pick<ProtectionRollup, 'platforms' | 'providers'> | null | undefined,
+ rollup: RecoveryRollupPlatformsLike | null | undefined,
): string[] => {
const values =
Array.isArray(rollup?.platforms) && rollup.platforms.length > 0
@@ -17,3 +37,40 @@ export const getRecoveryRollupPlatforms = (
return values.map((value) => toTrimmedString(value)).filter(Boolean);
};
+
+const normalizeRecoveryMeta = (meta: RecoveryResponseMeta | null | undefined): RecoveryResponseMeta => ({
+ page: Number.isFinite(meta?.page) ? meta.page : 1,
+ limit: Number.isFinite(meta?.limit) ? meta.limit : 0,
+ total: Number.isFinite(meta?.total) ? meta.total : 0,
+ totalPages: Number.isFinite(meta?.totalPages) ? meta.totalPages : 1,
+});
+
+export const normalizeRecoveryPoint = (
+ point: RecoveryPointTransport | RecoveryPoint,
+): RecoveryPoint => {
+ const { provider: _provider, ...rest } = point as RecoveryPointTransport;
+ const platform = getRecoveryPointPlatform(point);
+ return platform ? { ...rest, platform } : (rest as RecoveryPoint);
+};
+
+export const normalizeRecoveryRollup = (
+ rollup: ProtectionRollupTransport | ProtectionRollup,
+): ProtectionRollup => {
+ const { providers: _providers, ...rest } = rollup as ProtectionRollupTransport;
+ const platforms = getRecoveryRollupPlatforms(rollup);
+ return platforms.length > 0 ? { ...rest, platforms } : (rest as ProtectionRollup);
+};
+
+export const normalizeRecoveryPointsResponse = (
+ response: RecoveryPointsTransportResponse,
+): RecoveryPointsResponse => ({
+ data: Array.isArray(response?.data) ? response.data.map(normalizeRecoveryPoint) : [],
+ meta: normalizeRecoveryMeta(response?.meta),
+});
+
+export const normalizeRecoveryRollupsResponse = (
+ response: RecoveryRollupsTransportResponse,
+): RecoveryRollupsResponse => ({
+ data: Array.isArray(response?.data) ? response.data.map(normalizeRecoveryRollup) : [],
+ meta: normalizeRecoveryMeta(response?.meta),
+});
diff --git a/frontend-modern/src/utils/recoverySummaryPresentation.ts b/frontend-modern/src/utils/recoverySummaryPresentation.ts
index 9daa2aecf5..f6421293a5 100644
--- a/frontend-modern/src/utils/recoverySummaryPresentation.ts
+++ b/frontend-modern/src/utils/recoverySummaryPresentation.ts
@@ -384,18 +384,18 @@ export function buildRecoveryPlatformCoverage(
let multiPlatformCount = 0;
for (const rollup of rollups) {
- const providers = Array.from(
+ const platforms = Array.from(
new Set(
getRecoveryRollupPlatforms(rollup)
- .map((provider) => normalizeSourcePlatformQueryValue(String(provider || '').trim()))
+ .map((platform) => normalizeSourcePlatformQueryValue(String(platform || '').trim()))
.filter(Boolean),
),
);
- const resolvedProviders = providers.length > 0 ? providers : ['generic'];
- if (resolvedProviders.length > 1) multiPlatformCount += 1;
+ const resolvedPlatforms = platforms.length > 0 ? platforms : ['generic'];
+ if (resolvedPlatforms.length > 1) multiPlatformCount += 1;
- for (const provider of resolvedProviders) {
- counts.set(provider, (counts.get(provider) || 0) + 1);
+ for (const platform of resolvedPlatforms) {
+ counts.set(platform, (counts.get(platform) || 0) + 1);
}
}