@openshift-migration-advisor/shared-components 0.24.0 → 0.25.0-6fd4e1ee8e11

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.
Files changed (130) hide show
  1. package/README.md +31 -0
  2. package/dist/charts/index.d.ts +1 -1
  3. package/dist/charts/index.d.ts.map +1 -1
  4. package/dist/forms/RadioButtonFormGroup.d.ts.map +1 -1
  5. package/dist/forms/RadioButtonFormGroup.js +2 -2
  6. package/dist/report/ChartDownloadButton.d.ts +11 -0
  7. package/dist/report/ChartDownloadButton.d.ts.map +1 -0
  8. package/dist/report/ChartDownloadButton.js +24 -0
  9. package/dist/report/ChartExportProvider.d.ts +22 -0
  10. package/dist/report/ChartExportProvider.d.ts.map +1 -0
  11. package/dist/report/ChartExportProvider.js +222 -0
  12. package/dist/report/ChartExportSurface.d.ts +12 -0
  13. package/dist/report/ChartExportSurface.d.ts.map +1 -0
  14. package/dist/report/ChartExportSurface.js +32 -0
  15. package/dist/report/FeatureStatusBadge.d.ts +7 -0
  16. package/dist/report/FeatureStatusBadge.d.ts.map +1 -0
  17. package/dist/report/FeatureStatusBadge.js +13 -0
  18. package/dist/report/HostPowerStates.d.ts +8 -0
  19. package/dist/report/HostPowerStates.d.ts.map +1 -0
  20. package/dist/report/HostPowerStates.js +11 -0
  21. package/dist/report/InfrastructureSummary.d.ts +7 -0
  22. package/dist/report/InfrastructureSummary.d.ts.map +1 -0
  23. package/dist/report/InfrastructureSummary.js +9 -0
  24. package/dist/report/OSDistribution.d.ts +0 -2
  25. package/dist/report/OSDistribution.d.ts.map +1 -1
  26. package/dist/report/OSDistribution.js +10 -15
  27. package/dist/report/OsSupportTiersHelpPopover.d.ts.map +1 -1
  28. package/dist/report/OsSupportTiersHelpPopover.js +2 -31
  29. package/dist/report/OsUpgradeNotice.d.ts.map +1 -1
  30. package/dist/report/OsUpgradeNotice.js +1 -5
  31. package/dist/report/OsUpgradeRecommendationPopover.d.ts +0 -1
  32. package/dist/report/OsUpgradeRecommendationPopover.d.ts.map +1 -1
  33. package/dist/report/OsUpgradeRecommendationPopover.js +4 -3
  34. package/dist/report/PowerStateCard.d.ts +16 -0
  35. package/dist/report/PowerStateCard.d.ts.map +1 -0
  36. package/dist/report/PowerStateCard.js +9 -0
  37. package/dist/report/ReportExportMenu.d.ts +19 -0
  38. package/dist/report/ReportExportMenu.d.ts.map +1 -0
  39. package/dist/report/ReportExportMenu.js +31 -0
  40. package/dist/report/SupportTierBadge.d.ts +0 -1
  41. package/dist/report/SupportTierBadge.d.ts.map +1 -1
  42. package/dist/report/SupportTierBadge.js +1 -19
  43. package/dist/report/VCenterClusterDetails.d.ts +9 -0
  44. package/dist/report/VCenterClusterDetails.d.ts.map +1 -0
  45. package/dist/report/VCenterClusterDetails.js +31 -0
  46. package/dist/report/VmPowerStates.d.ts +8 -0
  47. package/dist/report/VmPowerStates.d.ts.map +1 -0
  48. package/dist/report/VmPowerStates.js +11 -0
  49. package/dist/report/captureChartElement.d.ts +8 -0
  50. package/dist/report/captureChartElement.d.ts.map +1 -0
  51. package/dist/report/captureChartElement.js +284 -0
  52. package/dist/report/chartExport.d.ts +57 -0
  53. package/dist/report/chartExport.d.ts.map +1 -0
  54. package/dist/report/chartExport.js +162 -0
  55. package/dist/report/chartExportContext.d.ts +28 -0
  56. package/dist/report/chartExportContext.d.ts.map +1 -0
  57. package/dist/report/chartExportContext.js +36 -0
  58. package/dist/report/chartExportFilenames.d.ts +4 -0
  59. package/dist/report/chartExportFilenames.d.ts.map +1 -0
  60. package/dist/report/chartExportFilenames.js +16 -0
  61. package/dist/report/constants.d.ts +2 -0
  62. package/dist/report/constants.d.ts.map +1 -1
  63. package/dist/report/constants.js +2 -0
  64. package/dist/report/dashboardStyles.d.ts +0 -4
  65. package/dist/report/dashboardStyles.d.ts.map +1 -1
  66. package/dist/report/dashboardStyles.js +0 -19
  67. package/dist/report/htmlExport.d.ts +9 -0
  68. package/dist/report/htmlExport.d.ts.map +1 -0
  69. package/dist/report/htmlExport.js +65 -0
  70. package/dist/report/index.d.ts +23 -0
  71. package/dist/report/index.d.ts.map +1 -1
  72. package/dist/report/index.js +21 -0
  73. package/dist/report/infrastructureSummaryModel.d.ts +82 -0
  74. package/dist/report/infrastructureSummaryModel.d.ts.map +1 -0
  75. package/dist/report/infrastructureSummaryModel.js +139 -0
  76. package/dist/report/pdfExport.d.ts +3 -0
  77. package/dist/report/pdfExport.d.ts.map +1 -0
  78. package/dist/report/pdfExport.js +82 -0
  79. package/dist/report/pdfPage.d.ts +15 -0
  80. package/dist/report/pdfPage.d.ts.map +1 -0
  81. package/dist/report/pdfPage.js +44 -0
  82. package/dist/report/powerStates.d.ts +11 -0
  83. package/dist/report/powerStates.d.ts.map +1 -0
  84. package/dist/report/powerStates.js +113 -0
  85. package/dist/report/reportExportOptions.d.ts +17 -0
  86. package/dist/report/reportExportOptions.d.ts.map +1 -0
  87. package/dist/report/reportExportOptions.js +31 -0
  88. package/dist/report/zipChartPngs.d.ts +3 -0
  89. package/dist/report/zipChartPngs.d.ts.map +1 -0
  90. package/dist/report/zipChartPngs.js +8 -0
  91. package/package.json +7 -2
  92. package/src/charts/index.ts +1 -0
  93. package/src/forms/RadioButtonFormGroup.tsx +10 -3
  94. package/src/report/ChartDownloadButton.tsx +59 -0
  95. package/src/report/ChartExportProvider.tsx +384 -0
  96. package/src/report/ChartExportSurface.tsx +60 -0
  97. package/src/report/FeatureStatusBadge.tsx +30 -0
  98. package/src/report/HostPowerStates.tsx +38 -0
  99. package/src/report/InfrastructureSummary.tsx +73 -0
  100. package/src/report/OSDistribution.tsx +96 -99
  101. package/src/report/OsSupportTiersHelpPopover.tsx +32 -62
  102. package/src/report/OsUpgradeNotice.tsx +1 -7
  103. package/src/report/OsUpgradeRecommendationPopover.tsx +3 -4
  104. package/src/report/PowerStateCard.tsx +86 -0
  105. package/src/report/ReportExportMenu.tsx +119 -0
  106. package/src/report/SupportTierBadge.tsx +12 -38
  107. package/src/report/VCenterClusterDetails.tsx +233 -0
  108. package/src/report/VmPowerStates.tsx +38 -0
  109. package/src/report/__tests__/ChartExportProvider.test.tsx +474 -0
  110. package/src/report/__tests__/HostPowerStates.test.tsx +47 -0
  111. package/src/report/__tests__/InfrastructureSummary.test.tsx +126 -0
  112. package/src/report/__tests__/OSDistribution.test.tsx +10 -11
  113. package/src/report/__tests__/captureChartElement.test.ts +132 -0
  114. package/src/report/__tests__/chartExportPackagers.test.ts +224 -0
  115. package/src/report/__tests__/infrastructureSummaryModel.test.ts +224 -0
  116. package/src/report/__tests__/powerStates.test.ts +70 -0
  117. package/src/report/captureChartElement.ts +368 -0
  118. package/src/report/chartExport.ts +237 -0
  119. package/src/report/chartExportContext.tsx +84 -0
  120. package/src/report/chartExportFilenames.ts +21 -0
  121. package/src/report/constants.ts +2 -0
  122. package/src/report/dashboardStyles.ts +0 -23
  123. package/src/report/htmlExport.ts +83 -0
  124. package/src/report/index.ts +128 -0
  125. package/src/report/infrastructureSummaryModel.ts +281 -0
  126. package/src/report/pdfExport.ts +154 -0
  127. package/src/report/pdfPage.ts +83 -0
  128. package/src/report/powerStates.ts +169 -0
  129. package/src/report/reportExportOptions.ts +53 -0
  130. package/src/report/zipChartPngs.ts +10 -0
