@openshift-migration-advisor/shared-components 0.25.0-fce5293f01c1 → 0.27.0-6438cd962b5f

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 (42) hide show
  1. package/dist/report/ChartExportProvider.d.ts +3 -2
  2. package/dist/report/ChartExportProvider.d.ts.map +1 -1
  3. package/dist/report/ChartExportProvider.js +3 -3
  4. package/dist/report/ErrorTable.d.ts +18 -0
  5. package/dist/report/ErrorTable.d.ts.map +1 -0
  6. package/dist/report/ErrorTable.js +20 -0
  7. package/dist/report/HostsOverview.d.ts +13 -0
  8. package/dist/report/HostsOverview.d.ts.map +1 -0
  9. package/dist/report/HostsOverview.js +84 -0
  10. package/dist/report/ReportTable.d.ts +14 -0
  11. package/dist/report/ReportTable.d.ts.map +1 -0
  12. package/dist/report/ReportTable.js +23 -0
  13. package/dist/report/WarningsTable.d.ts +9 -0
  14. package/dist/report/WarningsTable.d.ts.map +1 -0
  15. package/dist/report/WarningsTable.js +20 -0
  16. package/dist/report/chartExport.d.ts +16 -0
  17. package/dist/report/chartExport.d.ts.map +1 -1
  18. package/dist/report/chartExportContext.d.ts +6 -2
  19. package/dist/report/chartExportContext.d.ts.map +1 -1
  20. package/dist/report/constants.d.ts +2 -0
  21. package/dist/report/constants.d.ts.map +1 -1
  22. package/dist/report/constants.js +2 -0
  23. package/dist/report/index.d.ts +6 -2
  24. package/dist/report/index.d.ts.map +1 -1
  25. package/dist/report/index.js +4 -0
  26. package/dist/report/pdfExport.d.ts +2 -2
  27. package/dist/report/pdfExport.d.ts.map +1 -1
  28. package/dist/report/pdfExport.js +52 -3
  29. package/package.json +2 -2
  30. package/src/report/ChartExportProvider.tsx +13 -5
  31. package/src/report/ErrorTable.tsx +85 -0
  32. package/src/report/HostsOverview.tsx +185 -0
  33. package/src/report/ReportTable.tsx +81 -0
  34. package/src/report/WarningsTable.tsx +75 -0
  35. package/src/report/__tests__/ChartExportProvider.test.tsx +70 -2
  36. package/src/report/__tests__/HostsOverview.test.tsx +145 -0
  37. package/src/report/__tests__/chartExportPackagers.test.ts +58 -0
  38. package/src/report/chartExport.ts +18 -0
  39. package/src/report/chartExportContext.tsx +9 -1
  40. package/src/report/constants.ts +2 -0
  41. package/src/report/index.ts +18 -0
  42. package/src/report/pdfExport.ts +81 -2
