@openshift-migration-advisor/shared-components 0.24.0 → 0.25.0-1701f64050d7
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 +23 -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/HostsOverview.d.ts +13 -0
- package/dist/report/HostsOverview.d.ts.map +1 -0
- package/dist/report/HostsOverview.js +84 -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/WarningsTable.d.ts +9 -0
- package/dist/report/WarningsTable.d.ts.map +1 -0
- package/dist/report/WarningsTable.js +20 -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 +73 -0
- package/dist/report/chartExport.d.ts.map +1 -0
- package/dist/report/chartExport.js +162 -0
- package/dist/report/chartExportContext.d.ts +32 -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 +4 -0
- package/dist/report/constants.d.ts.map +1 -1
- package/dist/report/constants.js +4 -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 +28 -0
- package/dist/report/index.d.ts.map +1 -1
- package/dist/report/index.js +26 -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 +131 -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 +392 -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/HostsOverview.tsx +185 -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/WarningsTable.tsx +75 -0
- package/src/report/__tests__/ChartExportProvider.test.tsx +542 -0
- package/src/report/__tests__/HostPowerStates.test.tsx +47 -0
- package/src/report/__tests__/HostsOverview.test.tsx +145 -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 +282 -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 +255 -0
- package/src/report/chartExportContext.tsx +92 -0
- package/src/report/chartExportFilenames.ts +21 -0
- package/src/report/constants.ts +4 -0
- package/src/report/dashboardStyles.ts +0 -23
- package/src/report/htmlExport.ts +83 -0
- package/src/report/index.ts +154 -0
- package/src/report/infrastructureSummaryModel.ts +281 -0
- package/src/report/pdfExport.ts +233 -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,131 @@
|
|
|
1
|
+
import jsPDF from "jspdf";
|
|
2
|
+
import { releaseCanvas, } from "./chartExport.js";
|
|
3
|
+
import { fitPdfImageSize, placePdfBlock, sliceCanvas } from "./pdfPage.js";
|
|
4
|
+
const MARGIN_MM = 10;
|
|
5
|
+
const GAP_MM = 8;
|
|
6
|
+
/** Flatten captures onto white; jsPDF cannot embed transparent PNG alpha cleanly. */
|
|
7
|
+
const PAGE_BACKGROUND = "#ffffff";
|
|
8
|
+
export async function buildPdfFromCharts(charts, documentTitle, extraPages = []) {
|
|
9
|
+
const pdf = new jsPDF("p", "mm", "a4");
|
|
10
|
+
const pageWidth = pdf.internal.pageSize.getWidth();
|
|
11
|
+
const pageHeight = pdf.internal.pageSize.getHeight();
|
|
12
|
+
const contentWidth = pageWidth - MARGIN_MM * 2;
|
|
13
|
+
const contentHeight = pageHeight - MARGIN_MM * 2;
|
|
14
|
+
const pageTop = MARGIN_MM;
|
|
15
|
+
const pageBottom = pageHeight - MARGIN_MM;
|
|
16
|
+
addCoverPage(pdf, documentTitle, [...charts.map((chart) => chart.title), ...extraPages.map((p) => p.title)], pageWidth, pageHeight);
|
|
17
|
+
let cursorY = null;
|
|
18
|
+
for (const chart of charts) {
|
|
19
|
+
const canvas = await chart.capture();
|
|
20
|
+
try {
|
|
21
|
+
if (canvas.width < 1 || canvas.height < 1) {
|
|
22
|
+
throw new Error("Chart capture produced an empty image");
|
|
23
|
+
}
|
|
24
|
+
const size = fitPdfImageSize(canvas.width, canvas.height, contentWidth, contentHeight);
|
|
25
|
+
const placement = placePdfBlock(cursorY, size.heightMm, pageTop, pageBottom);
|
|
26
|
+
if (placement.needsNewPage) {
|
|
27
|
+
pdf.addPage();
|
|
28
|
+
}
|
|
29
|
+
addChartImage(pdf, canvas, MARGIN_MM + (contentWidth - size.widthMm) / 2, placement.y, size.widthMm, size.heightMm);
|
|
30
|
+
cursorY = placement.y + size.heightMm + GAP_MM;
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
releaseCanvas(canvas);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (extraPages.length > 0) {
|
|
37
|
+
addExtraPages(pdf, extraPages, pageWidth, pageHeight);
|
|
38
|
+
}
|
|
39
|
+
addPageNumbers(pdf, pageWidth, pageHeight);
|
|
40
|
+
return pdf.output("blob");
|
|
41
|
+
}
|
|
42
|
+
function addCoverPage(pdf, documentTitle, tocItems, pageWidth, pageHeight) {
|
|
43
|
+
const contentWidth = pageWidth - MARGIN_MM * 2;
|
|
44
|
+
pdf.setFontSize(18);
|
|
45
|
+
const titleLines = pdf.splitTextToSize(documentTitle, contentWidth);
|
|
46
|
+
let titleY = MARGIN_MM + 8;
|
|
47
|
+
for (const line of titleLines) {
|
|
48
|
+
pdf.text(line, pageWidth / 2, titleY, { align: "center" });
|
|
49
|
+
titleY += 8;
|
|
50
|
+
}
|
|
51
|
+
pdf.setFontSize(11);
|
|
52
|
+
const generatedAt = new Date();
|
|
53
|
+
pdf.text(`Generated: ${generatedAt.toLocaleDateString()} ${generatedAt.toLocaleTimeString()}`, pageWidth / 2, titleY + 4, { align: "center" });
|
|
54
|
+
pdf.setFontSize(14);
|
|
55
|
+
pdf.text("Table of contents", MARGIN_MM, titleY + 16);
|
|
56
|
+
pdf.setFontSize(11);
|
|
57
|
+
let tocY = titleY + 26;
|
|
58
|
+
for (const item of tocItems) {
|
|
59
|
+
if (tocY > pageHeight - MARGIN_MM - 10) {
|
|
60
|
+
pdf.addPage();
|
|
61
|
+
tocY = MARGIN_MM;
|
|
62
|
+
}
|
|
63
|
+
pdf.text(`- ${item}`, MARGIN_MM, tocY);
|
|
64
|
+
tocY += 7;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function addChartImage(pdf, canvas, x, y, widthMm, heightMm) {
|
|
68
|
+
const flattened = sliceCanvas(canvas, canvas.width, canvas.height, 0, PAGE_BACKGROUND);
|
|
69
|
+
try {
|
|
70
|
+
pdf.addImage(flattened.toDataURL("image/jpeg", 0.92), "JPEG", x, y, widthMm, heightMm);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
releaseCanvas(flattened);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Append one native-text PDF page per entry in `extraPages`, rendered as
|
|
78
|
+
* label/value rows rather than a captured image. Each page starts fresh so
|
|
79
|
+
* its content never bleeds into a chart page.
|
|
80
|
+
*/
|
|
81
|
+
function addExtraPages(pdf, extraPages, pageWidth, pageHeight) {
|
|
82
|
+
const LABEL_COL_WIDTH = 68; // mm — enough for the longest label
|
|
83
|
+
const VALUE_COL_X = MARGIN_MM + LABEL_COL_WIDTH;
|
|
84
|
+
const VALUE_COL_WIDTH = pageWidth - MARGIN_MM - LABEL_COL_WIDTH;
|
|
85
|
+
const LINE_HEIGHT = 7; // mm between rows
|
|
86
|
+
for (const page of extraPages) {
|
|
87
|
+
pdf.addPage();
|
|
88
|
+
let y = MARGIN_MM + 8;
|
|
89
|
+
pdf.setFontSize(16);
|
|
90
|
+
pdf.setFont("helvetica", "bold");
|
|
91
|
+
pdf.text(page.title, MARGIN_MM, y);
|
|
92
|
+
y += 10;
|
|
93
|
+
pdf.setDrawColor(0, 103, 187);
|
|
94
|
+
pdf.setLineWidth(0.5);
|
|
95
|
+
pdf.line(MARGIN_MM, y, pageWidth - MARGIN_MM, y);
|
|
96
|
+
y += 10;
|
|
97
|
+
pdf.setFontSize(11);
|
|
98
|
+
for (const item of page.items) {
|
|
99
|
+
pdf.setFont("helvetica", "bold");
|
|
100
|
+
const labelLines = pdf.splitTextToSize(item.label, LABEL_COL_WIDTH - 4);
|
|
101
|
+
pdf.text(labelLines, MARGIN_MM, y);
|
|
102
|
+
pdf.setFont("helvetica", "normal");
|
|
103
|
+
const valueLines = pdf.splitTextToSize(item.value, VALUE_COL_WIDTH);
|
|
104
|
+
pdf.text(valueLines, VALUE_COL_X, y);
|
|
105
|
+
y += LINE_HEIGHT * Math.max(labelLines.length, valueLines.length);
|
|
106
|
+
if (y > pageHeight - MARGIN_MM - 25) {
|
|
107
|
+
pdf.addPage();
|
|
108
|
+
y = MARGIN_MM + 10;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (page.footer) {
|
|
112
|
+
y += 4;
|
|
113
|
+
pdf.setFontSize(9);
|
|
114
|
+
pdf.setFont("helvetica", "bolditalic");
|
|
115
|
+
const footerLines = pdf.splitTextToSize(page.footer, pageWidth - MARGIN_MM * 2);
|
|
116
|
+
pdf.text(footerLines, MARGIN_MM, y);
|
|
117
|
+
pdf.setFont("helvetica", "normal");
|
|
118
|
+
pdf.setFontSize(11);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function addPageNumbers(pdf, pageWidth, pageHeight) {
|
|
123
|
+
const totalPages = pdf.getNumberOfPages();
|
|
124
|
+
pdf.setFontSize(9);
|
|
125
|
+
for (let page = 1; page <= totalPages; page++) {
|
|
126
|
+
pdf.setPage(page);
|
|
127
|
+
pdf.text(`Page ${page} of ${totalPages}`, pageWidth / 2, pageHeight - 6, {
|
|
128
|
+
align: "center",
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface PdfExportSegment {
|
|
2
|
+
top: number;
|
|
3
|
+
height: number;
|
|
4
|
+
}
|
|
5
|
+
export declare function splitSegmentForPageHeight(segment: PdfExportSegment, imgHeight: number, pageHeightPx: number): PdfExportSegment[];
|
|
6
|
+
export declare function fitPdfImageSize(pixelWidth: number, pixelHeight: number, maxWidthMm: number, maxHeightMm: number): {
|
|
7
|
+
widthMm: number;
|
|
8
|
+
heightMm: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function placePdfBlock(cursorY: number | null, blockHeightMm: number, pageTopMm: number, pageBottomMm: number): {
|
|
11
|
+
y: number;
|
|
12
|
+
needsNewPage: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare function sliceCanvas(sourceCanvas: HTMLCanvasElement, width: number, height: number, offsetY: number, backgroundColor: string): HTMLCanvasElement;
|
|
15
|
+
//# sourceMappingURL=pdfPage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdfPage.d.ts","sourceRoot":"","sources":["../../src/report/pdfPage.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,gBAAgB,EACzB,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,gBAAgB,EAAE,CAcpB;AAED,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,GAClB;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAUvC;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,OAAO,CAAA;CAAE,CAKtC;AAED,wBAAgB,WAAW,CACzB,YAAY,EAAE,iBAAiB,EAC/B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,MAAM,GACtB,iBAAiB,CAsBnB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export function splitSegmentForPageHeight(segment, imgHeight, pageHeightPx) {
|
|
2
|
+
const total = Math.max(1, Math.min(segment.height, imgHeight - segment.top));
|
|
3
|
+
if (pageHeightPx <= 0 || total <= pageHeightPx) {
|
|
4
|
+
return [{ top: segment.top, height: total }];
|
|
5
|
+
}
|
|
6
|
+
const slices = [];
|
|
7
|
+
let offset = 0;
|
|
8
|
+
while (offset < total) {
|
|
9
|
+
const height = Math.min(pageHeightPx, total - offset);
|
|
10
|
+
slices.push({ top: segment.top + offset, height });
|
|
11
|
+
offset += height;
|
|
12
|
+
}
|
|
13
|
+
return slices;
|
|
14
|
+
}
|
|
15
|
+
export function fitPdfImageSize(pixelWidth, pixelHeight, maxWidthMm, maxHeightMm) {
|
|
16
|
+
const safeWidth = Math.max(1, pixelWidth);
|
|
17
|
+
const safeHeight = Math.max(1, pixelHeight);
|
|
18
|
+
const widthScale = maxWidthMm / safeWidth;
|
|
19
|
+
const heightAtFullWidth = safeHeight * widthScale;
|
|
20
|
+
if (heightAtFullWidth <= maxHeightMm) {
|
|
21
|
+
return { widthMm: maxWidthMm, heightMm: heightAtFullWidth };
|
|
22
|
+
}
|
|
23
|
+
const scale = maxHeightMm / safeHeight;
|
|
24
|
+
return { widthMm: safeWidth * scale, heightMm: maxHeightMm };
|
|
25
|
+
}
|
|
26
|
+
export function placePdfBlock(cursorY, blockHeightMm, pageTopMm, pageBottomMm) {
|
|
27
|
+
if (cursorY === null || cursorY + blockHeightMm > pageBottomMm) {
|
|
28
|
+
return { y: pageTopMm, needsNewPage: true };
|
|
29
|
+
}
|
|
30
|
+
return { y: cursorY, needsNewPage: false };
|
|
31
|
+
}
|
|
32
|
+
export function sliceCanvas(sourceCanvas, width, height, offsetY, backgroundColor) {
|
|
33
|
+
const pageCanvas = document.createElement("canvas");
|
|
34
|
+
pageCanvas.width = width;
|
|
35
|
+
pageCanvas.height = height;
|
|
36
|
+
const context = pageCanvas.getContext("2d");
|
|
37
|
+
if (!context) {
|
|
38
|
+
throw new Error("Canvas 2D context unavailable");
|
|
39
|
+
}
|
|
40
|
+
context.fillStyle = backgroundColor;
|
|
41
|
+
context.fillRect(0, 0, width, height);
|
|
42
|
+
context.drawImage(sourceCanvas, 0, offsetY, width, height, 0, 0, width, height);
|
|
43
|
+
return pageCanvas;
|
|
44
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MigrationDonutChartDatum } from "../charts/MigrationDonutChart.js";
|
|
2
|
+
export type PowerStateChartModel = {
|
|
3
|
+
slices: MigrationDonutChartDatum[];
|
|
4
|
+
legend: Record<string, string>;
|
|
5
|
+
total: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const HOST_POWER_COLORS: Record<string, string>;
|
|
8
|
+
export declare const VM_POWER_COLORS: Record<string, string>;
|
|
9
|
+
export declare const buildHostPowerStateChart: (hostPowerStates?: Record<string, number>) => PowerStateChartModel;
|
|
10
|
+
export declare const buildVmPowerStateChart: (powerStates?: Record<string, number>) => PowerStateChartModel;
|
|
11
|
+
//# sourceMappingURL=powerStates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"powerStates.d.ts","sourceRoot":"","sources":["../../src/report/powerStates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAEjF,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,wBAAwB,EAAE,CAAC;IACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AA8BF,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAMpD,CAAC;AAcF,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAIlD,CAAC;AAmCF,eAAO,MAAM,wBAAwB,GACnC,kBAAkB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACvC,oBAgCF,CAAC;AAEF,eAAO,MAAM,sBAAsB,GACjC,cAAc,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACnC,oBAmCF,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const HOST_POWER_CATEGORIES = [
|
|
2
|
+
"Powered on",
|
|
3
|
+
"Powered off",
|
|
4
|
+
"Standby",
|
|
5
|
+
"Not responding",
|
|
6
|
+
"Maintenance",
|
|
7
|
+
];
|
|
8
|
+
const HOST_POWER_KEY_ALIASES = {
|
|
9
|
+
poweredon: "Powered on",
|
|
10
|
+
powered_on: "Powered on",
|
|
11
|
+
green: "Powered on",
|
|
12
|
+
poweredoff: "Powered off",
|
|
13
|
+
powered_off: "Powered off",
|
|
14
|
+
standby: "Standby",
|
|
15
|
+
stand_by: "Standby",
|
|
16
|
+
notresponding: "Not responding",
|
|
17
|
+
not_responding: "Not responding",
|
|
18
|
+
gray: "Not responding",
|
|
19
|
+
grey: "Not responding",
|
|
20
|
+
red: "Not responding",
|
|
21
|
+
maintenance: "Maintenance",
|
|
22
|
+
inmaintenance: "Maintenance",
|
|
23
|
+
inmaintenancemode: "Maintenance",
|
|
24
|
+
};
|
|
25
|
+
export const HOST_POWER_COLORS = {
|
|
26
|
+
"Powered on": "#0066cc",
|
|
27
|
+
"Powered off": "#dca614",
|
|
28
|
+
Standby: "#f0ab00",
|
|
29
|
+
"Not responding": "#c9190b",
|
|
30
|
+
Maintenance: "#002f5d",
|
|
31
|
+
};
|
|
32
|
+
const VM_POWER_CATEGORIES = ["Powered off", "Powered on", "Suspended"];
|
|
33
|
+
const VM_POWER_KEY_ALIASES = {
|
|
34
|
+
poweredoff: "Powered off",
|
|
35
|
+
powered_off: "Powered off",
|
|
36
|
+
poweredon: "Powered on",
|
|
37
|
+
powered_on: "Powered on",
|
|
38
|
+
suspended: "Suspended",
|
|
39
|
+
};
|
|
40
|
+
export const VM_POWER_COLORS = {
|
|
41
|
+
"Powered off": "#0066cc",
|
|
42
|
+
"Powered on": "#dca614",
|
|
43
|
+
Suspended: "#5e40be",
|
|
44
|
+
};
|
|
45
|
+
const OTHER_COLOR = "#6a6e73";
|
|
46
|
+
const normalizeKey = (key) => key
|
|
47
|
+
.trim()
|
|
48
|
+
.toLowerCase()
|
|
49
|
+
.replace(/[\s-]+/g, "");
|
|
50
|
+
const formatUnknownLabel = (key) => {
|
|
51
|
+
const spaced = key
|
|
52
|
+
.replace(/[_-]+/g, " ")
|
|
53
|
+
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
54
|
+
.trim();
|
|
55
|
+
if (!spaced) {
|
|
56
|
+
return "Unknown";
|
|
57
|
+
}
|
|
58
|
+
return spaced.charAt(0).toUpperCase() + spaced.slice(1);
|
|
59
|
+
};
|
|
60
|
+
const toSlice = (name, count, unit) => ({
|
|
61
|
+
name,
|
|
62
|
+
count,
|
|
63
|
+
legendCategory: name,
|
|
64
|
+
countDisplay: `${count} ${count === 1 ? unit.replace(/s$/, "") : unit}`,
|
|
65
|
+
});
|
|
66
|
+
const sumCounts = (counts) => Object.values(counts).reduce((total, count) => total + (count || 0), 0);
|
|
67
|
+
export const buildHostPowerStateChart = (hostPowerStates) => {
|
|
68
|
+
const counts = Object.fromEntries(HOST_POWER_CATEGORIES.map((category) => [category, 0]));
|
|
69
|
+
for (const [key, count] of Object.entries(hostPowerStates ?? {})) {
|
|
70
|
+
const mapped = HOST_POWER_KEY_ALIASES[normalizeKey(key)];
|
|
71
|
+
const label = mapped ?? formatUnknownLabel(key);
|
|
72
|
+
counts[label] = (counts[label] ?? 0) + (count || 0);
|
|
73
|
+
}
|
|
74
|
+
const orderedLabels = [
|
|
75
|
+
...HOST_POWER_CATEGORIES,
|
|
76
|
+
...Object.keys(counts).filter((label) => !HOST_POWER_CATEGORIES.includes(label)),
|
|
77
|
+
];
|
|
78
|
+
const slices = orderedLabels.map((label) => toSlice(label, counts[label] ?? 0, "hosts"));
|
|
79
|
+
const legend = {};
|
|
80
|
+
for (const label of orderedLabels) {
|
|
81
|
+
legend[label] = HOST_POWER_COLORS[label] ?? OTHER_COLOR;
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
slices,
|
|
85
|
+
legend,
|
|
86
|
+
total: sumCounts(counts),
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
export const buildVmPowerStateChart = (powerStates) => {
|
|
90
|
+
const counts = {
|
|
91
|
+
"Powered off": 0,
|
|
92
|
+
"Powered on": 0,
|
|
93
|
+
};
|
|
94
|
+
for (const [key, count] of Object.entries(powerStates ?? {})) {
|
|
95
|
+
const mapped = VM_POWER_KEY_ALIASES[normalizeKey(key)];
|
|
96
|
+
const label = mapped ?? formatUnknownLabel(key);
|
|
97
|
+
counts[label] = (counts[label] ?? 0) + (count || 0);
|
|
98
|
+
}
|
|
99
|
+
const orderedLabels = [
|
|
100
|
+
...VM_POWER_CATEGORIES.filter((category) => category !== "Suspended" || (counts[category] ?? 0) > 0),
|
|
101
|
+
...Object.keys(counts).filter((label) => !VM_POWER_CATEGORIES.includes(label)),
|
|
102
|
+
];
|
|
103
|
+
const slices = orderedLabels.map((label) => toSlice(label, counts[label] ?? 0, "VMs"));
|
|
104
|
+
const legend = {};
|
|
105
|
+
for (const label of orderedLabels) {
|
|
106
|
+
legend[label] = VM_POWER_COLORS[label] ?? OTHER_COLOR;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
slices,
|
|
110
|
+
legend,
|
|
111
|
+
total: sumCounts(counts),
|
|
112
|
+
};
|
|
113
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface ReportExportOption {
|
|
2
|
+
key: string;
|
|
3
|
+
label: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
onSelect: () => void;
|
|
6
|
+
isDisabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface StandardReportExportHandlers {
|
|
9
|
+
onExportPdf?: () => void;
|
|
10
|
+
onExportPng?: () => void;
|
|
11
|
+
onExportHtml?: () => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Standard report-download actions. Omit a handler to hide that format.
|
|
15
|
+
*/
|
|
16
|
+
export declare const standardReportExportOptions: ({ onExportPdf, onExportPng, onExportHtml, }: StandardReportExportHandlers) => ReportExportOption[];
|
|
17
|
+
//# sourceMappingURL=reportExportOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reportExportOptions.d.ts","sourceRoot":"","sources":["../../src/report/reportExportOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,4BAA4B;IAC3C,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED;;GAEG;AACH,eAAO,MAAM,2BAA2B,GAAI,6CAIzC,4BAA4B,KAAG,kBAAkB,EA+BnD,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard report-download actions. Omit a handler to hide that format.
|
|
3
|
+
*/
|
|
4
|
+
export const standardReportExportOptions = ({ onExportPdf, onExportPng, onExportHtml, }) => {
|
|
5
|
+
const options = [];
|
|
6
|
+
if (onExportPdf) {
|
|
7
|
+
options.push({
|
|
8
|
+
key: "pdf",
|
|
9
|
+
label: "PDF",
|
|
10
|
+
description: "Export the report as a PDF",
|
|
11
|
+
onSelect: onExportPdf,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
if (onExportHtml) {
|
|
15
|
+
options.push({
|
|
16
|
+
key: "html",
|
|
17
|
+
label: "HTML",
|
|
18
|
+
description: "Export the report as HTML",
|
|
19
|
+
onSelect: onExportHtml,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (onExportPng) {
|
|
23
|
+
options.push({
|
|
24
|
+
key: "png",
|
|
25
|
+
label: "PNG",
|
|
26
|
+
description: "Download all charts as PNG files",
|
|
27
|
+
onSelect: onExportPng,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return options;
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zipChartPngs.d.ts","sourceRoot":"","sources":["../../src/report/zipChartPngs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,wBAAsB,YAAY,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAM1E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openshift-migration-advisor/shared-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0-1701f64050d7",
|
|
4
4
|
"description": "Shared React UI components for Migration Advisor apps (report charts, forms, OS support tiers)",
|
|
5
5
|
"author": "Montse Ortega <mortegag@redhat.com>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -44,5 +44,10 @@
|
|
|
44
44
|
"src",
|
|
45
45
|
"LICENSE",
|
|
46
46
|
"README.md"
|
|
47
|
-
]
|
|
47
|
+
],
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"html2canvas-pro": "^2.4.5",
|
|
50
|
+
"jspdf": "^4.2.1",
|
|
51
|
+
"jszip": "^3.10.2"
|
|
52
|
+
}
|
|
48
53
|
}
|
package/src/charts/index.ts
CHANGED
|
@@ -33,12 +33,19 @@ export default function RadioButtonFormGroup({
|
|
|
33
33
|
const showError = error && (isTouched || isSubmitted);
|
|
34
34
|
|
|
35
35
|
return (
|
|
36
|
-
<FormGroup
|
|
36
|
+
<FormGroup
|
|
37
|
+
label={label}
|
|
38
|
+
isRequired={isRequired}
|
|
39
|
+
fieldId={id}
|
|
40
|
+
role="radiogroup"
|
|
41
|
+
isInline
|
|
42
|
+
{...props}
|
|
43
|
+
>
|
|
37
44
|
<Controller
|
|
38
45
|
name={name}
|
|
39
46
|
control={methods.control}
|
|
40
47
|
render={({ field }) => (
|
|
41
|
-
|
|
48
|
+
<>
|
|
42
49
|
{options.map((option) => (
|
|
43
50
|
<Radio
|
|
44
51
|
key={option.value}
|
|
@@ -50,7 +57,7 @@ export default function RadioButtonFormGroup({
|
|
|
50
57
|
onBlur={field.onBlur}
|
|
51
58
|
/>
|
|
52
59
|
))}
|
|
53
|
-
|
|
60
|
+
</>
|
|
54
61
|
)}
|
|
55
62
|
/>
|
|
56
63
|
<FormFieldHelperText
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Button, Flex, FlexItem } from "@patternfly/react-core";
|
|
2
|
+
import { DownloadIcon } from "@patternfly/react-icons";
|
|
3
|
+
import type { FC, ReactNode } from "react";
|
|
4
|
+
import { chartExportHideProps } from "./chartExport.js";
|
|
5
|
+
import { useChartExport } from "./chartExportContext.js";
|
|
6
|
+
|
|
7
|
+
export const ChartDownloadButton: FC<{
|
|
8
|
+
chartId: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
}> = ({ chartId, title }) => {
|
|
11
|
+
const exportApi = useChartExport();
|
|
12
|
+
if (!exportApi) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const label = title ? `Download ${title} as PNG` : "Download chart as PNG";
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Button
|
|
20
|
+
variant="plain"
|
|
21
|
+
icon={<DownloadIcon />}
|
|
22
|
+
aria-label={label}
|
|
23
|
+
isLoading={exportApi.downloadingChartId === chartId}
|
|
24
|
+
isDisabled={exportApi.isBusy}
|
|
25
|
+
onClick={() => {
|
|
26
|
+
void exportApi.downloadChart(chartId);
|
|
27
|
+
}}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
ChartDownloadButton.displayName = "ChartDownloadButton";
|
|
33
|
+
|
|
34
|
+
export const ChartHeaderActions: FC<{
|
|
35
|
+
chartId: string;
|
|
36
|
+
title?: string;
|
|
37
|
+
children?: ReactNode;
|
|
38
|
+
}> = ({ chartId, title, children }) => {
|
|
39
|
+
const exportApi = useChartExport();
|
|
40
|
+
if (!exportApi && !children) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<FlexItem {...chartExportHideProps}>
|
|
46
|
+
<Flex
|
|
47
|
+
alignItems={{ default: "alignItemsCenter" }}
|
|
48
|
+
spaceItems={{ default: "spaceItemsSm" }}
|
|
49
|
+
>
|
|
50
|
+
{children}
|
|
51
|
+
{exportApi ? (
|
|
52
|
+
<ChartDownloadButton chartId={chartId} title={title} />
|
|
53
|
+
) : null}
|
|
54
|
+
</Flex>
|
|
55
|
+
</FlexItem>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
ChartHeaderActions.displayName = "ChartHeaderActions";
|