@@ -0,0 +1,83 @@
1
+ export interface PdfExportSegment {
2
+ top: number;
3
+ height: number;
4
+ }
5
+
6
+ export function splitSegmentForPageHeight(
7
+ segment: PdfExportSegment,
8
+ imgHeight: number,
9
+ pageHeightPx: number,
10
+ ): PdfExportSegment[] {
11
+ const total = Math.max(1, Math.min(segment.height, imgHeight - segment.top));
12
+ if (pageHeightPx <= 0 || total <= pageHeightPx) {
13
+ return [{ top: segment.top, height: total }];
14
+ }
15
+
16
+ const slices: PdfExportSegment[] = [];
17
+ let offset = 0;
18
+ while (offset < total) {
19
+ const height = Math.min(pageHeightPx, total - offset);
20
+ slices.push({ top: segment.top + offset, height });
21
+ offset += height;
22
+ }
23
+ return slices;
24
+ }
25
+
26
+ export function fitPdfImageSize(
27
+ pixelWidth: number,
28
+ pixelHeight: number,
29
+ maxWidthMm: number,
30
+ maxHeightMm: number,
31
+ ): { widthMm: number; heightMm: number } {
32
+ const safeWidth = Math.max(1, pixelWidth);
33
+ const safeHeight = Math.max(1, pixelHeight);
34
+ const widthScale = maxWidthMm / safeWidth;
35
+ const heightAtFullWidth = safeHeight * widthScale;
36
+ if (heightAtFullWidth <= maxHeightMm) {
37
+ return { widthMm: maxWidthMm, heightMm: heightAtFullWidth };
38
+ }
39
+ const scale = maxHeightMm / safeHeight;
40
+ return { widthMm: safeWidth * scale, heightMm: maxHeightMm };
41
+ }
42
+
43
+ export function placePdfBlock(
44
+ cursorY: number | null,
45
+ blockHeightMm: number,
46
+ pageTopMm: number,
47
+ pageBottomMm: number,
48
+ ): { y: number; needsNewPage: boolean } {
49
+ if (cursorY === null || cursorY + blockHeightMm > pageBottomMm) {
50
+ return { y: pageTopMm, needsNewPage: true };
51
+ }
52
+ return { y: cursorY, needsNewPage: false };
53
+ }
54
+
55
+ export function sliceCanvas(
56
+ sourceCanvas: HTMLCanvasElement,
57
+ width: number,
58
+ height: number,
59
+ offsetY: number,
60
+ backgroundColor: string,
61
+ ): HTMLCanvasElement {
62
+ const pageCanvas = document.createElement("canvas");
63
+ pageCanvas.width = width;
64
+ pageCanvas.height = height;
65
+ const context = pageCanvas.getContext("2d");
66
+ if (!context) {
67
+ throw new Error("Canvas 2D context unavailable");
68
+ }
69
+ context.fillStyle = backgroundColor;
70
+ context.fillRect(0, 0, width, height);
71
+ context.drawImage(
72
+ sourceCanvas,
73
+ 0,
74
+ offsetY,
75
+ width,
76
+ height,
77
+ 0,
78
+ 0,
79
+ width,
80
+ height,
81
+ );
82
+ return pageCanvas;
83
+ }
@@ -0,0 +1,169 @@
1
+ import type { MigrationDonutChartDatum } from "../charts/MigrationDonutChart.js";
2
+
3
+ export type PowerStateChartModel = {
4
+ slices: MigrationDonutChartDatum[];
5
+ legend: Record<string, string>;
6
+ total: number;
7
+ };
8
+
9
+ const HOST_POWER_CATEGORIES = [
10
+ "Powered on",
11
+ "Powered off",
12
+ "Standby",
13
+ "Not responding",
14
+ "Maintenance",
15
+ ] as const;
16
+
17
+ type HostPowerCategory = (typeof HOST_POWER_CATEGORIES)[number];
18
+
19
+ const HOST_POWER_KEY_ALIASES: Record<string, HostPowerCategory> = {
20
+ poweredon: "Powered on",
21
+ powered_on: "Powered on",
22
+ green: "Powered on",
23
+ poweredoff: "Powered off",
24
+ powered_off: "Powered off",
25
+ standby: "Standby",
26
+ stand_by: "Standby",
27
+ notresponding: "Not responding",
28
+ not_responding: "Not responding",
29
+ gray: "Not responding",
30
+ grey: "Not responding",
31
+ red: "Not responding",
32
+ maintenance: "Maintenance",
33
+ inmaintenance: "Maintenance",
34
+ inmaintenancemode: "Maintenance",
35
+ };
36
+
37
+ export const HOST_POWER_COLORS: Record<string, string> = {
38
+ "Powered on": "#0066cc",
39
+ "Powered off": "#dca614",
40
+ Standby: "#f0ab00",
41
+ "Not responding": "#c9190b",
42
+ Maintenance: "#002f5d",
43
+ };
44
+
45
+ const VM_POWER_CATEGORIES = ["Powered off", "Powered on", "Suspended"] as const;
46
+
47
+ type VmPowerCategory = (typeof VM_POWER_CATEGORIES)[number];
48
+
49
+ const VM_POWER_KEY_ALIASES: Record<string, VmPowerCategory> = {
50
+ poweredoff: "Powered off",
51
+ powered_off: "Powered off",
52
+ poweredon: "Powered on",
53
+ powered_on: "Powered on",
54
+ suspended: "Suspended",
55
+ };
56
+
57
+ export const VM_POWER_COLORS: Record<string, string> = {
58
+ "Powered off": "#0066cc",
59
+ "Powered on": "#dca614",
60
+ Suspended: "#5e40be",
61
+ };
62
+
63
+ const OTHER_COLOR = "#6a6e73";
64
+
65
+ const normalizeKey = (key: string): string =>
66
+ key
67
+ .trim()
68
+ .toLowerCase()
69
+ .replace(/[\s-]+/g, "");
70
+
71
+ const formatUnknownLabel = (key: string): string => {
72
+ const spaced = key
73
+ .replace(/[_-]+/g, " ")
74
+ .replace(/([a-z])([A-Z])/g, "$1 $2")
75
+ .trim();
76
+ if (!spaced) {
77
+ return "Unknown";
78
+ }
79
+ return spaced.charAt(0).toUpperCase() + spaced.slice(1);
80
+ };
81
+
82
+ const toSlice = (
83
+ name: string,
84
+ count: number,
85
+ unit: string,
86
+ ): MigrationDonutChartDatum => ({
87
+ name,
88
+ count,
89
+ legendCategory: name,
90
+ countDisplay: `${count} ${count === 1 ? unit.replace(/s$/, "") : unit}`,
91
+ });
92
+
93
+ const sumCounts = (counts: Record<string, number>): number =>
94
+ Object.values(counts).reduce((total, count) => total + (count || 0), 0);
95
+
96
+ export const buildHostPowerStateChart = (
97
+ hostPowerStates?: Record<string, number>,
98
+ ): PowerStateChartModel => {
99
+ const counts: Record<string, number> = Object.fromEntries(
100
+ HOST_POWER_CATEGORIES.map((category) => [category, 0]),
101
+ );
102
+
103
+ for (const [key, count] of Object.entries(hostPowerStates ?? {})) {
104
+ const mapped = HOST_POWER_KEY_ALIASES[normalizeKey(key)];
105
+ const label = mapped ?? formatUnknownLabel(key);
106
+ counts[label] = (counts[label] ?? 0) + (count || 0);
107
+ }
108
+
109
+ const orderedLabels = [
110
+ ...HOST_POWER_CATEGORIES,
111
+ ...Object.keys(counts).filter(
112
+ (label) => !HOST_POWER_CATEGORIES.includes(label as HostPowerCategory),
113
+ ),
114
+ ];
115
+
116
+ const slices = orderedLabels.map((label) =>
117
+ toSlice(label, counts[label] ?? 0, "hosts"),
118
+ );
119
+
120
+ const legend: Record<string, string> = {};
121
+ for (const label of orderedLabels) {
122
+ legend[label] = HOST_POWER_COLORS[label] ?? OTHER_COLOR;
123
+ }
124
+
125
+ return {
126
+ slices,
127
+ legend,
128
+ total: sumCounts(counts),
129
+ };
130
+ };
131
+
132
+ export const buildVmPowerStateChart = (
133
+ powerStates?: Record<string, number>,
134
+ ): PowerStateChartModel => {
135
+ const counts: Record<string, number> = {
136
+ "Powered off": 0,
137
+ "Powered on": 0,
138
+ };
139
+
140
+ for (const [key, count] of Object.entries(powerStates ?? {})) {
141
+ const mapped = VM_POWER_KEY_ALIASES[normalizeKey(key)];
142
+ const label = mapped ?? formatUnknownLabel(key);
143
+ counts[label] = (counts[label] ?? 0) + (count || 0);
144
+ }
145
+
146
+ const orderedLabels = [
147
+ ...VM_POWER_CATEGORIES.filter(
148
+ (category) => category !== "Suspended" || (counts[category] ?? 0) > 0,
149
+ ),
150
+ ...Object.keys(counts).filter(
151
+ (label) => !VM_POWER_CATEGORIES.includes(label as VmPowerCategory),
152
+ ),
153
+ ];
154
+
155
+ const slices = orderedLabels.map((label) =>
156
+ toSlice(label, counts[label] ?? 0, "VMs"),
157
+ );
158
+
159
+ const legend: Record<string, string> = {};
160
+ for (const label of orderedLabels) {
161
+ legend[label] = VM_POWER_COLORS[label] ?? OTHER_COLOR;
162
+ }
163
+
164
+ return {
165
+ slices,
166
+ legend,
167
+ total: sumCounts(counts),
168
+ };
169
+ };
@@ -0,0 +1,53 @@
1
+ export interface ReportExportOption {
2
+ key: string;
3
+ label: string;
4
+ description?: string;
5
+ onSelect: () => void;
6
+ isDisabled?: boolean;
7
+ }
8
+
9
+ export interface StandardReportExportHandlers {
10
+ onExportPdf?: () => void;
11
+ onExportPng?: () => void;
12
+ onExportHtml?: () => void;
13
+ }
14
+
15
+ /**
16
+ * Standard report-download actions. Omit a handler to hide that format.
17
+ */
18
+ export const standardReportExportOptions = ({
19
+ onExportPdf,
20
+ onExportPng,
21
+ onExportHtml,
22
+ }: StandardReportExportHandlers): ReportExportOption[] => {
23
+ const options: ReportExportOption[] = [];
24
+
25
+ if (onExportPdf) {
26
+ options.push({
27
+ key: "pdf",
28
+ label: "PDF",
29
+ description: "Export the report as a PDF",
30
+ onSelect: onExportPdf,
31
+ });
32
+ }
33
+
34
+ if (onExportHtml) {
35
+ options.push({
36
+ key: "html",
37
+ label: "HTML",
38
+ description: "Export the report as HTML",
39
+ onSelect: onExportHtml,
40
+ });
41
+ }
42
+
43
+ if (onExportPng) {
44
+ options.push({
45
+ key: "png",
46
+ label: "PNG",
47
+ description: "Download all charts as PNG files",
48
+ onSelect: onExportPng,
49
+ });
50
+ }
51
+
52
+ return options;
53
+ };
@@ -0,0 +1,10 @@
1
+ import JSZip from "jszip";
2
+ import type { ChartExportFile } from "./chartExport.js";
3
+
4
+ export async function zipChartPngs(files: ChartExportFile[]): Promise<Blob> {
5
+ const zip = new JSZip();
6
+ for (const file of files) {
7
+ zip.file(file.filename, file.blob);
8
+ }
9
+ return zip.generateAsync({ type: "blob", compression: "STORE" });
10
+ }