@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.
- 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/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/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/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 +2 -0
- package/dist/report/constants.d.ts.map +1 -1
- package/dist/report/constants.js +2 -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 +23 -0
- package/dist/report/index.d.ts.map +1 -1
- package/dist/report/index.js +21 -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/FeatureStatusBadge.tsx +30 -0
- package/src/report/HostPowerStates.tsx +38 -0
- package/src/report/InfrastructureSummary.tsx +73 -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/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__/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 +2 -0
- package/src/report/dashboardStyles.ts +0 -23
- package/src/report/htmlExport.ts +83 -0
- package/src/report/index.ts +128 -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
|
@@ -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,49 @@ export {
|
|
|
17
65
|
EmptySearchResults,
|
|
18
66
|
type EmptySearchResultsProps,
|
|
19
67
|
} from "./EmptySearchResults.js";
|
|
68
|
+
export {
|
|
69
|
+
FeatureStatusBadge,
|
|
70
|
+
type FeatureStatusBadgeProps,
|
|
71
|
+
} from "./FeatureStatusBadge.js";
|
|
72
|
+
export {
|
|
73
|
+
HostPowerStates,
|
|
74
|
+
type HostPowerStatesProps,
|
|
75
|
+
} from "./HostPowerStates.js";
|
|
76
|
+
export {
|
|
77
|
+
buildHtmlFromCharts,
|
|
78
|
+
buildHtmlReport,
|
|
79
|
+
escapeHtml,
|
|
80
|
+
type HtmlReportImage,
|
|
81
|
+
} from "./htmlExport.js";
|
|
82
|
+
export {
|
|
83
|
+
InfrastructureSummary,
|
|
84
|
+
type InfrastructureSummaryProps,
|
|
85
|
+
} from "./InfrastructureSummary.js";
|
|
86
|
+
export type {
|
|
87
|
+
ClusterDetailRow,
|
|
88
|
+
ClusterDetailsModel,
|
|
89
|
+
FeatureStatus,
|
|
90
|
+
HostCapability,
|
|
91
|
+
InfrastructureSummaryModel,
|
|
92
|
+
InventoryCluster,
|
|
93
|
+
InventoryDatastore,
|
|
94
|
+
InventoryHost,
|
|
95
|
+
InventoryInfra,
|
|
96
|
+
InventoryNetwork,
|
|
97
|
+
InventoryVms,
|
|
98
|
+
NetworkLabel,
|
|
99
|
+
} from "./infrastructureSummaryModel.js";
|
|
100
|
+
export {
|
|
101
|
+
booleanToFeatureStatus,
|
|
102
|
+
buildClusterDetailRows,
|
|
103
|
+
buildClusterDetails,
|
|
104
|
+
buildInfrastructureSummary,
|
|
105
|
+
countVCenters,
|
|
106
|
+
formatVSphereVersion,
|
|
107
|
+
hostCapabilityStatus,
|
|
108
|
+
visibleNetworks,
|
|
109
|
+
vsanStatus,
|
|
110
|
+
} from "./infrastructureSummaryModel.js";
|
|
20
111
|
export { OSBarChart, OSDistribution } from "./OSDistribution.js";
|
|
21
112
|
export { OsSupportTiersHelpPopover } from "./OsSupportTiersHelpPopover.js";
|
|
22
113
|
export { OsUpgradeNotice } from "./OsUpgradeNotice.js";
|
|
@@ -45,6 +136,34 @@ export {
|
|
|
45
136
|
SupportTier,
|
|
46
137
|
} from "./osSupportTier.js";
|
|
47
138
|
export { default as PopoverIcon } from "./PopoverIcon.js";
|
|
139
|
+
export {
|
|
140
|
+
PowerStateCard,
|
|
141
|
+
type PowerStateCardProps,
|
|
142
|
+
} from "./PowerStateCard.js";
|
|
143
|
+
export { buildPdfFromCharts } from "./pdfExport.js";
|
|
144
|
+
export {
|
|
145
|
+
type PdfExportSegment,
|
|
146
|
+
sliceCanvas,
|
|
147
|
+
splitSegmentForPageHeight,
|
|
148
|
+
} from "./pdfPage.js";
|
|
149
|
+
export type { PowerStateChartModel } from "./powerStates.js";
|
|
150
|
+
export {
|
|
151
|
+
buildHostPowerStateChart,
|
|
152
|
+
buildVmPowerStateChart,
|
|
153
|
+
HOST_POWER_COLORS,
|
|
154
|
+
VM_POWER_COLORS,
|
|
155
|
+
} from "./powerStates.js";
|
|
156
|
+
export {
|
|
157
|
+
ExportReportButton,
|
|
158
|
+
type ExportReportButtonProps,
|
|
159
|
+
ReportExportMenu,
|
|
160
|
+
type ReportExportMenuProps,
|
|
161
|
+
} from "./ReportExportMenu.js";
|
|
162
|
+
export {
|
|
163
|
+
type ReportExportOption,
|
|
164
|
+
type StandardReportExportHandlers,
|
|
165
|
+
standardReportExportOptions,
|
|
166
|
+
} from "./reportExportOptions.js";
|
|
48
167
|
export { SupportTierBadge } from "./SupportTierBadge.js";
|
|
49
168
|
export {
|
|
50
169
|
ALL_TIERS_FILTER,
|
|
@@ -52,3 +171,12 @@ export {
|
|
|
52
171
|
type OsTableRow,
|
|
53
172
|
useOsBarChartViewModel,
|
|
54
173
|
} from "./useOsBarChartViewModel.js";
|
|
174
|
+
export {
|
|
175
|
+
VCenterClusterDetails,
|
|
176
|
+
type VCenterClusterDetailsProps,
|
|
177
|
+
} from "./VCenterClusterDetails.js";
|
|
178
|
+
export {
|
|
179
|
+
VmPowerStates,
|
|
180
|
+
type VmPowerStatesProps,
|
|
181
|
+
} from "./VmPowerStates.js";
|
|
182
|
+
export { zipChartPngs } from "./zipChartPngs.js";
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
export type FeatureStatus = "enabled" | "disabled" | "unknown";
|
|
2
|
+
|
|
3
|
+
export type HostCapability = "vmotionSupported" | "storageVmotionSupported";
|
|
4
|
+
|
|
5
|
+
export type InventoryHost = {
|
|
6
|
+
vmotionSupported?: boolean;
|
|
7
|
+
storageVmotionSupported?: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type InventoryDatastore = {
|
|
11
|
+
type?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type InventoryNetwork = {
|
|
15
|
+
name: string;
|
|
16
|
+
type?: string;
|
|
17
|
+
vlanId?: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type InventoryInfra = {
|
|
21
|
+
totalHosts?: number;
|
|
22
|
+
totalDatacenters?: number;
|
|
23
|
+
hosts?: InventoryHost[];
|
|
24
|
+
clustersPerDatacenter?: number[];
|
|
25
|
+
networks?: InventoryNetwork[];
|
|
26
|
+
datastores?: InventoryDatastore[];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type InventoryVms = {
|
|
30
|
+
total?: number;
|
|
31
|
+
diskTypes?: Record<string, unknown>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type InventoryCluster = {
|
|
35
|
+
infra?: InventoryInfra;
|
|
36
|
+
vms?: InventoryVms;
|
|
37
|
+
vcenter?: { id?: string };
|
|
38
|
+
clusterFeatures?: {
|
|
39
|
+
drsEnabled?: boolean;
|
|
40
|
+
haEnabled?: boolean;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type InfrastructureSummaryModel = {
|
|
45
|
+
vmwareVersion: string;
|
|
46
|
+
datacenters: number | undefined;
|
|
47
|
+
vCenters: number | undefined;
|
|
48
|
+
esxiHosts: number | undefined;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type NetworkLabel = {
|
|
52
|
+
name: string;
|
|
53
|
+
vlanId?: string;
|
|
54
|
+
displayName: string;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type ClusterDetailRow = {
|
|
58
|
+
id: string;
|
|
59
|
+
name: string;
|
|
60
|
+
hosts: number;
|
|
61
|
+
vms: number;
|
|
62
|
+
vmotion: FeatureStatus;
|
|
63
|
+
drs: FeatureStatus;
|
|
64
|
+
vsan: FeatureStatus;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type ClusterDetailsModel = {
|
|
68
|
+
hosts: number;
|
|
69
|
+
vms: number;
|
|
70
|
+
networksDetected: number;
|
|
71
|
+
vmotion: FeatureStatus;
|
|
72
|
+
drs: FeatureStatus;
|
|
73
|
+
ha: FeatureStatus;
|
|
74
|
+
vsan: FeatureStatus;
|
|
75
|
+
networks: NetworkLabel[];
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const VSAN_TYPE_PATTERN = /vsan/i;
|
|
79
|
+
|
|
80
|
+
export const formatVSphereVersion = (version?: string): string => {
|
|
81
|
+
if (!version?.trim()) {
|
|
82
|
+
return "—";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const withoutPrefix = version.trim().replace(/^vSphere\s+/i, "");
|
|
86
|
+
const parts = withoutPrefix.split(".");
|
|
87
|
+
while (parts.length > 3 && parts[parts.length - 1] === "0") {
|
|
88
|
+
parts.pop();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return `vSphere ${parts.join(".")}`;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const booleanToFeatureStatus = (
|
|
95
|
+
value: boolean | undefined,
|
|
96
|
+
): FeatureStatus => {
|
|
97
|
+
if (value === true) {
|
|
98
|
+
return "enabled";
|
|
99
|
+
}
|
|
100
|
+
if (value === false) {
|
|
101
|
+
return "disabled";
|
|
102
|
+
}
|
|
103
|
+
return "unknown";
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const hostCapabilityStatus = (
|
|
107
|
+
hosts: InventoryHost[] | undefined,
|
|
108
|
+
capability: HostCapability,
|
|
109
|
+
): FeatureStatus => {
|
|
110
|
+
if (!hosts || hosts.length === 0) {
|
|
111
|
+
return "unknown";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const known = hosts
|
|
115
|
+
.map((host) => host[capability])
|
|
116
|
+
.filter((value): value is boolean => typeof value === "boolean");
|
|
117
|
+
|
|
118
|
+
if (known.length === 0) {
|
|
119
|
+
return "unknown";
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return known.some(Boolean) ? "enabled" : "disabled";
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export const vsanStatus = (
|
|
126
|
+
infra?: InventoryInfra,
|
|
127
|
+
vms?: InventoryVms,
|
|
128
|
+
): FeatureStatus => {
|
|
129
|
+
const datastoreMatch = infra?.datastores?.some((datastore) =>
|
|
130
|
+
VSAN_TYPE_PATTERN.test(datastore.type ?? ""),
|
|
131
|
+
);
|
|
132
|
+
const diskTypeMatch = Object.keys(vms?.diskTypes ?? {}).some((type) =>
|
|
133
|
+
VSAN_TYPE_PATTERN.test(type),
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
if (datastoreMatch || diskTypeMatch) {
|
|
137
|
+
return "enabled";
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (infra?.datastores || vms?.diskTypes) {
|
|
141
|
+
return "disabled";
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return "unknown";
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const hostCount = (infra?: InventoryInfra): number | undefined => {
|
|
148
|
+
if (typeof infra?.totalHosts === "number") {
|
|
149
|
+
return infra.totalHosts;
|
|
150
|
+
}
|
|
151
|
+
if (infra?.hosts) {
|
|
152
|
+
return infra.hosts.length;
|
|
153
|
+
}
|
|
154
|
+
return undefined;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const datacenterCount = (infra?: InventoryInfra): number | undefined => {
|
|
158
|
+
if (typeof infra?.totalDatacenters === "number") {
|
|
159
|
+
return infra.totalDatacenters;
|
|
160
|
+
}
|
|
161
|
+
if (infra?.clustersPerDatacenter && infra.clustersPerDatacenter.length > 0) {
|
|
162
|
+
return infra.clustersPerDatacenter.length;
|
|
163
|
+
}
|
|
164
|
+
return undefined;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export const countVCenters = (
|
|
168
|
+
clusters?: Record<string, InventoryCluster>,
|
|
169
|
+
vcenterId?: string,
|
|
170
|
+
): number | undefined => {
|
|
171
|
+
const ids = new Set<string>();
|
|
172
|
+
if (vcenterId) {
|
|
173
|
+
ids.add(vcenterId);
|
|
174
|
+
}
|
|
175
|
+
for (const cluster of Object.values(clusters ?? {})) {
|
|
176
|
+
if (cluster.vcenter?.id) {
|
|
177
|
+
ids.add(cluster.vcenter.id);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return ids.size > 0 ? ids.size : undefined;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const toNetworkLabel = (network: InventoryNetwork): NetworkLabel => {
|
|
184
|
+
const vlanId = network.vlanId?.trim();
|
|
185
|
+
return {
|
|
186
|
+
name: network.name,
|
|
187
|
+
vlanId: vlanId || undefined,
|
|
188
|
+
displayName: vlanId ? `${network.name} (VLAN ${vlanId})` : network.name,
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export const visibleNetworks = (infra?: InventoryInfra): NetworkLabel[] =>
|
|
193
|
+
(infra?.networks ?? [])
|
|
194
|
+
.filter(
|
|
195
|
+
(network) => Boolean(network.name?.trim()) && network.type !== "dvswitch",
|
|
196
|
+
)
|
|
197
|
+
.map(toNetworkLabel);
|
|
198
|
+
|
|
199
|
+
export const buildInfrastructureSummary = ({
|
|
200
|
+
infra,
|
|
201
|
+
vcenterVersion,
|
|
202
|
+
vcenterId,
|
|
203
|
+
clusters,
|
|
204
|
+
}: {
|
|
205
|
+
infra?: InventoryInfra;
|
|
206
|
+
vcenterVersion?: string;
|
|
207
|
+
vcenterId?: string;
|
|
208
|
+
clusters?: Record<string, InventoryCluster>;
|
|
209
|
+
}): InfrastructureSummaryModel => ({
|
|
210
|
+
vmwareVersion: formatVSphereVersion(vcenterVersion),
|
|
211
|
+
datacenters: datacenterCount(infra),
|
|
212
|
+
vCenters: countVCenters(clusters, vcenterId),
|
|
213
|
+
esxiHosts: hostCount(infra),
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
const clusterFeatureStatus = (
|
|
217
|
+
cluster: InventoryCluster,
|
|
218
|
+
): Pick<ClusterDetailRow, "vmotion" | "drs" | "vsan"> & {
|
|
219
|
+
ha: FeatureStatus;
|
|
220
|
+
} => ({
|
|
221
|
+
vmotion: hostCapabilityStatus(cluster.infra?.hosts, "vmotionSupported"),
|
|
222
|
+
drs: booleanToFeatureStatus(cluster.clusterFeatures?.drsEnabled),
|
|
223
|
+
ha: booleanToFeatureStatus(cluster.clusterFeatures?.haEnabled),
|
|
224
|
+
vsan: vsanStatus(cluster.infra, cluster.vms),
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
const compareClustersByVmCount = (
|
|
228
|
+
a: string,
|
|
229
|
+
b: string,
|
|
230
|
+
clusters: Record<string, InventoryCluster>,
|
|
231
|
+
): number => {
|
|
232
|
+
const vmsA = clusters[a]?.vms?.total ?? 0;
|
|
233
|
+
const vmsB = clusters[b]?.vms?.total ?? 0;
|
|
234
|
+
return vmsB - vmsA || a.localeCompare(b);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export const buildClusterDetailRows = (
|
|
238
|
+
clusters?: Record<string, InventoryCluster>,
|
|
239
|
+
): ClusterDetailRow[] => {
|
|
240
|
+
if (!clusters) {
|
|
241
|
+
return [];
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return Object.keys(clusters)
|
|
245
|
+
.sort((a, b) => compareClustersByVmCount(a, b, clusters))
|
|
246
|
+
.map((id) => {
|
|
247
|
+
const cluster = clusters[id];
|
|
248
|
+
const features = clusterFeatureStatus(cluster);
|
|
249
|
+
return {
|
|
250
|
+
id,
|
|
251
|
+
name: id,
|
|
252
|
+
hosts: hostCount(cluster.infra) ?? 0,
|
|
253
|
+
vms: cluster.vms?.total ?? 0,
|
|
254
|
+
vmotion: features.vmotion,
|
|
255
|
+
drs: features.drs,
|
|
256
|
+
vsan: features.vsan,
|
|
257
|
+
};
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
export const buildClusterDetails = (
|
|
262
|
+
cluster?: InventoryCluster,
|
|
263
|
+
): ClusterDetailsModel | undefined => {
|
|
264
|
+
if (!cluster) {
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const networks = visibleNetworks(cluster.infra);
|
|
269
|
+
const features = clusterFeatureStatus(cluster);
|
|
270
|
+
|
|
271
|
+
return {
|
|
272
|
+
hosts: hostCount(cluster.infra) ?? 0,
|
|
273
|
+
vms: cluster.vms?.total ?? 0,
|
|
274
|
+
networksDetected: networks.length,
|
|
275
|
+
vmotion: features.vmotion,
|
|
276
|
+
drs: features.drs,
|
|
277
|
+
ha: features.ha,
|
|
278
|
+
vsan: features.vsan,
|
|
279
|
+
networks,
|
|
280
|
+
};
|
|
281
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import jsPDF from "jspdf";
|
|
2
|
+
import { type ChartCaptureSource, releaseCanvas } from "./chartExport.js";
|
|
3
|
+
import { fitPdfImageSize, placePdfBlock, sliceCanvas } from "./pdfPage.js";
|
|
4
|
+
|
|
5
|
+
const MARGIN_MM = 10;
|
|
6
|
+
const GAP_MM = 8;
|
|
7
|
+
/** Flatten captures onto white; jsPDF cannot embed transparent PNG alpha cleanly. */
|
|
8
|
+
const PAGE_BACKGROUND = "#ffffff";
|
|
9
|
+
|
|
10
|
+
export async function buildPdfFromCharts(
|
|
11
|
+
charts: ChartCaptureSource[],
|
|
12
|
+
documentTitle: string,
|
|
13
|
+
): Promise<Blob> {
|
|
14
|
+
const pdf = new jsPDF("p", "mm", "a4");
|
|
15
|
+
const pageWidth = pdf.internal.pageSize.getWidth();
|
|
16
|
+
const pageHeight = pdf.internal.pageSize.getHeight();
|
|
17
|
+
const contentWidth = pageWidth - MARGIN_MM * 2;
|
|
18
|
+
const contentHeight = pageHeight - MARGIN_MM * 2;
|
|
19
|
+
const pageTop = MARGIN_MM;
|
|
20
|
+
const pageBottom = pageHeight - MARGIN_MM;
|
|
21
|
+
|
|
22
|
+
addCoverPage(
|
|
23
|
+
pdf,
|
|
24
|
+
documentTitle,
|
|
25
|
+
charts.map((chart) => chart.title),
|
|
26
|
+
pageWidth,
|
|
27
|
+
pageHeight,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
let cursorY: number | null = null;
|
|
31
|
+
for (const chart of charts) {
|
|
32
|
+
const canvas = await chart.capture();
|
|
33
|
+
try {
|
|
34
|
+
if (canvas.width < 1 || canvas.height < 1) {
|
|
35
|
+
throw new Error("Chart capture produced an empty image");
|
|
36
|
+
}
|
|
37
|
+
const size = fitPdfImageSize(
|
|
38
|
+
canvas.width,
|
|
39
|
+
canvas.height,
|
|
40
|
+
contentWidth,
|
|
41
|
+
contentHeight,
|
|
42
|
+
);
|
|
43
|
+
const placement = placePdfBlock(
|
|
44
|
+
cursorY,
|
|
45
|
+
size.heightMm,
|
|
46
|
+
pageTop,
|
|
47
|
+
pageBottom,
|
|
48
|
+
);
|
|
49
|
+
if (placement.needsNewPage) {
|
|
50
|
+
pdf.addPage();
|
|
51
|
+
}
|
|
52
|
+
addChartImage(
|
|
53
|
+
pdf,
|
|
54
|
+
canvas,
|
|
55
|
+
MARGIN_MM + (contentWidth - size.widthMm) / 2,
|
|
56
|
+
placement.y,
|
|
57
|
+
size.widthMm,
|
|
58
|
+
size.heightMm,
|
|
59
|
+
);
|
|
60
|
+
cursorY = placement.y + size.heightMm + GAP_MM;
|
|
61
|
+
} finally {
|
|
62
|
+
releaseCanvas(canvas);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
addPageNumbers(pdf, pageWidth, pageHeight);
|
|
67
|
+
return pdf.output("blob");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function addCoverPage(
|
|
71
|
+
pdf: jsPDF,
|
|
72
|
+
documentTitle: string,
|
|
73
|
+
tocItems: string[],
|
|
74
|
+
pageWidth: number,
|
|
75
|
+
pageHeight: number,
|
|
76
|
+
): void {
|
|
77
|
+
const contentWidth = pageWidth - MARGIN_MM * 2;
|
|
78
|
+
pdf.setFontSize(18);
|
|
79
|
+
const titleLines = pdf.splitTextToSize(
|
|
80
|
+
documentTitle,
|
|
81
|
+
contentWidth,
|
|
82
|
+
) as string[];
|
|
83
|
+
let titleY = MARGIN_MM + 8;
|
|
84
|
+
for (const line of titleLines) {
|
|
85
|
+
pdf.text(line, pageWidth / 2, titleY, { align: "center" });
|
|
86
|
+
titleY += 8;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
pdf.setFontSize(11);
|
|
90
|
+
const generatedAt = new Date();
|
|
91
|
+
pdf.text(
|
|
92
|
+
`Generated: ${generatedAt.toLocaleDateString()} ${generatedAt.toLocaleTimeString()}`,
|
|
93
|
+
pageWidth / 2,
|
|
94
|
+
titleY + 4,
|
|
95
|
+
{ align: "center" },
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
pdf.setFontSize(14);
|
|
99
|
+
pdf.text("Table of contents", MARGIN_MM, titleY + 16);
|
|
100
|
+
pdf.setFontSize(11);
|
|
101
|
+
let tocY = titleY + 26;
|
|
102
|
+
for (const item of tocItems) {
|
|
103
|
+
if (tocY > pageHeight - MARGIN_MM - 10) {
|
|
104
|
+
pdf.addPage();
|
|
105
|
+
tocY = MARGIN_MM;
|
|
106
|
+
}
|
|
107
|
+
pdf.text(`- ${item}`, MARGIN_MM, tocY);
|
|
108
|
+
tocY += 7;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function addChartImage(
|
|
113
|
+
pdf: jsPDF,
|
|
114
|
+
canvas: HTMLCanvasElement,
|
|
115
|
+
x: number,
|
|
116
|
+
y: number,
|
|
117
|
+
widthMm: number,
|
|
118
|
+
heightMm: number,
|
|
119
|
+
): void {
|
|
120
|
+
const flattened = sliceCanvas(
|
|
121
|
+
canvas,
|
|
122
|
+
canvas.width,
|
|
123
|
+
canvas.height,
|
|
124
|
+
0,
|
|
125
|
+
PAGE_BACKGROUND,
|
|
126
|
+
);
|
|
127
|
+
try {
|
|
128
|
+
pdf.addImage(
|
|
129
|
+
flattened.toDataURL("image/jpeg", 0.92),
|
|
130
|
+
"JPEG",
|
|
131
|
+
x,
|
|
132
|
+
y,
|
|
133
|
+
widthMm,
|
|
134
|
+
heightMm,
|
|
135
|
+
);
|
|
136
|
+
} finally {
|
|
137
|
+
releaseCanvas(flattened);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function addPageNumbers(
|
|
142
|
+
pdf: jsPDF,
|
|
143
|
+
pageWidth: number,
|
|
144
|
+
pageHeight: number,
|
|
145
|
+
): void {
|
|
146
|
+
const totalPages = pdf.getNumberOfPages();
|
|
147
|
+
pdf.setFontSize(9);
|
|
148
|
+
for (let page = 1; page <= totalPages; page++) {
|
|
149
|
+
pdf.setPage(page);
|
|
150
|
+
pdf.text(`Page ${page} of ${totalPages}`, pageWidth / 2, pageHeight - 6, {
|
|
151
|
+
align: "center",
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|