@@ -0,0 +1,145 @@
1
+ import "@testing-library/jest-dom";
2
+ import {
3
+ chart_color_blue_300,
4
+ chart_color_green_300,
5
+ chart_color_purple_100,
6
+ chart_color_purple_300,
7
+ chart_color_teal_200,
8
+ chart_color_yellow_400,
9
+ } from "@patternfly/react-tokens";
10
+ import { cleanup, render, screen } from "@testing-library/react";
11
+ import { afterEach, describe, expect, it, vi } from "vitest";
12
+ import type { MigrationDonutChartProps } from "../../charts/MigrationDonutChart.js";
13
+ import { HostsOverview } from "../HostsOverview.js";
14
+
15
+ const donutProps = vi.hoisted(() => ({
16
+ current: null as MigrationDonutChartProps | null,
17
+ }));
18
+
19
+ vi.mock("../../charts/MigrationDonutChart.js", () => ({
20
+ MigrationDonutChart: (props: MigrationDonutChartProps): JSX.Element => {
21
+ donutProps.current = props;
22
+ return (
23
+ <div data-testid="hosts-donut">
24
+ {props.title} {props.subTitle}
25
+ </div>
26
+ );
27
+ },
28
+ }));
29
+
30
+ afterEach(() => {
31
+ donutProps.current = null;
32
+ cleanup();
33
+ });
34
+
35
+ const renderedDonut = (): MigrationDonutChartProps => {
36
+ const props = donutProps.current;
37
+ if (!props) {
38
+ throw new Error("expected the host model donut to render");
39
+ }
40
+ return props;
41
+ };
42
+
43
+ describe("HostsOverview", () => {
44
+ it("shows the shared empty state when no hosts are available", () => {
45
+ render(<HostsOverview />);
46
+
47
+ expect(screen.getByText("Host distribution by model")).toBeInTheDocument();
48
+ expect(screen.getByText("Top 5 models")).toBeInTheDocument();
49
+ expect(screen.getByText("Host data not collected")).toBeInTheDocument();
50
+ expect(screen.queryByTestId("hosts-donut")).not.toBeInTheDocument();
51
+ });
52
+
53
+ it("buckets host counts into the top 5 models plus Other models", () => {
54
+ render(
55
+ <HostsOverview
56
+ hosts={[
57
+ { model: "M1" },
58
+ { model: "M1" },
59
+ { model: "M1" },
60
+ { model: "M1" },
61
+ { model: "M1" },
62
+ { model: "M1" },
63
+ { model: "M2" },
64
+ { model: "M2" },
65
+ { model: "M2" },
66
+ { model: "M2" },
67
+ { model: "M2" },
68
+ { model: "M3" },
69
+ { model: "M3" },
70
+ { model: "M3" },
71
+ { model: "M3" },
72
+ { model: "M4" },
73
+ { model: "M4" },
74
+ { model: "M4" },
75
+ { model: "M5" },
76
+ { model: "M5" },
77
+ { model: "M6" },
78
+ { model: "M7" },
79
+ ]}
80
+ />,
81
+ );
82
+
83
+ expect(screen.getByTestId("hosts-donut")).toHaveTextContent("22 Hosts");
84
+
85
+ const props = renderedDonut();
86
+ expect(props.data.map((slice) => [slice.name, slice.count])).toEqual([
87
+ ["M1", 6],
88
+ ["M2", 5],
89
+ ["M3", 4],
90
+ ["M4", 3],
91
+ ["M5", 2],
92
+ ["Other models", 2],
93
+ ]);
94
+ expect(props.data[5]?.countDisplay).toBe("2 hosts");
95
+ expect(props.legend).toEqual({
96
+ M1: chart_color_blue_300.value,
97
+ M2: chart_color_purple_300.value,
98
+ M3: chart_color_purple_100.value,
99
+ M4: chart_color_teal_200.value,
100
+ M5: chart_color_yellow_400.value,
101
+ "Other models": chart_color_green_300.value,
102
+ });
103
+ expect(props.legendVariant).toBe("html");
104
+ expect(props.height).toBe(300);
105
+ expect(props.width).toBe(420);
106
+ expect(props.donutThickness).toBe(18);
107
+ expect(props.titleFontSize).toBe(34);
108
+ expect(props.legendWidth).toBe(680);
109
+ expect(props.itemsPerRow).toBe(2);
110
+ expect(props.labelFontSize).toBe(16);
111
+ expect(props.marginLeft).toBe("0%");
112
+ expect(props.subTitleColor).toBe(
113
+ "var(--pf-t--global--text--color--subtle)",
114
+ );
115
+ expect(
116
+ props.tooltipLabelFormatter?.({
117
+ datum: {
118
+ x: "M1",
119
+ y: 6,
120
+ countDisplay: "6 hosts",
121
+ legendCategory: "M1",
122
+ },
123
+ percent: 27.2727,
124
+ total: 22,
125
+ }),
126
+ ).toBe("6 hosts\n27.3%");
127
+ });
128
+
129
+ it("treats numeric models as labels and blank models as unknown", () => {
130
+ render(
131
+ <HostsOverview
132
+ legendVariant="chart"
133
+ hosts={[{ model: 42 }, { model: " " }, { model: " R640 " }]}
134
+ />,
135
+ );
136
+
137
+ expect(renderedDonut().data.map((slice) => slice.name)).toEqual([
138
+ "42",
139
+ "Unknown model",
140
+ "R640",
141
+ ]);
142
+ expect(renderedDonut().legendVariant).toBe("chart");
143
+ expect(renderedDonut().title).toBe("3");
144
+ });
145
+ });
@@ -7,6 +7,7 @@ import {
7
7
  } from "../chartExport.js";
