@openshift-migration-advisor/shared-components 0.24.0 → 0.25.0-1c27267d2ea6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/dist/charts/index.d.ts +1 -1
- package/dist/charts/index.d.ts.map +1 -1
- package/dist/forms/RadioButtonFormGroup.d.ts.map +1 -1
- package/dist/forms/RadioButtonFormGroup.js +2 -2
- package/dist/report/ChartDownloadButton.d.ts +11 -0
- package/dist/report/ChartDownloadButton.d.ts.map +1 -0
- package/dist/report/ChartDownloadButton.js +24 -0
- package/dist/report/ChartExportProvider.d.ts +22 -0
- package/dist/report/ChartExportProvider.d.ts.map +1 -0
- package/dist/report/ChartExportProvider.js +222 -0
- package/dist/report/ChartExportSurface.d.ts +12 -0
- package/dist/report/ChartExportSurface.d.ts.map +1 -0
- package/dist/report/ChartExportSurface.js +32 -0
- package/dist/report/ErrorTable.d.ts +18 -0
- package/dist/report/ErrorTable.d.ts.map +1 -0
- package/dist/report/ErrorTable.js +20 -0
- package/dist/report/FeatureStatusBadge.d.ts +7 -0
- package/dist/report/FeatureStatusBadge.d.ts.map +1 -0
- package/dist/report/FeatureStatusBadge.js +13 -0
- package/dist/report/HostPowerStates.d.ts +8 -0
- package/dist/report/HostPowerStates.d.ts.map +1 -0
- package/dist/report/HostPowerStates.js +11 -0
- package/dist/report/InfrastructureSummary.d.ts +7 -0
- package/dist/report/InfrastructureSummary.d.ts.map +1 -0
- package/dist/report/InfrastructureSummary.js +9 -0
- package/dist/report/NetworkOverview.d.ts +31 -0
- package/dist/report/NetworkOverview.d.ts.map +1 -0
- package/dist/report/NetworkOverview.js +201 -0
- package/dist/report/OSDistribution.d.ts +0 -2
- package/dist/report/OSDistribution.d.ts.map +1 -1
- package/dist/report/OSDistribution.js +10 -15
- package/dist/report/OsSupportTiersHelpPopover.d.ts.map +1 -1
- package/dist/report/OsSupportTiersHelpPopover.js +2 -31
- package/dist/report/OsUpgradeNotice.d.ts.map +1 -1
- package/dist/report/OsUpgradeNotice.js +1 -5
- package/dist/report/OsUpgradeRecommendationPopover.d.ts +0 -1
- package/dist/report/OsUpgradeRecommendationPopover.d.ts.map +1 -1
- package/dist/report/OsUpgradeRecommendationPopover.js +4 -3
- package/dist/report/PowerStateCard.d.ts +16 -0
- package/dist/report/PowerStateCard.d.ts.map +1 -0
- package/dist/report/PowerStateCard.js +9 -0
- package/dist/report/ReportExportMenu.d.ts +19 -0
- package/dist/report/ReportExportMenu.d.ts.map +1 -0
- package/dist/report/ReportExportMenu.js +31 -0
- package/dist/report/ReportTable.d.ts +14 -0
- package/dist/report/ReportTable.d.ts.map +1 -0
- package/dist/report/ReportTable.js +23 -0
- package/dist/report/SupportTierBadge.d.ts +0 -1
- package/dist/report/SupportTierBadge.d.ts.map +1 -1
- package/dist/report/SupportTierBadge.js +1 -19
- package/dist/report/VCenterClusterDetails.d.ts +9 -0
- package/dist/report/VCenterClusterDetails.d.ts.map +1 -0
- package/dist/report/VCenterClusterDetails.js +31 -0
- package/dist/report/VmPowerStates.d.ts +8 -0
- package/dist/report/VmPowerStates.d.ts.map +1 -0
- package/dist/report/VmPowerStates.js +11 -0
- package/dist/report/captureChartElement.d.ts +8 -0
- package/dist/report/captureChartElement.d.ts.map +1 -0
- package/dist/report/captureChartElement.js +284 -0
- package/dist/report/chartExport.d.ts +57 -0
- package/dist/report/chartExport.d.ts.map +1 -0
- package/dist/report/chartExport.js +162 -0
- package/dist/report/chartExportContext.d.ts +28 -0
- package/dist/report/chartExportContext.d.ts.map +1 -0
- package/dist/report/chartExportContext.js +36 -0
- package/dist/report/chartExportFilenames.d.ts +4 -0
- package/dist/report/chartExportFilenames.d.ts.map +1 -0
- package/dist/report/chartExportFilenames.js +16 -0
- package/dist/report/constants.d.ts +3 -0
- package/dist/report/constants.d.ts.map +1 -1
- package/dist/report/constants.js +3 -0
- package/dist/report/dashboardStyles.d.ts +0 -4
- package/dist/report/dashboardStyles.d.ts.map +1 -1
- package/dist/report/dashboardStyles.js +0 -19
- package/dist/report/htmlExport.d.ts +9 -0
- package/dist/report/htmlExport.d.ts.map +1 -0
- package/dist/report/htmlExport.js +65 -0
- package/dist/report/index.d.ts +26 -0
- package/dist/report/index.d.ts.map +1 -1
- package/dist/report/index.js +24 -0
- package/dist/report/infrastructureSummaryModel.d.ts +82 -0
- package/dist/report/infrastructureSummaryModel.d.ts.map +1 -0
- package/dist/report/infrastructureSummaryModel.js +139 -0
- package/dist/report/pdfExport.d.ts +3 -0
- package/dist/report/pdfExport.d.ts.map +1 -0
- package/dist/report/pdfExport.js +82 -0
- package/dist/report/pdfPage.d.ts +15 -0
- package/dist/report/pdfPage.d.ts.map +1 -0
- package/dist/report/pdfPage.js +44 -0
- package/dist/report/powerStates.d.ts +11 -0
- package/dist/report/powerStates.d.ts.map +1 -0
- package/dist/report/powerStates.js +113 -0
- package/dist/report/reportExportOptions.d.ts +17 -0
- package/dist/report/reportExportOptions.d.ts.map +1 -0
- package/dist/report/reportExportOptions.js +31 -0
- package/dist/report/zipChartPngs.d.ts +3 -0
- package/dist/report/zipChartPngs.d.ts.map +1 -0
- package/dist/report/zipChartPngs.js +8 -0
- package/package.json +7 -2
- package/src/charts/index.ts +1 -0
- package/src/forms/RadioButtonFormGroup.tsx +10 -3
- package/src/report/ChartDownloadButton.tsx +59 -0
- package/src/report/ChartExportProvider.tsx +384 -0
- package/src/report/ChartExportSurface.tsx +60 -0
- package/src/report/ErrorTable.tsx +85 -0
- package/src/report/FeatureStatusBadge.tsx +30 -0
- package/src/report/HostPowerStates.tsx +38 -0
- package/src/report/InfrastructureSummary.tsx +73 -0
- package/src/report/NetworkOverview.tsx +405 -0
- package/src/report/OSDistribution.tsx +96 -99
- package/src/report/OsSupportTiersHelpPopover.tsx +32 -62
- package/src/report/OsUpgradeNotice.tsx +1 -7
- package/src/report/OsUpgradeRecommendationPopover.tsx +3 -4
- package/src/report/PowerStateCard.tsx +86 -0
- package/src/report/ReportExportMenu.tsx +119 -0
- package/src/report/ReportTable.tsx +81 -0
- package/src/report/SupportTierBadge.tsx +12 -38
- package/src/report/VCenterClusterDetails.tsx +233 -0
- package/src/report/VmPowerStates.tsx +38 -0
- package/src/report/__tests__/ChartExportProvider.test.tsx +474 -0
- package/src/report/__tests__/HostPowerStates.test.tsx +47 -0
- package/src/report/__tests__/InfrastructureSummary.test.tsx +126 -0
- package/src/report/__tests__/NetworkOverview.test.tsx +269 -0
- package/src/report/__tests__/OSDistribution.test.tsx +10 -11
- package/src/report/__tests__/captureChartElement.test.ts +132 -0
- package/src/report/__tests__/chartExportPackagers.test.ts +224 -0
- package/src/report/__tests__/infrastructureSummaryModel.test.ts +224 -0
- package/src/report/__tests__/powerStates.test.ts +70 -0
- package/src/report/captureChartElement.ts +368 -0
- package/src/report/chartExport.ts +237 -0
- package/src/report/chartExportContext.tsx +84 -0
- package/src/report/chartExportFilenames.ts +21 -0
- package/src/report/constants.ts +3 -0
- package/src/report/dashboardStyles.ts +0 -23
- package/src/report/htmlExport.ts +83 -0
- package/src/report/index.ts +142 -0
- package/src/report/infrastructureSummaryModel.ts +281 -0
- package/src/report/pdfExport.ts +154 -0
- package/src/report/pdfPage.ts +83 -0
- package/src/report/powerStates.ts +169 -0
- package/src/report/reportExportOptions.ts +53 -0
- package/src/report/zipChartPngs.ts +10 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
|
|
3
|
+
export const CHART_EXPORT_HIDE_ATTR = "data-chart-export-hide";
|
|
4
|
+
export const CHART_EXPORT_SCROLL_ATTR = "data-chart-export-scroll";
|
|
5
|
+
export const CHART_EXPORT_CAPTURING_ATTR = "data-chart-capturing";
|
|
6
|
+
|
|
7
|
+
export const chartExportHideProps = {
|
|
8
|
+
[CHART_EXPORT_HIDE_ATTR]: "",
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
export const chartExportScrollProps = {
|
|
12
|
+
[CHART_EXPORT_SCROLL_ATTR]: "",
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
export const chartExportRootStyle: CSSProperties = {
|
|
16
|
+
width: "100%",
|
|
17
|
+
height: "100%",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type ChartExportMeta = {
|
|
21
|
+
id: string;
|
|
22
|
+
title: string;
|
|
23
|
+
filename?: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type ChartExportView = {
|
|
27
|
+
id: string;
|
|
28
|
+
title: string;
|
|
29
|
+
filename?: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type RegisteredChart = {
|
|
33
|
+
id: string;
|
|
34
|
+
title: string;
|
|
35
|
+
filename: string;
|
|
36
|
+
element: HTMLElement;
|
|
37
|
+
exportViews?: ChartExportView[];
|
|
38
|
+
activeExportViewId?: string;
|
|
39
|
+
setExportView?: (viewId: string) => Promise<void>;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type ChartExportFile = {
|
|
43
|
+
filename: string;
|
|
44
|
+
blob: Blob;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type ChartCaptureSource = {
|
|
48
|
+
id: string;
|
|
49
|
+
title: string;
|
|
50
|
+
filename: string;
|
|
51
|
+
capture: () => Promise<HTMLCanvasElement>;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export function releaseCanvas(canvas: HTMLCanvasElement): void {
|
|
55
|
+
canvas.width = 0;
|
|
56
|
+
canvas.height = 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function waitForChartExportPaint(): Promise<void> {
|
|
60
|
+
if (typeof requestAnimationFrame !== "function") {
|
|
61
|
+
return Promise.resolve();
|
|
62
|
+
}
|
|
63
|
+
return new Promise((resolve) => {
|
|
64
|
+
requestAnimationFrame(() => {
|
|
65
|
+
requestAnimationFrame(() => resolve());
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function chartExportViewsFromLabels(
|
|
71
|
+
titlePrefix: string,
|
|
72
|
+
labels: Record<string, string>,
|
|
73
|
+
): ChartExportView[] {
|
|
74
|
+
return Object.entries(labels).map(([id, label]) => ({
|
|
75
|
+
id,
|
|
76
|
+
title: `${titlePrefix} — ${label}`,
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function shouldCycleExportViews(chart: RegisteredChart): boolean {
|
|
81
|
+
return Boolean(
|
|
82
|
+
chart.exportViews && chart.exportViews.length > 1 && chart.setExportView,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function bulkExportViews(chart: RegisteredChart): ChartExportView[] {
|
|
87
|
+
if (shouldCycleExportViews(chart) && chart.exportViews) {
|
|
88
|
+
return chart.exportViews;
|
|
89
|
+
}
|
|
90
|
+
return [
|
|
91
|
+
{
|
|
92
|
+
id: chart.id,
|
|
93
|
+
title: chart.title,
|
|
94
|
+
filename: chart.filename,
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function toBulkChartCaptureSources(
|
|
100
|
+
charts: RegisteredChart[],
|
|
101
|
+
capture: (element: HTMLElement) => Promise<HTMLCanvasElement>,
|
|
102
|
+
prepareElement?: (element: HTMLElement) => () => void,
|
|
103
|
+
): ChartCaptureSource[] {
|
|
104
|
+
return charts.flatMap((chart) => {
|
|
105
|
+
const views = bulkExportViews(chart);
|
|
106
|
+
const cyclesViews = shouldCycleExportViews(chart);
|
|
107
|
+
return views.map((view) => ({
|
|
108
|
+
id: cyclesViews ? `${chart.id}--${view.id}` : chart.id,
|
|
109
|
+
title: view.title,
|
|
110
|
+
filename:
|
|
111
|
+
view.filename ??
|
|
112
|
+
(cyclesViews
|
|
113
|
+
? chartPngFilename(view.title, `${chart.id}-${view.id}`)
|
|
114
|
+
: chart.filename),
|
|
115
|
+
capture: async () => {
|
|
116
|
+
const restore = prepareElement?.(chart.element);
|
|
117
|
+
try {
|
|
118
|
+
if (cyclesViews && chart.setExportView) {
|
|
119
|
+
await chart.setExportView(view.id);
|
|
120
|
+
}
|
|
121
|
+
return await capture(chart.element);
|
|
122
|
+
} finally {
|
|
123
|
+
restore?.();
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
}));
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export async function restoreChartExportViews(
|
|
131
|
+
charts: RegisteredChart[],
|
|
132
|
+
): Promise<void> {
|
|
133
|
+
for (const chart of charts) {
|
|
134
|
+
if (
|
|
135
|
+
shouldCycleExportViews(chart) &&
|
|
136
|
+
chart.setExportView &&
|
|
137
|
+
chart.activeExportViewId
|
|
138
|
+
) {
|
|
139
|
+
try {
|
|
140
|
+
await chart.setExportView(chart.activeExportViewId);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.error("Failed to restore the selected chart view:", error);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function sortRegisteredChartsByDocumentOrder(
|
|
149
|
+
charts: RegisteredChart[],
|
|
150
|
+
): RegisteredChart[] {
|
|
151
|
+
return [...charts].sort((left, right) => {
|
|
152
|
+
if (left.element === right.element) {
|
|
153
|
+
return 0;
|
|
154
|
+
}
|
|
155
|
+
const position = left.element.compareDocumentPosition(right.element);
|
|
156
|
+
if (position & Node.DOCUMENT_POSITION_FOLLOWING) {
|
|
157
|
+
return -1;
|
|
158
|
+
}
|
|
159
|
+
if (position & Node.DOCUMENT_POSITION_PRECEDING) {
|
|
160
|
+
return 1;
|
|
161
|
+
}
|
|
162
|
+
return 0;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function canvasToBlob(canvas: HTMLCanvasElement): Promise<Blob> {
|
|
167
|
+
return new Promise((resolve, reject) => {
|
|
168
|
+
if (canvas.width < 1 || canvas.height < 1) {
|
|
169
|
+
reject(new Error("Failed to encode canvas as PNG"));
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
canvas.toBlob((blob) => {
|
|
173
|
+
if (blob) {
|
|
174
|
+
resolve(blob);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
reject(new Error("Failed to encode canvas as PNG"));
|
|
178
|
+
}, "image/png");
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function slugifyExportName(value: string): string {
|
|
183
|
+
const slug = value
|
|
184
|
+
.toLowerCase()
|
|
185
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
186
|
+
.replace(/^-|-$/g, "");
|
|
187
|
+
return slug || "chart";
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function chartPngFilename(title: string, id = "chart"): string {
|
|
191
|
+
return `${slugifyExportName(title) || slugifyExportName(id)}.png`;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const KEEP_TAGS = new Set(["HTML", "HEAD", "BODY", "STYLE", "LINK"]);
|
|
195
|
+
|
|
196
|
+
function isHiddenForChartExport(node: Element): boolean {
|
|
197
|
+
return (
|
|
198
|
+
node.hasAttribute(CHART_EXPORT_HIDE_ATTR) ||
|
|
199
|
+
Boolean(node.closest(`[${CHART_EXPORT_HIDE_ATTR}]`))
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* html2canvas clones the whole document for every capture. Ignore everything
|
|
205
|
+
* except the target card (and ancestors / stylesheet nodes) so zip-all does
|
|
206
|
+
* not re-render every other chart.
|
|
207
|
+
*/
|
|
208
|
+
export function shouldIgnoreChartExportElement(
|
|
209
|
+
node: Element,
|
|
210
|
+
captureRoot?: Element | null,
|
|
211
|
+
): boolean {
|
|
212
|
+
if (!captureRoot) {
|
|
213
|
+
return isHiddenForChartExport(node);
|
|
214
|
+
}
|
|
215
|
+
if (KEEP_TAGS.has(node.tagName)) {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
if (
|
|
219
|
+
node !== captureRoot &&
|
|
220
|
+
!captureRoot.contains(node) &&
|
|
221
|
+
!node.contains(captureRoot)
|
|
222
|
+
) {
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
return isHiddenForChartExport(node);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function downloadBlob(blob: Blob, filename: string): void {
|
|
229
|
+
const url = URL.createObjectURL(blob);
|
|
230
|
+
const link = document.createElement("a");
|
|
231
|
+
link.href = url;
|
|
232
|
+
link.download = filename;
|
|
233
|
+
document.body.appendChild(link);
|
|
234
|
+
link.click();
|
|
235
|
+
document.body.removeChild(link);
|
|
236
|
+
URL.revokeObjectURL(url);
|
|
237
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
type RefCallback,
|
|
4
|
+
useContext,
|
|
5
|
+
useEffect,
|
|
6
|
+
useState,
|
|
7
|
+
} from "react";
|
|
8
|
+
import {
|
|
9
|
+
type ChartExportMeta,
|
|
10
|
+
type ChartExportView,
|
|
11
|
+
chartPngFilename,
|
|
12
|
+
type RegisteredChart,
|
|
13
|
+
} from "./chartExport.js";
|
|
14
|
+
|
|
15
|
+
export type ChartExportFormat = "pdf" | "png" | "html";
|
|
16
|
+
|
|
17
|
+
export type ChartExportApi = {
|
|
18
|
+
downloadChart: (id: string) => Promise<void>;
|
|
19
|
+
downloadAll: () => Promise<void>;
|
|
20
|
+
downloadPdf: (documentTitle: string) => Promise<void>;
|
|
21
|
+
downloadHtml: (documentTitle: string) => Promise<void>;
|
|
22
|
+
downloadingChartId: string | null;
|
|
23
|
+
exportingFormat: ChartExportFormat | null;
|
|
24
|
+
exportLoadingLabel: string | null;
|
|
25
|
+
isExportingAll: boolean;
|
|
26
|
+
isBusy: boolean;
|
|
27
|
+
exportError: string | null;
|
|
28
|
+
clearExportError: () => void;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type ChartExportRegistry = {
|
|
32
|
+
register: (chart: RegisteredChart) => () => void;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const ChartExportRegistryContext =
|
|
36
|
+
createContext<ChartExportRegistry | null>(null);
|
|
37
|
+
export const ChartExportApiContext = createContext<ChartExportApi | null>(null);
|
|
38
|
+
|
|
39
|
+
export function useChartExport(): ChartExportApi | null {
|
|
40
|
+
return useContext(ChartExportApiContext);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function useRegisterChart({
|
|
44
|
+
id,
|
|
45
|
+
title,
|
|
46
|
+
filename,
|
|
47
|
+
exportViews,
|
|
48
|
+
activeExportViewId,
|
|
49
|
+
setExportView,
|
|
50
|
+
}: ChartExportMeta & {
|
|
51
|
+
exportViews?: ChartExportView[];
|
|
52
|
+
activeExportViewId?: string;
|
|
53
|
+
setExportView?: (viewId: string) => Promise<void>;
|
|
54
|
+
}): RefCallback<HTMLElement> {
|
|
55
|
+
const registry = useContext(ChartExportRegistryContext);
|
|
56
|
+
const [element, setElement] = useState<HTMLElement | null>(null);
|
|
57
|
+
const resolvedFilename = filename ?? chartPngFilename(title, id);
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (!registry || !element) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
return registry.register({
|
|
64
|
+
id,
|
|
65
|
+
title,
|
|
66
|
+
filename: resolvedFilename,
|
|
67
|
+
element,
|
|
68
|
+
exportViews,
|
|
69
|
+
activeExportViewId,
|
|
70
|
+
setExportView,
|
|
71
|
+
});
|
|
72
|
+
}, [
|
|
73
|
+
activeExportViewId,
|
|
74
|
+
element,
|
|
75
|
+
exportViews,
|
|
76
|
+
id,
|
|
77
|
+
registry,
|
|
78
|
+
resolvedFilename,
|
|
79
|
+
setExportView,
|
|
80
|
+
title,
|
|
81
|
+
]);
|
|
82
|
+
|
|
83
|
+
return setElement;
|
|
84
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function getDatedChartExportBasename(date = new Date()): string {
|
|
2
|
+
const year = date.getFullYear();
|
|
3
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
4
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
5
|
+
return `migration-export-${year}-${month}-${day}`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getChartExportFilename(
|
|
9
|
+
format: "pdf" | "html" | "zip",
|
|
10
|
+
date = new Date(),
|
|
11
|
+
): string {
|
|
12
|
+
const base = getDatedChartExportBasename(date);
|
|
13
|
+
if (format === "zip") {
|
|
14
|
+
return `${base}-charts.zip`;
|
|
15
|
+
}
|
|
16
|
+
return `${base}.${format}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getChartZipFilename(date = new Date()): string {
|
|
20
|
+
return getChartExportFilename("zip", date);
|
|
21
|
+
}
|
package/src/report/constants.ts
CHANGED
|
@@ -25,4 +25,7 @@ export const REPORT_CARD_EMPTY_STATE_TITLES = {
|
|
|
25
25
|
operatingSystems: "Operating system data not collected",
|
|
26
26
|
migrationStatus: "Migration status data not collected",
|
|
27
27
|
issuesBreakdown: "Issues breakdown data not collected",
|
|
28
|
+
errors: "Error data not collected",
|
|
29
|
+
hostPowerStates: "Host power state data not collected",
|
|
30
|
+
vmPowerStates: "VM power state data not collected",
|
|
28
31
|
} as const;
|
|
@@ -47,23 +47,10 @@ export const dashboardStyles = {
|
|
|
47
47
|
overflow: hidden !important;
|
|
48
48
|
`,
|
|
49
49
|
|
|
50
|
-
cardPrint: css`
|
|
51
|
-
border: 1px solid #d2d2d2 !important;
|
|
52
|
-
border-radius: 10px;
|
|
53
|
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
|
54
|
-
min-height: unset;
|
|
55
|
-
max-height: unset;
|
|
56
|
-
page-break-inside: avoid;
|
|
57
|
-
`,
|
|
58
|
-
|
|
59
50
|
storageCardOverflowHidden: css`
|
|
60
51
|
overflow: hidden;
|
|
61
52
|
`,
|
|
62
53
|
|
|
63
|
-
storageCardOverflowVisible: css`
|
|
64
|
-
overflow: visible;
|
|
65
|
-
`,
|
|
66
|
-
|
|
67
54
|
storageChartWrapper: css`
|
|
68
55
|
display: flex;
|
|
69
56
|
justify-content: center;
|
|
@@ -72,16 +59,6 @@ export const dashboardStyles = {
|
|
|
72
59
|
padding: 20px 0;
|
|
73
60
|
`,
|
|
74
61
|
|
|
75
|
-
storageExportSectionMargin: css`
|
|
76
|
-
margin-bottom: 24px;
|
|
77
|
-
`,
|
|
78
|
-
|
|
79
|
-
storageExportSectionTitle: css`
|
|
80
|
-
font-size: 14px;
|
|
81
|
-
font-weight: 600;
|
|
82
|
-
margin-bottom: 12px;
|
|
83
|
-
`,
|
|
84
|
-
|
|
85
62
|
storageFlexFullWidth: css`
|
|
86
63
|
width: 100%;
|
|
87
64
|
`,
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type ChartCaptureSource, releaseCanvas } from "./chartExport.js";
|
|
2
|
+
|
|
3
|
+
export interface HtmlReportImage {
|
|
4
|
+
name: string;
|
|
5
|
+
dataUrl: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function escapeHtml(value: string): string {
|
|
9
|
+
return value
|
|
10
|
+
.replace(/&/g, "&")
|
|
11
|
+
.replace(/</g, "<")
|
|
12
|
+
.replace(/>/g, ">")
|
|
13
|
+
.replace(/"/g, """)
|
|
14
|
+
.replace(/'/g, "'");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function buildHtmlReport(
|
|
18
|
+
documentTitle: string,
|
|
19
|
+
images: HtmlReportImage[],
|
|
20
|
+
generatedAt = new Date(),
|
|
21
|
+
): string {
|
|
22
|
+
const sections = images
|
|
23
|
+
.map(
|
|
24
|
+
(image) => `
|
|
25
|
+
<section>
|
|
26
|
+
<h2>${escapeHtml(image.name)}</h2>
|
|
27
|
+
<img src="${image.dataUrl}" alt="${escapeHtml(image.name)}" />
|
|
28
|
+
</section>`,
|
|
29
|
+
)
|
|
30
|
+
.join("\n");
|
|
31
|
+
|
|
32
|
+
return `<!DOCTYPE html>
|
|
33
|
+
<html lang="en">
|
|
34
|
+
<head>
|
|
35
|
+
<meta charset="utf-8" />
|
|
36
|
+
<title>${escapeHtml(documentTitle)}</title>
|
|
37
|
+
<style>
|
|
38
|
+
body {
|
|
39
|
+
font-family: RedHatText, Helvetica, Arial, sans-serif;
|
|
40
|
+
margin: 32px auto;
|
|
41
|
+
max-width: 1100px;
|
|
42
|
+
background: #fff;
|
|
43
|
+
color: #151515;
|
|
44
|
+
}
|
|
45
|
+
h1 { font-size: 28px; margin-bottom: 8px; }
|
|
46
|
+
h2 { font-size: 18px; margin: 32px 0 12px; }
|
|
47
|
+
.meta { color: #6a6e73; margin-bottom: 24px; }
|
|
48
|
+
img {
|
|
49
|
+
width: 100%;
|
|
50
|
+
height: auto;
|
|
51
|
+
}
|
|
52
|
+
</style>
|
|
53
|
+
</head>
|
|
54
|
+
<body>
|
|
55
|
+
<h1>${escapeHtml(documentTitle)}</h1>
|
|
56
|
+
<p class="meta">Generated ${escapeHtml(generatedAt.toLocaleString())}</p>
|
|
57
|
+
${sections}
|
|
58
|
+
</body>
|
|
59
|
+
</html>
|
|
60
|
+
`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function buildHtmlFromCharts(
|
|
64
|
+
charts: ChartCaptureSource[],
|
|
65
|
+
documentTitle: string,
|
|
66
|
+
): Promise<Blob> {
|
|
67
|
+
const images: HtmlReportImage[] = [];
|
|
68
|
+
for (const chart of charts) {
|
|
69
|
+
const canvas = await chart.capture();
|
|
70
|
+
try {
|
|
71
|
+
images.push({
|
|
72
|
+
name: chart.title,
|
|
73
|
+
dataUrl: canvas.toDataURL("image/png"),
|
|
74
|
+
});
|
|
75
|
+
} finally {
|
|
76
|
+
releaseCanvas(canvas);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return new Blob([buildHtmlReport(documentTitle, images)], {
|
|
81
|
+
type: "text/html;charset=utf-8",
|
|
82
|
+
});
|
|
83
|
+
}
|
package/src/report/index.ts
CHANGED
|
@@ -3,6 +3,54 @@ export {
|
|
|
3
3
|
CardEmptyState,
|
|
4
4
|
type CardEmptyStateProps,
|
|
5
5
|
} from "./CardEmptyState.js";
|
|
6
|
+
export {
|
|
7
|
+
ChartDownloadButton,
|
|
8
|
+
ChartHeaderActions,
|
|
9
|
+
} from "./ChartDownloadButton.js";
|
|
10
|
+
export {
|
|
11
|
+
type BuildChartDocument,
|
|
12
|
+
type CaptureChartElement,
|
|
13
|
+
ChartExportProvider,
|
|
14
|
+
type ChartExportProviderProps,
|
|
15
|
+
type EncodeChartPng,
|
|
16
|
+
type ZipChartFiles,
|
|
17
|
+
} from "./ChartExportProvider.js";
|
|
18
|
+
export { ChartExportSurface } from "./ChartExportSurface.js";
|
|
19
|
+
export { captureChartElement } from "./captureChartElement.js";
|
|
20
|
+
export {
|
|
21
|
+
CHART_EXPORT_CAPTURING_ATTR,
|
|
22
|
+
CHART_EXPORT_HIDE_ATTR,
|
|
23
|
+
CHART_EXPORT_SCROLL_ATTR,
|
|
24
|
+
type ChartCaptureSource,
|
|
25
|
+
type ChartExportFile,
|
|
26
|
+
type ChartExportMeta,
|
|
27
|
+
type ChartExportView,
|
|
28
|
+
canvasToBlob,
|
|
29
|
+
chartExportHideProps,
|
|
30
|
+
chartExportRootStyle,
|
|
31
|
+
chartExportScrollProps,
|
|
32
|
+
chartExportViewsFromLabels,
|
|
33
|
+
chartPngFilename,
|
|
34
|
+
downloadBlob,
|
|
35
|
+
type RegisteredChart,
|
|
36
|
+
releaseCanvas,
|
|
37
|
+
restoreChartExportViews,
|
|
38
|
+
shouldIgnoreChartExportElement,
|
|
39
|
+
slugifyExportName,
|
|
40
|
+
sortRegisteredChartsByDocumentOrder,
|
|
41
|
+
toBulkChartCaptureSources,
|
|
42
|
+
} from "./chartExport.js";
|
|
43
|
+
export {
|
|
44
|
+
type ChartExportApi,
|
|
45
|
+
type ChartExportFormat,
|
|
46
|
+
useChartExport,
|
|
47
|
+
useRegisterChart,
|
|
48
|
+
} from "./chartExportContext.js";
|
|
49
|
+
export {
|
|
50
|
+
getChartExportFilename,
|
|
51
|
+
getChartZipFilename,
|
|
52
|
+
getDatedChartExportBasename,
|
|
53
|
+
} from "./chartExportFilenames.js";
|
|
6
54
|
export {
|
|
7
55
|
chartColorFailure,
|
|
8
56
|
chartColorSuccess,
|
|
@@ -17,6 +65,62 @@ export {
|
|
|
17
65
|
EmptySearchResults,
|
|
18
66
|
type EmptySearchResultsProps,
|
|
19
67
|
} from "./EmptySearchResults.js";
|
|
68
|
+
export {
|
|
69
|
+
ErrorTable,
|
|
70
|
+
type ErrorTableProps,
|
|
71
|
+
type MigrationIssueLike,
|
|
72
|
+
} from "./ErrorTable.js";
|
|
73
|
+
export {
|
|
74
|
+
FeatureStatusBadge,
|
|
75
|
+
type FeatureStatusBadgeProps,
|
|
76
|
+
} from "./FeatureStatusBadge.js";
|
|
77
|
+
export {
|
|
78
|
+
HostPowerStates,
|
|
79
|
+
type HostPowerStatesProps,
|
|
80
|
+
} from "./HostPowerStates.js";
|
|
81
|
+
export {
|
|
82
|
+
buildHtmlFromCharts,
|
|
83
|
+
buildHtmlReport,
|
|
84
|
+
escapeHtml,
|
|
85
|
+
type HtmlReportImage,
|
|
86
|
+
} from "./htmlExport.js";
|
|
87
|
+
export {
|
|
88
|
+
InfrastructureSummary,
|
|
89
|
+
type InfrastructureSummaryProps,
|
|
90
|
+
} from "./InfrastructureSummary.js";
|
|
91
|
+
export type {
|
|
92
|
+
ClusterDetailRow,
|
|
93
|
+
ClusterDetailsModel,
|
|
94
|
+
FeatureStatus,
|
|
95
|
+
HostCapability,
|
|
96
|
+
InfrastructureSummaryModel,
|
|
97
|
+
InventoryCluster,
|
|
98
|
+
InventoryDatastore,
|
|
99
|
+
InventoryHost,
|
|
100
|
+
InventoryInfra,
|
|
101
|
+
InventoryNetwork,
|
|
102
|
+
InventoryVms,
|
|
103
|
+
NetworkLabel,
|
|
104
|
+
} from "./infrastructureSummaryModel.js";
|
|
105
|
+
export {
|
|
106
|
+
booleanToFeatureStatus,
|
|
107
|
+
buildClusterDetailRows,
|
|
108
|
+
buildClusterDetails,
|
|
109
|
+
buildInfrastructureSummary,
|
|
110
|
+
countVCenters,
|
|
111
|
+
formatVSphereVersion,
|
|
112
|
+
hostCapabilityStatus,
|
|
113
|
+
visibleNetworks,
|
|
114
|
+
vsanStatus,
|
|
115
|
+
} from "./infrastructureSummaryModel.js";
|
|
116
|
+
export {
|
|
117
|
+
type NetworkInfraLike,
|
|
118
|
+
type NetworkLike,
|
|
119
|
+
NetworkOverview,
|
|
120
|
+
type NetworkOverviewProps,
|
|
121
|
+
type NicCountHistogram,
|
|
122
|
+
type NicCountSummary,
|
|
123
|
+
} from "./NetworkOverview.js";
|
|
20
124
|
export { OSBarChart, OSDistribution } from "./OSDistribution.js";
|
|
21
125
|
export { OsSupportTiersHelpPopover } from "./OsSupportTiersHelpPopover.js";
|
|
22
126
|
export { OsUpgradeNotice } from "./OsUpgradeNotice.js";
|
|
@@ -45,6 +149,35 @@ export {
|
|
|
45
149
|
SupportTier,
|
|
46
150
|
} from "./osSupportTier.js";
|
|
47
151
|
export { default as PopoverIcon } from "./PopoverIcon.js";
|
|
152
|
+
export {
|
|
153
|
+
PowerStateCard,
|
|
154
|
+
type PowerStateCardProps,
|
|
155
|
+
} from "./PowerStateCard.js";
|
|
156
|
+
export { buildPdfFromCharts } from "./pdfExport.js";
|
|
157
|
+
export {
|
|
158
|
+
type PdfExportSegment,
|
|
159
|
+
sliceCanvas,
|
|
160
|
+
splitSegmentForPageHeight,
|
|
161
|
+
} from "./pdfPage.js";
|
|
162
|
+
export type { PowerStateChartModel } from "./powerStates.js";
|
|
163
|
+
export {
|
|
164
|
+
buildHostPowerStateChart,
|
|
165
|
+
buildVmPowerStateChart,
|
|
166
|
+
HOST_POWER_COLORS,
|
|
167
|
+
VM_POWER_COLORS,
|
|
168
|
+
} from "./powerStates.js";
|
|
169
|
+
export {
|
|
170
|
+
ExportReportButton,
|
|
171
|
+
type ExportReportButtonProps,
|
|
172
|
+
ReportExportMenu,
|
|
173
|
+
type ReportExportMenuProps,
|
|
174
|
+
} from "./ReportExportMenu.js";
|
|
175
|
+
export { ReportTable, type ReportTableProps } from "./ReportTable.js";
|
|
176
|
+
export {
|
|
177
|
+
type ReportExportOption,
|
|
178
|
+
type StandardReportExportHandlers,
|
|
179
|
+
standardReportExportOptions,
|
|
180
|
+
} from "./reportExportOptions.js";
|
|
48
181
|
export { SupportTierBadge } from "./SupportTierBadge.js";
|
|
49
182
|
export {
|
|
50
183
|
ALL_TIERS_FILTER,
|
|
@@ -52,3 +185,12 @@ export {
|
|
|
52
185
|
type OsTableRow,
|
|
53
186
|
useOsBarChartViewModel,
|
|
54
187
|
} from "./useOsBarChartViewModel.js";
|
|
188
|
+
export {
|
|
189
|
+
VCenterClusterDetails,
|
|
190
|
+
type VCenterClusterDetailsProps,
|
|
191
|
+
} from "./VCenterClusterDetails.js";
|
|
192
|
+
export {
|
|
193
|
+
VmPowerStates,
|
|
194
|
+
type VmPowerStatesProps,
|
|
195
|
+
} from "./VmPowerStates.js";
|
|
196
|
+
export { zipChartPngs } from "./zipChartPngs.js";
|