@openshift-migration-advisor/shared-components 0.25.0 → 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.
- package/README.md +25 -0
- 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/HostPowerStates.d.ts +0 -1
- package/dist/report/HostPowerStates.d.ts.map +1 -1
- package/dist/report/HostPowerStates.js +2 -2
- 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.map +1 -1
- package/dist/report/InfrastructureSummary.js +6 -2
- 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 +8 -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 +0 -1
- package/dist/report/PowerStateCard.d.ts.map +1 -1
- package/dist/report/PowerStateCard.js +4 -2
- 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 -21
- package/dist/report/VCenterClusterDetails.d.ts +0 -1
- package/dist/report/VCenterClusterDetails.d.ts.map +1 -1
- package/dist/report/VCenterClusterDetails.js +9 -4
- package/dist/report/VmPowerStates.d.ts +0 -1
- package/dist/report/VmPowerStates.d.ts.map +1 -1
- package/dist/report/VmPowerStates.js +2 -2
- 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 +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 +18 -0
- package/dist/report/index.d.ts.map +1 -1
- package/dist/report/index.js +18 -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/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/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/HostPowerStates.tsx +0 -3
- package/src/report/HostsOverview.tsx +185 -0
- package/src/report/InfrastructureSummary.tsx +48 -31
- package/src/report/NetworkOverview.tsx +405 -0
- package/src/report/OSDistribution.tsx +46 -42
- package/src/report/OsUpgradeRecommendationPopover.tsx +3 -4
- package/src/report/PowerStateCard.tsx +49 -36
- package/src/report/ReportExportMenu.tsx +119 -0
- package/src/report/ReportTable.tsx +81 -0
- package/src/report/SupportTierBadge.tsx +12 -40
- package/src/report/VCenterClusterDetails.tsx +38 -16
- package/src/report/VmPowerStates.tsx +0 -3
- package/src/report/WarningsTable.tsx +75 -0
- package/src/report/__tests__/ChartExportProvider.test.tsx +542 -0
- package/src/report/__tests__/HostsOverview.test.tsx +145 -0
- package/src/report/__tests__/InfrastructureSummary.test.tsx +0 -22
- 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/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 +2 -0
- package/src/report/dashboardStyles.ts +0 -23
- package/src/report/htmlExport.ts +83 -0
- package/src/report/index.ts +98 -0
- package/src/report/pdfExport.ts +233 -0
- package/src/report/pdfPage.ts +83 -0
- package/src/report/reportExportOptions.ts +53 -0
- package/src/report/zipChartPngs.ts +10 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import jsPDF from "jspdf";
|
|
2
|
+
import {
|
|
3
|
+
type ChartCaptureSource,
|
|
4
|
+
type PdfTextPage,
|
|
5
|
+
releaseCanvas,
|
|
6
|
+
} from "./chartExport.js";
|
|
7
|
+
import { fitPdfImageSize, placePdfBlock, sliceCanvas } from "./pdfPage.js";
|
|
8
|
+
|
|
9
|
+
const MARGIN_MM = 10;
|
|
10
|
+
const GAP_MM = 8;
|
|
11
|
+
/** Flatten captures onto white; jsPDF cannot embed transparent PNG alpha cleanly. */
|
|
12
|
+
const PAGE_BACKGROUND = "#ffffff";
|
|
13
|
+
|
|
14
|
+
export async function buildPdfFromCharts(
|
|
15
|
+
charts: ChartCaptureSource[],
|
|
16
|
+
documentTitle: string,
|
|
17
|
+
extraPages: PdfTextPage[] = [],
|
|
18
|
+
): Promise<Blob> {
|
|
19
|
+
const pdf = new jsPDF("p", "mm", "a4");
|
|
20
|
+
const pageWidth = pdf.internal.pageSize.getWidth();
|
|
21
|
+
const pageHeight = pdf.internal.pageSize.getHeight();
|
|
22
|
+
const contentWidth = pageWidth - MARGIN_MM * 2;
|
|
23
|
+
const contentHeight = pageHeight - MARGIN_MM * 2;
|
|
24
|
+
const pageTop = MARGIN_MM;
|
|
25
|
+
const pageBottom = pageHeight - MARGIN_MM;
|
|
26
|
+
|
|
27
|
+
addCoverPage(
|
|
28
|
+
pdf,
|
|
29
|
+
documentTitle,
|
|
30
|
+
[...charts.map((chart) => chart.title), ...extraPages.map((p) => p.title)],
|
|
31
|
+
pageWidth,
|
|
32
|
+
pageHeight,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
let cursorY: number | null = null;
|
|
36
|
+
for (const chart of charts) {
|
|
37
|
+
const canvas = await chart.capture();
|
|
38
|
+
try {
|
|
39
|
+
if (canvas.width < 1 || canvas.height < 1) {
|
|
40
|
+
throw new Error("Chart capture produced an empty image");
|
|
41
|
+
}
|
|
42
|
+
const size = fitPdfImageSize(
|
|
43
|
+
canvas.width,
|
|
44
|
+
canvas.height,
|
|
45
|
+
contentWidth,
|
|
46
|
+
contentHeight,
|
|
47
|
+
);
|
|
48
|
+
const placement = placePdfBlock(
|
|
49
|
+
cursorY,
|
|
50
|
+
size.heightMm,
|
|
51
|
+
pageTop,
|
|
52
|
+
pageBottom,
|
|
53
|
+
);
|
|
54
|
+
if (placement.needsNewPage) {
|
|
55
|
+
pdf.addPage();
|
|
56
|
+
}
|
|
57
|
+
addChartImage(
|
|
58
|
+
pdf,
|
|
59
|
+
canvas,
|
|
60
|
+
MARGIN_MM + (contentWidth - size.widthMm) / 2,
|
|
61
|
+
placement.y,
|
|
62
|
+
size.widthMm,
|
|
63
|
+
size.heightMm,
|
|
64
|
+
);
|
|
65
|
+
cursorY = placement.y + size.heightMm + GAP_MM;
|
|
66
|
+
} finally {
|
|
67
|
+
releaseCanvas(canvas);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (extraPages.length > 0) {
|
|
72
|
+
addExtraPages(pdf, extraPages, pageWidth, pageHeight);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
addPageNumbers(pdf, pageWidth, pageHeight);
|
|
76
|
+
return pdf.output("blob");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function addCoverPage(
|
|
80
|
+
pdf: jsPDF,
|
|
81
|
+
documentTitle: string,
|
|
82
|
+
tocItems: string[],
|
|
83
|
+
pageWidth: number,
|
|
84
|
+
pageHeight: number,
|
|
85
|
+
): void {
|
|
86
|
+
const contentWidth = pageWidth - MARGIN_MM * 2;
|
|
87
|
+
pdf.setFontSize(18);
|
|
88
|
+
const titleLines = pdf.splitTextToSize(
|
|
89
|
+
documentTitle,
|
|
90
|
+
contentWidth,
|
|
91
|
+
) as string[];
|
|
92
|
+
let titleY = MARGIN_MM + 8;
|
|
93
|
+
for (const line of titleLines) {
|
|
94
|
+
pdf.text(line, pageWidth / 2, titleY, { align: "center" });
|
|
95
|
+
titleY += 8;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
pdf.setFontSize(11);
|
|
99
|
+
const generatedAt = new Date();
|
|
100
|
+
pdf.text(
|
|
101
|
+
`Generated: ${generatedAt.toLocaleDateString()} ${generatedAt.toLocaleTimeString()}`,
|
|
102
|
+
pageWidth / 2,
|
|
103
|
+
titleY + 4,
|
|
104
|
+
{ align: "center" },
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
pdf.setFontSize(14);
|
|
108
|
+
pdf.text("Table of contents", MARGIN_MM, titleY + 16);
|
|
109
|
+
pdf.setFontSize(11);
|
|
110
|
+
let tocY = titleY + 26;
|
|
111
|
+
for (const item of tocItems) {
|
|
112
|
+
if (tocY > pageHeight - MARGIN_MM - 10) {
|
|
113
|
+
pdf.addPage();
|
|
114
|
+
tocY = MARGIN_MM;
|
|
115
|
+
}
|
|
116
|
+
pdf.text(`- ${item}`, MARGIN_MM, tocY);
|
|
117
|
+
tocY += 7;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function addChartImage(
|
|
122
|
+
pdf: jsPDF,
|
|
123
|
+
canvas: HTMLCanvasElement,
|
|
124
|
+
x: number,
|
|
125
|
+
y: number,
|
|
126
|
+
widthMm: number,
|
|
127
|
+
heightMm: number,
|
|
128
|
+
): void {
|
|
129
|
+
const flattened = sliceCanvas(
|
|
130
|
+
canvas,
|
|
131
|
+
canvas.width,
|
|
132
|
+
canvas.height,
|
|
133
|
+
0,
|
|
134
|
+
PAGE_BACKGROUND,
|
|
135
|
+
);
|
|
136
|
+
try {
|
|
137
|
+
pdf.addImage(
|
|
138
|
+
flattened.toDataURL("image/jpeg", 0.92),
|
|
139
|
+
"JPEG",
|
|
140
|
+
x,
|
|
141
|
+
y,
|
|
142
|
+
widthMm,
|
|
143
|
+
heightMm,
|
|
144
|
+
);
|
|
145
|
+
} finally {
|
|
146
|
+
releaseCanvas(flattened);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
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
|
+
|
|
220
|
+
function addPageNumbers(
|
|
221
|
+
pdf: jsPDF,
|
|
222
|
+
pageWidth: number,
|
|
223
|
+
pageHeight: number,
|
|
224
|
+
): void {
|
|
225
|
+
const totalPages = pdf.getNumberOfPages();
|
|
226
|
+
pdf.setFontSize(9);
|
|
227
|
+
for (let page = 1; page <= totalPages; page++) {
|
|
228
|
+
pdf.setPage(page);
|
|
229
|
+
pdf.text(`Page ${page} of ${totalPages}`, pageWidth / 2, pageHeight - 6, {
|
|
230
|
+
align: "center",
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
@@ -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,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
|
+
}
|