8
8
  import { getChartExportFilename } from "../chartExportFilenames.js";
9
9
  import { buildHtmlReport, escapeHtml } from "../htmlExport.js";
10
+ import { buildPdfFromCharts } from "../pdfExport.js";
10
11
  import {
11
12
  fitPdfImageSize,
12
13
  placePdfBlock,
@@ -198,6 +199,63 @@ describe("placePdfBlock", () => {
198
199
  });
199
200
  });
200
201
 
202
+ describe("buildPdfFromCharts with extra text pages", () => {
203
+ it("appends a text page even when there are no chart captures", async () => {
204
+ const blob = await buildPdfFromCharts([], "Report", [
205
+ {
206
+ title: "Cluster sizing recommendations",
207
+ items: [
208
+ { label: "Cluster name", value: "cluster-1" },
209
+ { label: "Target platform", value: "Bare metal" },
210
+ {
211
+ label: "Total nodes",
212
+ value: "6 (3 workers + 3 control plane)",
213
+ },
214
+ { label: "Failover capacity", value: "1 failover nodes" },
215
+ { label: "Worker node size", value: "8 CPU, 32 GB memory" },
216
+ {
217
+ label: "Control plane node size",
218
+ value: "16 CPU, 64 GB memory",
219
+ },
220
+ ],
221
+ footer: "Note: estimates only.",
222
+ },
223
+ ]);
224
+
225
+ expect(blob).toBeInstanceOf(Blob);
226
+ expect(blob.size).toBeGreaterThan(0);
227
+ expect(blob.type).toBe("application/pdf");
228
+ });
229
+
230
+ it("paginates extra pages with many rows without throwing", async () => {
231
+ const manyItems = Array.from({ length: 60 }, (_, index) => ({
232
+ label: `Field ${index}`,
233
+ value: `Value ${index}`,
234
+ }));
235
+
236
+ const blob = await buildPdfFromCharts([], "Report", [
237
+ { title: "Cluster sizing recommendations", items: manyItems },
238
+ ]);
239
+
240
+ expect(blob.size).toBeGreaterThan(0);
241
+ });
242
+
243
+ it("supports multiple extra pages (e.g. one per sized cluster)", async () => {
244
+ const blob = await buildPdfFromCharts([], "Report", [
245
+ {
246
+ title: "Cluster sizing recommendations — cluster-a",
247
+ items: [{ label: "Cluster name", value: "cluster-a" }],
248
+ },
249
+ {
250
+ title: "Cluster sizing recommendations — cluster-b",
251
+ items: [{ label: "Cluster name", value: "cluster-b" }],
252
+ },
253
+ ]);
254
+
255
+ expect(blob.size).toBeGreaterThan(0);
256
+ });
257
+ });
258
+
201
259
  describe("buildHtmlReport", () => {
202
260
  it("embeds captured chart images and escapes the title", () => {
203
261
  const html = buildHtmlReport(
@@ -51,6 +51,24 @@ export type ChartCaptureSource = {
51
51
  capture: () => Promise<HTMLCanvasElement>;
52
52
  };
53
53
 
54
+ /** One label/value row rendered on a {@link PdfTextPage}. */
55
+ export type PdfTextPageItem = {
56
+ label: string;
57
+ value: string;
58
+ };
59
+
60
+ /**
61
+ * A native-text PDF page appended after the captured chart images.
62
+ *
63
+ * Used for content that is not a chart/card (e.g. calculated recommendations)
64
+ * but still needs to be part of the exported PDF.
65
+ */
66
+ export type PdfTextPage = {
67
+ title: string;
68
+ items: PdfTextPageItem[];
69
+ footer?: string;
70
+ };
71
+
54
72
  export function releaseCanvas(canvas: HTMLCanvasElement): void {
55
73
  canvas.width = 0;
56
74
  canvas.height = 0;
@@ -9,6 +9,7 @@ import {
9
9
  type ChartExportMeta,
10
10
  type ChartExportView,
11
11
  chartPngFilename,
12
+ type PdfTextPage,
12
13
  type RegisteredChart,
13
14
  } from "./chartExport.js";
14
15
 
@@ -17,7 +18,14 @@ export type ChartExportFormat = "pdf" | "png" | "html";
17
18
  export type ChartExportApi = {
18
19
  downloadChart: (id: string) => Promise<void>;
19
20
  downloadAll: () => Promise<void>;
20
- downloadPdf: (documentTitle: string) => Promise<void>;
21
+ /**
22
+ * @param extraPages - Native-text pages appended after the captured chart
23
+ * images (e.g. calculated recommendations that aren't rendered as charts).
24
+ */
25
+ downloadPdf: (
26
+ documentTitle: string,
27
+ extraPages?: PdfTextPage[],
28
+ ) => Promise<void>;
21
29
  downloadHtml: (documentTitle: string) => Promise<void>;
22
30
  downloadingChartId: string | null;
23
31
  exportingFormat: ChartExportFormat | null;
@@ -25,6 +25,8 @@ 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
+ warnings: "Warning data not collected",
28
30
  hostPowerStates: "Host power state data not collected",
29
31
  vmPowerStates: "VM power state data not collected",
30
32
  } as const;
@@ -9,6 +9,7 @@ export {
9
9
  } from "./ChartDownloadButton.js";
10
10
  export {
11
11
  type BuildChartDocument,
12
+ type BuildPdfDocument,
12
13
  type CaptureChartElement,
13
14
  ChartExportProvider,
14
15
  type ChartExportProviderProps,
@@ -32,6 +33,8 @@ export {
32
33
  chartExportViewsFromLabels,
33
34
  chartPngFilename,
34
35
  downloadBlob,
36
+ type PdfTextPage,
37
+ type PdfTextPageItem,
35
38
  type RegisteredChart,
36
39
  releaseCanvas,
37
40
  restoreChartExportViews,
@@ -65,6 +68,11 @@ export {
65
68
  EmptySearchResults,
66
69
  type EmptySearchResultsProps,
67
70
  } from "./EmptySearchResults.js";
71
+ export {
72
+ ErrorTable,
73
+ type ErrorTableProps,
74
+ type MigrationIssueLike,
75
+ } from "./ErrorTable.js";
68
76
  export {
69
77
  FeatureStatusBadge,
70
78
  type FeatureStatusBadgeProps,
@@ -73,6 +81,11 @@ export {
73
81
  HostPowerStates,
74
82
  type HostPowerStatesProps,
75
83
  } from "./HostPowerStates.js";
84
+ export {
85
+ type HostLike,
86
+ HostsOverview,
87
+ type HostsOverviewProps,
88
+ } from "./HostsOverview.js";
76
89
  export {
77
90
  buildHtmlFromCharts,
78
91
  buildHtmlReport,
@@ -167,6 +180,7 @@ export {
167
180
  ReportExportMenu,
168
181
  type ReportExportMenuProps,
169
182
  } from "./ReportExportMenu.js";
183
+ export { ReportTable, type ReportTableProps } from "./ReportTable.js";
170
184
  export {
171
185
  type ReportExportOption,
172
186
  type StandardReportExportHandlers,
@@ -187,4 +201,8 @@ export {
187
201
  VmPowerStates,
188
202
  type VmPowerStatesProps,
189
203
  } from "./VmPowerStates.js";
204
+ export {
205
+ WarningsTable,
206
+ type WarningsTableProps,
207
+ } from "./WarningsTable.js";
190
208
  export { zipChartPngs } from "./zipChartPngs.js";
@@ -1,5 +1,9 @@
1
1
  import jsPDF from "jspdf";
2
- import { type ChartCaptureSource, releaseCanvas } from "./chartExport.js";
2
+ import {
3
+ type ChartCaptureSource,
4
+ type PdfTextPage,
5
+ releaseCanvas,
6
+ } from "./chartExport.js";
3
7
  import { fitPdfImageSize, placePdfBlock, sliceCanvas } from "./pdfPage.js";
4
8
 
5
9
  const MARGIN_MM = 10;
@@ -10,6 +14,7 @@ const PAGE_BACKGROUND = "#ffffff";
10
14
  export async function buildPdfFromCharts(
11
15
  charts: ChartCaptureSource[],
12
16
  documentTitle: string,
17
+ extraPages: PdfTextPage[] = [],
13
18
  ): Promise<Blob> {
14
19
  const pdf = new jsPDF("p", "mm", "a4");
15
20
  const pageWidth = pdf.internal.pageSize.getWidth();
@@ -22,7 +27,7 @@ export async function buildPdfFromCharts(
22
27
  addCoverPage(
23
28
  pdf,
24
29
  documentTitle,
25
- charts.map((chart) => chart.title),
30
+ [...charts.map((chart) => chart.title), ...extraPages.map((p) => p.title)],
26
31
  pageWidth,
27
32
  pageHeight,
28
33
  );
@@ -63,6 +68,10 @@ export async function buildPdfFromCharts(
63
68
  }
64
69
  }
65
70
 
71
+ if (extraPages.length > 0) {
72
+ addExtraPages(pdf, extraPages, pageWidth, pageHeight);
73
+ }
74
+
66
75
  addPageNumbers(pdf, pageWidth, pageHeight);
67
76
  return pdf.output("blob");
68
77
  }
@@ -138,6 +147,76 @@ function addChartImage(
138
147
  }
139
148
  }
140
149
 
150
+ /**
151
+ * Append one native-text PDF page per entry in `extraPages`, rendered as
152
+ * label/value rows rather than a captured image. Each page starts fresh so
153
+ * its content never bleeds into a chart page.
154
+ */
155
+ function addExtraPages(
156
+ pdf: jsPDF,
157
+ extraPages: PdfTextPage[],
158
+ pageWidth: number,
159
+ pageHeight: number,
160
+ ): void {
161
+ const LABEL_COL_WIDTH = 68; // mm — enough for the longest label
162
+ const VALUE_COL_X = MARGIN_MM + LABEL_COL_WIDTH;
163
+ const VALUE_COL_WIDTH = pageWidth - MARGIN_MM - LABEL_COL_WIDTH;
164
+ const LINE_HEIGHT = 7; // mm between rows
165
+
166
+ for (const page of extraPages) {
167
+ pdf.addPage();
168
+ let y = MARGIN_MM + 8;
169
+
170
+ pdf.setFontSize(16);
171
+ pdf.setFont("helvetica", "bold");
172
+ pdf.text(page.title, MARGIN_MM, y);
173
+ y += 10;
174
+
175
+ pdf.setDrawColor(0, 103, 187);
176
+ pdf.setLineWidth(0.5);
177
+ pdf.line(MARGIN_MM, y, pageWidth - MARGIN_MM, y);
178
+ y += 10;
179
+
180
+ pdf.setFontSize(11);
181
+
182
+ for (const item of page.items) {
183
+ pdf.setFont("helvetica", "bold");
184
+ const labelLines = pdf.splitTextToSize(
185
+ item.label,
186
+ LABEL_COL_WIDTH - 4,
187
+ ) as string[];
188
+ pdf.text(labelLines, MARGIN_MM, y);
189
+
190
+ pdf.setFont("helvetica", "normal");
191
+ const valueLines = pdf.splitTextToSize(
192
+ item.value,
193
+ VALUE_COL_WIDTH,
194
+ ) as string[];
195
+ pdf.text(valueLines, VALUE_COL_X, y);
196
+
197
+ y += LINE_HEIGHT * Math.max(labelLines.length, valueLines.length);
198
+
199
+ if (y > pageHeight - MARGIN_MM - 25) {
200
+ pdf.addPage();
201
+ y = MARGIN_MM + 10;
202
+ }
203
+ }
204
+
205
+ if (page.footer) {
206
+ y += 4;
207
+ pdf.setFontSize(9);
208
+ pdf.setFont("helvetica", "bolditalic");
209
+ const footerLines = pdf.splitTextToSize(
210
+ page.footer,
211
+ pageWidth - MARGIN_MM * 2,
212
+ ) as string[];
213
+ pdf.text(footerLines, MARGIN_MM, y);
214
+ pdf.setFont("helvetica", "normal");
215
+ pdf.setFontSize(11);
216
+ }
217
+ }
218
+ }
219
+
141
220
  function addPageNumbers(
142
221
  pdf: jsPDF,
143
222
  pageWidth: number,