@openshift-migration-advisor/shared-components 0.25.0 → 0.27.0-5d313f88dc52
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 +304 -0
- package/dist/report/chartExport.d.ts +80 -0
- package/dist/report/chartExport.d.ts.map +1 -0
- package/dist/report/chartExport.js +182 -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 +582 -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 +205 -0
- package/src/report/__tests__/chartExportPackagers.test.ts +299 -0
- package/src/report/captureChartElement.ts +398 -0
- package/src/report/chartExport.ts +277 -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,304 @@
|
|
|
1
|
+
import { t_color_gray_20, t_color_white, t_global_text_color_regular, } from "@patternfly/react-tokens";
|
|
2
|
+
import html2canvas from "html2canvas-pro";
|
|
3
|
+
import { applyLightThemeToDocument, CHART_EXPORT_CAPTURING_ATTR, CHART_EXPORT_SCROLL_ATTR, shouldIgnoreChartExportElement, } from "./chartExport.js";
|
|
4
|
+
/** CSS-pixel scale; 2x made zip-all of ~15 live cards too slow. */
|
|
5
|
+
const CHART_CAPTURE_SCALE = 1;
|
|
6
|
+
const HIDDEN_LAYOUT_STYLE_KEYS = [
|
|
7
|
+
"display",
|
|
8
|
+
"position",
|
|
9
|
+
"left",
|
|
10
|
+
"top",
|
|
11
|
+
"width",
|
|
12
|
+
"maxHeight",
|
|
13
|
+
"overflow",
|
|
14
|
+
"zIndex",
|
|
15
|
+
];
|
|
16
|
+
function isDisplayNone(node) {
|
|
17
|
+
return window.getComputedStyle(node).display === "none";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Tab panels stay mounted with `hidden` / `display:none` when another tab is
|
|
21
|
+
* active. html2canvas then measures a 0×0 box. Reveal those ancestors off-screen
|
|
22
|
+
* for the duration of the capture, then restore.
|
|
23
|
+
*/
|
|
24
|
+
export function revealHiddenChartAncestors(element) {
|
|
25
|
+
const saved = [];
|
|
26
|
+
let node = element;
|
|
27
|
+
while (node && node !== document.documentElement) {
|
|
28
|
+
if (node.hidden || isDisplayNone(node)) {
|
|
29
|
+
saved.push({
|
|
30
|
+
node,
|
|
31
|
+
hidden: node.hidden,
|
|
32
|
+
styles: {
|
|
33
|
+
display: node.style.display,
|
|
34
|
+
position: node.style.position,
|
|
35
|
+
left: node.style.left,
|
|
36
|
+
top: node.style.top,
|
|
37
|
+
width: node.style.width,
|
|
38
|
+
maxHeight: node.style.maxHeight,
|
|
39
|
+
overflow: node.style.overflow,
|
|
40
|
+
zIndex: node.style.zIndex,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
node = node.parentElement;
|
|
45
|
+
}
|
|
46
|
+
if (saved.length === 0) {
|
|
47
|
+
return () => undefined;
|
|
48
|
+
}
|
|
49
|
+
const outermost = saved[saved.length - 1].node;
|
|
50
|
+
const parentWidth = outermost.parentElement?.clientWidth ?? 0;
|
|
51
|
+
const layoutWidth = parentWidth || document.documentElement.clientWidth || 1024;
|
|
52
|
+
for (const entry of saved) {
|
|
53
|
+
entry.node.hidden = false;
|
|
54
|
+
entry.node.style.display = "block";
|
|
55
|
+
entry.node.style.position = "fixed";
|
|
56
|
+
entry.node.style.left = "-10000px";
|
|
57
|
+
entry.node.style.top = "0";
|
|
58
|
+
entry.node.style.width = `${layoutWidth}px`;
|
|
59
|
+
entry.node.style.maxHeight = "none";
|
|
60
|
+
entry.node.style.overflow = "visible";
|
|
61
|
+
entry.node.style.zIndex = "-1";
|
|
62
|
+
}
|
|
63
|
+
return () => {
|
|
64
|
+
for (const entry of saved) {
|
|
65
|
+
entry.node.hidden = entry.hidden;
|
|
66
|
+
for (const key of HIDDEN_LAYOUT_STYLE_KEYS) {
|
|
67
|
+
entry.node.style[key] = entry.styles[key];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const PADDED_CAPTURE_SELECTOR = ".pf-v6-c-card__title, .pf-v6-c-card__header, .pf-v6-c-card__body";
|
|
73
|
+
const CARD_CAPTURE_SELECTOR = ".pf-v6-c-card";
|
|
74
|
+
const TRANSPARENT_FILLS = new Set(["", "transparent", "rgba(0, 0, 0, 0)"]);
|
|
75
|
+
/** PatternFly light-theme chrome. html2canvas inlines live computed SVG styles. */
|
|
76
|
+
const LIGHT_EXPORT_BACKGROUND = t_color_white.value;
|
|
77
|
+
const LIGHT_EXPORT_BORDER = t_color_gray_20.value;
|
|
78
|
+
const LIGHT_EXPORT_TEXT = t_global_text_color_regular.value;
|
|
79
|
+
function queryCards(root) {
|
|
80
|
+
const cards = Array.from(root.querySelectorAll(CARD_CAPTURE_SELECTOR));
|
|
81
|
+
if (root.matches(CARD_CAPTURE_SELECTOR)) {
|
|
82
|
+
cards.unshift(root);
|
|
83
|
+
}
|
|
84
|
+
return cards;
|
|
85
|
+
}
|
|
86
|
+
function resolvedFill(color) {
|
|
87
|
+
return TRANSPARENT_FILLS.has(color) ? "#ffffff" : color;
|
|
88
|
+
}
|
|
89
|
+
function applyComputedPadding(source, dest) {
|
|
90
|
+
const computed = window.getComputedStyle(source);
|
|
91
|
+
dest.style.paddingTop = computed.paddingTop;
|
|
92
|
+
dest.style.paddingRight = computed.paddingRight;
|
|
93
|
+
dest.style.paddingBottom = computed.paddingBottom;
|
|
94
|
+
dest.style.paddingLeft = computed.paddingLeft;
|
|
95
|
+
}
|
|
96
|
+
function readCardBorder(source) {
|
|
97
|
+
if (source.style.borderWidth && source.style.borderStyle) {
|
|
98
|
+
return {
|
|
99
|
+
width: source.style.borderWidth,
|
|
100
|
+
style: source.style.borderStyle,
|
|
101
|
+
color: source.style.borderColor,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const computed = window.getComputedStyle(source);
|
|
105
|
+
const before = window.getComputedStyle(source, "::before");
|
|
106
|
+
const width = before.borderTopWidth && before.borderTopWidth !== "0px"
|
|
107
|
+
? before.borderTopWidth
|
|
108
|
+
: computed.borderTopWidth;
|
|
109
|
+
const style = before.borderTopStyle && before.borderTopStyle !== "none"
|
|
110
|
+
? before.borderTopStyle
|
|
111
|
+
: computed.borderTopStyle;
|
|
112
|
+
const color = before.borderTopColor && before.borderTopColor !== "rgba(0, 0, 0, 0)"
|
|
113
|
+
? before.borderTopColor
|
|
114
|
+
: computed.borderTopColor;
|
|
115
|
+
if (width === "0px" || style === "none") {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
return { width, style, color };
|
|
119
|
+
}
|
|
120
|
+
function applyCardChrome(source, dest, colors) {
|
|
121
|
+
const computed = window.getComputedStyle(source);
|
|
122
|
+
dest.style.borderRadius = computed.borderRadius;
|
|
123
|
+
dest.style.overflow = "hidden";
|
|
124
|
+
dest.style.backgroundColor =
|
|
125
|
+
colors === "light"
|
|
126
|
+
? LIGHT_EXPORT_BACKGROUND
|
|
127
|
+
: resolvedFill(computed.backgroundColor);
|
|
128
|
+
const border = readCardBorder(source);
|
|
129
|
+
if (border) {
|
|
130
|
+
dest.style.borderWidth = border.width;
|
|
131
|
+
dest.style.borderStyle = border.style;
|
|
132
|
+
dest.style.borderColor =
|
|
133
|
+
colors === "light" ? LIGHT_EXPORT_BORDER : border.color;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function applyLightThemeSvgText(root) {
|
|
137
|
+
for (const node of root.querySelectorAll("text, tspan")) {
|
|
138
|
+
if (!(node instanceof SVGElement)) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
node.style.fill = LIGHT_EXPORT_TEXT;
|
|
142
|
+
node.style.color = LIGHT_EXPORT_TEXT;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function hideCardBeforePseudo() {
|
|
146
|
+
const style = document.createElement("style");
|
|
147
|
+
style.setAttribute("data-chart-export-hide-before", "");
|
|
148
|
+
style.textContent = `
|
|
149
|
+
[${CHART_EXPORT_CAPTURING_ATTR}] .pf-v6-c-card::before,
|
|
150
|
+
[${CHART_EXPORT_CAPTURING_ATTR}].pf-v6-c-card::before {
|
|
151
|
+
border: none !important;
|
|
152
|
+
box-shadow: none !important;
|
|
153
|
+
}
|
|
154
|
+
`;
|
|
155
|
+
document.head.append(style);
|
|
156
|
+
return () => {
|
|
157
|
+
style.remove();
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function copyComputedPadding(node) {
|
|
161
|
+
const previous = {
|
|
162
|
+
paddingTop: node.style.paddingTop,
|
|
163
|
+
paddingRight: node.style.paddingRight,
|
|
164
|
+
paddingBottom: node.style.paddingBottom,
|
|
165
|
+
paddingLeft: node.style.paddingLeft,
|
|
166
|
+
};
|
|
167
|
+
applyComputedPadding(node, node);
|
|
168
|
+
return previous;
|
|
169
|
+
}
|
|
170
|
+
function copyCardChrome(node) {
|
|
171
|
+
const previous = {
|
|
172
|
+
borderRadius: node.style.borderRadius,
|
|
173
|
+
backgroundColor: node.style.backgroundColor,
|
|
174
|
+
overflow: node.style.getPropertyValue("overflow"),
|
|
175
|
+
overflowPriority: node.style.getPropertyPriority("overflow"),
|
|
176
|
+
borderWidth: node.style.borderWidth,
|
|
177
|
+
borderStyle: node.style.borderStyle,
|
|
178
|
+
borderColor: node.style.borderColor,
|
|
179
|
+
minHeight: node.style.minHeight,
|
|
180
|
+
height: node.style.height,
|
|
181
|
+
maxHeight: node.style.maxHeight,
|
|
182
|
+
};
|
|
183
|
+
applyCardChrome(node, node, "computed");
|
|
184
|
+
node.style.minHeight = "0px";
|
|
185
|
+
node.style.height = "auto";
|
|
186
|
+
node.style.maxHeight = "none";
|
|
187
|
+
return previous;
|
|
188
|
+
}
|
|
189
|
+
function applyComputedStylesToClone(sourceRoot, clonedRoot) {
|
|
190
|
+
const sourceCards = queryCards(sourceRoot);
|
|
191
|
+
const cloneCards = queryCards(clonedRoot);
|
|
192
|
+
sourceCards.forEach((source, index) => {
|
|
193
|
+
const dest = cloneCards[index];
|
|
194
|
+
if (dest) {
|
|
195
|
+
applyCardChrome(source, dest, "light");
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
const sources = sourceRoot.querySelectorAll(PADDED_CAPTURE_SELECTOR);
|
|
199
|
+
const dests = clonedRoot.querySelectorAll(PADDED_CAPTURE_SELECTOR);
|
|
200
|
+
sources.forEach((source, index) => {
|
|
201
|
+
const dest = dests[index];
|
|
202
|
+
if (dest) {
|
|
203
|
+
applyComputedPadding(source, dest);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
function prepareCaptureLayout(element) {
|
|
208
|
+
const expandNodes = [
|
|
209
|
+
element,
|
|
210
|
+
...Array.from(element.querySelectorAll(`[${CHART_EXPORT_SCROLL_ATTR}], .pf-v6-c-card__body`)),
|
|
211
|
+
];
|
|
212
|
+
const cards = queryCards(element);
|
|
213
|
+
const paddedNodes = Array.from(element.querySelectorAll(PADDED_CAPTURE_SELECTOR));
|
|
214
|
+
const previousExpand = expandNodes.map((node) => ({
|
|
215
|
+
node,
|
|
216
|
+
overflow: node.style.getPropertyValue("overflow"),
|
|
217
|
+
overflowPriority: node.style.getPropertyPriority("overflow"),
|
|
218
|
+
maxHeight: node.style.maxHeight,
|
|
219
|
+
height: node.style.height,
|
|
220
|
+
}));
|
|
221
|
+
const previousChrome = cards.map((node) => ({
|
|
222
|
+
node,
|
|
223
|
+
...copyCardChrome(node),
|
|
224
|
+
}));
|
|
225
|
+
const previousPadding = paddedNodes.map((node) => ({
|
|
226
|
+
node,
|
|
227
|
+
...copyComputedPadding(node),
|
|
228
|
+
}));
|
|
229
|
+
for (const node of expandNodes) {
|
|
230
|
+
node.style.setProperty("overflow", "visible", "important");
|
|
231
|
+
node.style.maxHeight = "none";
|
|
232
|
+
node.style.height = "auto";
|
|
233
|
+
}
|
|
234
|
+
return () => {
|
|
235
|
+
for (const entry of previousExpand) {
|
|
236
|
+
if (entry.overflow) {
|
|
237
|
+
entry.node.style.setProperty("overflow", entry.overflow, entry.overflowPriority);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
entry.node.style.removeProperty("overflow");
|
|
241
|
+
}
|
|
242
|
+
entry.node.style.maxHeight = entry.maxHeight;
|
|
243
|
+
entry.node.style.height = entry.height;
|
|
244
|
+
}
|
|
245
|
+
for (const entry of previousChrome) {
|
|
246
|
+
entry.node.style.borderRadius = entry.borderRadius;
|
|
247
|
+
entry.node.style.backgroundColor = entry.backgroundColor;
|
|
248
|
+
if (entry.overflow) {
|
|
249
|
+
entry.node.style.setProperty("overflow", entry.overflow, entry.overflowPriority);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
entry.node.style.removeProperty("overflow");
|
|
253
|
+
}
|
|
254
|
+
entry.node.style.borderWidth = entry.borderWidth;
|
|
255
|
+
entry.node.style.borderStyle = entry.borderStyle;
|
|
256
|
+
entry.node.style.borderColor = entry.borderColor;
|
|
257
|
+
entry.node.style.minHeight = entry.minHeight;
|
|
258
|
+
entry.node.style.height = entry.height;
|
|
259
|
+
entry.node.style.maxHeight = entry.maxHeight;
|
|
260
|
+
}
|
|
261
|
+
for (const entry of previousPadding) {
|
|
262
|
+
entry.node.style.paddingTop = entry.paddingTop;
|
|
263
|
+
entry.node.style.paddingRight = entry.paddingRight;
|
|
264
|
+
entry.node.style.paddingBottom = entry.paddingBottom;
|
|
265
|
+
entry.node.style.paddingLeft = entry.paddingLeft;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
export async function captureChartElement(element) {
|
|
270
|
+
const restoreHidden = revealHiddenChartAncestors(element);
|
|
271
|
+
const restoreLayout = prepareCaptureLayout(element);
|
|
272
|
+
element.setAttribute(CHART_EXPORT_CAPTURING_ATTR, "");
|
|
273
|
+
const restoreCardBefore = hideCardBeforePseudo();
|
|
274
|
+
try {
|
|
275
|
+
await new Promise((resolve) => {
|
|
276
|
+
requestAnimationFrame(() => resolve());
|
|
277
|
+
});
|
|
278
|
+
if (element.getBoundingClientRect().width < 1) {
|
|
279
|
+
await new Promise((resolve) => {
|
|
280
|
+
requestAnimationFrame(() => resolve());
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
return html2canvas(element, {
|
|
284
|
+
useCORS: true,
|
|
285
|
+
backgroundColor: LIGHT_EXPORT_BACKGROUND,
|
|
286
|
+
logging: false,
|
|
287
|
+
scale: CHART_CAPTURE_SCALE,
|
|
288
|
+
imageTimeout: 0,
|
|
289
|
+
ignoreElements: (node) => node instanceof Element &&
|
|
290
|
+
shouldIgnoreChartExportElement(node, element),
|
|
291
|
+
onclone: (clonedDoc, clonedElement) => {
|
|
292
|
+
applyLightThemeToDocument(clonedDoc);
|
|
293
|
+
applyComputedStylesToClone(element, clonedElement);
|
|
294
|
+
applyLightThemeSvgText(clonedElement);
|
|
295
|
+
},
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
finally {
|
|
299
|
+
restoreCardBefore();
|
|
300
|
+
element.removeAttribute(CHART_EXPORT_CAPTURING_ATTR);
|
|
301
|
+
restoreLayout();
|
|
302
|
+
restoreHidden();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
export declare const CHART_EXPORT_HIDE_ATTR = "data-chart-export-hide";
|
|
3
|
+
export declare const CHART_EXPORT_SCROLL_ATTR = "data-chart-export-scroll";
|
|
4
|
+
export declare const CHART_EXPORT_CAPTURING_ATTR = "data-chart-capturing";
|
|
5
|
+
export declare const chartExportHideProps: {
|
|
6
|
+
readonly "data-chart-export-hide": "";
|
|
7
|
+
};
|
|
8
|
+
export declare const chartExportScrollProps: {
|
|
9
|
+
readonly "data-chart-export-scroll": "";
|
|
10
|
+
};
|
|
11
|
+
export declare const chartExportRootStyle: CSSProperties;
|
|
12
|
+
export type ChartExportMeta = {
|
|
13
|
+
id: string;
|
|
14
|
+
title: string;
|
|
15
|
+
filename?: string;
|
|
16
|
+
};
|
|
17
|
+
export type ChartExportView = {
|
|
18
|
+
id: string;
|
|
19
|
+
title: string;
|
|
20
|
+
filename?: string;
|
|
21
|
+
};
|
|
22
|
+
export type RegisteredChart = {
|
|
23
|
+
id: string;
|
|
24
|
+
title: string;
|
|
25
|
+
filename: string;
|
|
26
|
+
element: HTMLElement;
|
|
27
|
+
exportViews?: ChartExportView[];
|
|
28
|
+
activeExportViewId?: string;
|
|
29
|
+
setExportView?: (viewId: string) => Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
export type ChartExportFile = {
|
|
32
|
+
filename: string;
|
|
33
|
+
blob: Blob;
|
|
34
|
+
};
|
|
35
|
+
export type ChartCaptureSource = {
|
|
36
|
+
id: string;
|
|
37
|
+
title: string;
|
|
38
|
+
filename: string;
|
|
39
|
+
capture: () => Promise<HTMLCanvasElement>;
|
|
40
|
+
};
|
|
41
|
+
/** One label/value row rendered on a {@link PdfTextPage}. */
|
|
42
|
+
export type PdfTextPageItem = {
|
|
43
|
+
label: string;
|
|
44
|
+
value: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* A native-text PDF page appended after the captured chart images.
|
|
48
|
+
*
|
|
49
|
+
* Used for content that is not a chart/card (e.g. calculated recommendations)
|
|
50
|
+
* but still needs to be part of the exported PDF.
|
|
51
|
+
*/
|
|
52
|
+
export type PdfTextPage = {
|
|
53
|
+
title: string;
|
|
54
|
+
items: PdfTextPageItem[];
|
|
55
|
+
footer?: string;
|
|
56
|
+
};
|
|
57
|
+
export declare function releaseCanvas(canvas: HTMLCanvasElement): void;
|
|
58
|
+
export declare function waitForChartExportPaint(): Promise<void>;
|
|
59
|
+
/** PatternFly applies dark tokens when this class is on `:root`. */
|
|
60
|
+
export declare const PATTERNFLY_DARK_THEME_CLASSES: readonly ["pf-v6-theme-dark", "pf-v5-theme-dark"];
|
|
61
|
+
/**
|
|
62
|
+
* Force PatternFly light tokens on a document (the html2canvas clone).
|
|
63
|
+
* Does not touch the live page.
|
|
64
|
+
*/
|
|
65
|
+
export declare function applyLightThemeToDocument(root: Document): void;
|
|
66
|
+
export declare function chartExportViewsFromLabels(titlePrefix: string, labels: Record<string, string>): ChartExportView[];
|
|
67
|
+
export declare function toBulkChartCaptureSources(charts: RegisteredChart[], capture: (element: HTMLElement) => Promise<HTMLCanvasElement>, prepareElement?: (element: HTMLElement) => () => void): ChartCaptureSource[];
|
|
68
|
+
export declare function restoreChartExportViews(charts: RegisteredChart[]): Promise<void>;
|
|
69
|
+
export declare function sortRegisteredChartsByDocumentOrder(charts: RegisteredChart[]): RegisteredChart[];
|
|
70
|
+
export declare function canvasToBlob(canvas: HTMLCanvasElement): Promise<Blob>;
|
|
71
|
+
export declare function slugifyExportName(value: string): string;
|
|
72
|
+
export declare function chartPngFilename(title: string, id?: string): string;
|
|
73
|
+
/**
|
|
74
|
+
* html2canvas clones the whole document for every capture. Ignore everything
|
|
75
|
+
* except the target card (and ancestors / stylesheet nodes) so zip-all does
|
|
76
|
+
* not re-render every other chart.
|
|
77
|
+
*/
|
|
78
|
+
export declare function shouldIgnoreChartExportElement(node: Element, captureRoot?: Element | null): boolean;
|
|
79
|
+
export declare function downloadBlob(blob: Blob, filename: string): void;
|
|
80
|
+
//# sourceMappingURL=chartExport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chartExport.d.ts","sourceRoot":"","sources":["../../src/report/chartExport.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
export const CHART_EXPORT_HIDE_ATTR = "data-chart-export-hide";
|
|
2
|
+
export const CHART_EXPORT_SCROLL_ATTR = "data-chart-export-scroll";
|
|
3
|
+
export const CHART_EXPORT_CAPTURING_ATTR = "data-chart-capturing";
|
|
4
|
+
export const chartExportHideProps = {
|
|
5
|
+
[CHART_EXPORT_HIDE_ATTR]: "",
|
|
6
|
+
};
|
|
7
|
+
export const chartExportScrollProps = {
|
|
8
|
+
[CHART_EXPORT_SCROLL_ATTR]: "",
|
|
9
|
+
};
|
|
10
|
+
export const chartExportRootStyle = {
|
|
11
|
+
width: "100%",
|
|
12
|
+
height: "100%",
|
|
13
|
+
};
|
|
14
|
+
export function releaseCanvas(canvas) {
|
|
15
|
+
canvas.width = 0;
|
|
16
|
+
canvas.height = 0;
|
|
17
|
+
}
|
|
18
|
+
export function waitForChartExportPaint() {
|
|
19
|
+
if (typeof requestAnimationFrame !== "function") {
|
|
20
|
+
return Promise.resolve();
|
|
21
|
+
}
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
requestAnimationFrame(() => {
|
|
24
|
+
requestAnimationFrame(() => resolve());
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** PatternFly applies dark tokens when this class is on `:root`. */
|
|
29
|
+
export const PATTERNFLY_DARK_THEME_CLASSES = [
|
|
30
|
+
"pf-v6-theme-dark",
|
|
31
|
+
"pf-v5-theme-dark",
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* Force PatternFly light tokens on a document (the html2canvas clone).
|
|
35
|
+
* Does not touch the live page.
|
|
36
|
+
*/
|
|
37
|
+
export function applyLightThemeToDocument(root) {
|
|
38
|
+
for (const node of [root.documentElement, root.body]) {
|
|
39
|
+
if (!node) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
for (const className of PATTERNFLY_DARK_THEME_CLASSES) {
|
|
43
|
+
node.classList.remove(className);
|
|
44
|
+
}
|
|
45
|
+
node.style.colorScheme = "light";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export function chartExportViewsFromLabels(titlePrefix, labels) {
|
|
49
|
+
return Object.entries(labels).map(([id, label]) => ({
|
|
50
|
+
id,
|
|
51
|
+
title: `${titlePrefix} — ${label}`,
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
function shouldCycleExportViews(chart) {
|
|
55
|
+
return Boolean(chart.exportViews && chart.exportViews.length > 1 && chart.setExportView);
|
|
56
|
+
}
|
|
57
|
+
function bulkExportViews(chart) {
|
|
58
|
+
if (shouldCycleExportViews(chart) && chart.exportViews) {
|
|
59
|
+
return chart.exportViews;
|
|
60
|
+
}
|
|
61
|
+
return [
|
|
62
|
+
{
|
|
63
|
+
id: chart.id,
|
|
64
|
+
title: chart.title,
|
|
65
|
+
filename: chart.filename,
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
export function toBulkChartCaptureSources(charts, capture, prepareElement) {
|
|
70
|
+
return charts.flatMap((chart) => {
|
|
71
|
+
const views = bulkExportViews(chart);
|
|
72
|
+
const cyclesViews = shouldCycleExportViews(chart);
|
|
73
|
+
return views.map((view) => ({
|
|
74
|
+
id: cyclesViews ? `${chart.id}--${view.id}` : chart.id,
|
|
75
|
+
title: view.title,
|
|
76
|
+
filename: view.filename ??
|
|
77
|
+
(cyclesViews
|
|
78
|
+
? chartPngFilename(view.title, `${chart.id}-${view.id}`)
|
|
79
|
+
: chart.filename),
|
|
80
|
+
capture: async () => {
|
|
81
|
+
const restore = prepareElement?.(chart.element);
|
|
82
|
+
try {
|
|
83
|
+
if (cyclesViews && chart.setExportView) {
|
|
84
|
+
await chart.setExportView(view.id);
|
|
85
|
+
}
|
|
86
|
+
return await capture(chart.element);
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
restore?.();
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
}));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
export async function restoreChartExportViews(charts) {
|
|
96
|
+
for (const chart of charts) {
|
|
97
|
+
if (shouldCycleExportViews(chart) &&
|
|
98
|
+
chart.setExportView &&
|
|
99
|
+
chart.activeExportViewId) {
|
|
100
|
+
try {
|
|
101
|
+
await chart.setExportView(chart.activeExportViewId);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
console.error("Failed to restore the selected chart view:", error);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export function sortRegisteredChartsByDocumentOrder(charts) {
|
|
110
|
+
return [...charts].sort((left, right) => {
|
|
111
|
+
if (left.element === right.element) {
|
|
112
|
+
return 0;
|
|
113
|
+
}
|
|
114
|
+
const position = left.element.compareDocumentPosition(right.element);
|
|
115
|
+
if (position & Node.DOCUMENT_POSITION_FOLLOWING) {
|
|
116
|
+
return -1;
|
|
117
|
+
}
|
|
118
|
+
if (position & Node.DOCUMENT_POSITION_PRECEDING) {
|
|
119
|
+
return 1;
|
|
120
|
+
}
|
|
121
|
+
return 0;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
export function canvasToBlob(canvas) {
|
|
125
|
+
return new Promise((resolve, reject) => {
|
|
126
|
+
if (canvas.width < 1 || canvas.height < 1) {
|
|
127
|
+
reject(new Error("Failed to encode canvas as PNG"));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
canvas.toBlob((blob) => {
|
|
131
|
+
if (blob) {
|
|
132
|
+
resolve(blob);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
reject(new Error("Failed to encode canvas as PNG"));
|
|
136
|
+
}, "image/png");
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
export function slugifyExportName(value) {
|
|
140
|
+
const slug = value
|
|
141
|
+
.toLowerCase()
|
|
142
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
143
|
+
.replace(/^-|-$/g, "");
|
|
144
|
+
return slug || "chart";
|
|
145
|
+
}
|
|
146
|
+
export function chartPngFilename(title, id = "chart") {
|
|
147
|
+
return `${slugifyExportName(title) || slugifyExportName(id)}.png`;
|
|
148
|
+
}
|
|
149
|
+
const KEEP_TAGS = new Set(["HTML", "HEAD", "BODY", "STYLE", "LINK"]);
|
|
150
|
+
function isHiddenForChartExport(node) {
|
|
151
|
+
return (node.hasAttribute(CHART_EXPORT_HIDE_ATTR) ||
|
|
152
|
+
Boolean(node.closest(`[${CHART_EXPORT_HIDE_ATTR}]`)));
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* html2canvas clones the whole document for every capture. Ignore everything
|
|
156
|
+
* except the target card (and ancestors / stylesheet nodes) so zip-all does
|
|
157
|
+
* not re-render every other chart.
|
|
158
|
+
*/
|
|
159
|
+
export function shouldIgnoreChartExportElement(node, captureRoot) {
|
|
160
|
+
if (!captureRoot) {
|
|
161
|
+
return isHiddenForChartExport(node);
|
|
162
|
+
}
|
|
163
|
+
if (KEEP_TAGS.has(node.tagName)) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
if (node !== captureRoot &&
|
|
167
|
+
!captureRoot.contains(node) &&
|
|
168
|
+
!node.contains(captureRoot)) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
return isHiddenForChartExport(node);
|
|
172
|
+
}
|
|
173
|
+
export function downloadBlob(blob, filename) {
|
|
174
|
+
const url = URL.createObjectURL(blob);
|
|
175
|
+
const link = document.createElement("a");
|
|
176
|
+
link.href = url;
|
|
177
|
+
link.download = filename;
|
|
178
|
+
document.body.appendChild(link);
|
|
179
|
+
link.click();
|
|
180
|
+
document.body.removeChild(link);
|
|
181
|
+
URL.revokeObjectURL(url);
|
|
182
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type RefCallback } from "react";
|
|
2
|
+
import { type ChartExportMeta, type ChartExportView, type PdfTextPage, type RegisteredChart } from "./chartExport.js";
|
|
3
|
+
export type ChartExportFormat = "pdf" | "png" | "html";
|
|
4
|
+
export type ChartExportApi = {
|
|
5
|
+
downloadChart: (id: string) => Promise<void>;
|
|
6
|
+
downloadAll: () => Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* @param extraPages - Native-text pages appended after the captured chart
|
|
9
|
+
* images (e.g. calculated recommendations that aren't rendered as charts).
|
|
10
|
+
*/
|
|
11
|
+
downloadPdf: (documentTitle: string, extraPages?: PdfTextPage[]) => Promise<void>;
|
|
12
|
+
downloadHtml: (documentTitle: string) => Promise<void>;
|
|
13
|
+
downloadingChartId: string | null;
|
|
14
|
+
exportingFormat: ChartExportFormat | null;
|
|
15
|
+
exportLoadingLabel: string | null;
|
|
16
|
+
isExportingAll: boolean;
|
|
17
|
+
isBusy: boolean;
|
|
18
|
+
exportError: string | null;
|
|
19
|
+
clearExportError: () => void;
|
|
20
|
+
};
|
|
21
|
+
export type ChartExportRegistry = {
|
|
22
|
+
register: (chart: RegisteredChart) => () => void;
|
|
23
|
+
};
|
|
24
|
+
export declare const ChartExportRegistryContext: import("react").Context<ChartExportRegistry | null>;
|
|
25
|
+
export declare const ChartExportApiContext: import("react").Context<ChartExportApi | null>;
|
|
26
|
+
export declare function useChartExport(): ChartExportApi | null;
|
|
27
|
+
export declare function useRegisterChart({ id, title, filename, exportViews, activeExportViewId, setExportView, }: ChartExportMeta & {
|
|
28
|
+
exportViews?: ChartExportView[];
|
|
29
|
+
activeExportViewId?: string;
|
|
30
|
+
setExportView?: (viewId: string) => Promise<void>;
|
|
31
|
+
}): RefCallback<HTMLElement>;
|
|
32
|
+
//# sourceMappingURL=chartExportContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chartExportContext.d.ts","sourceRoot":"","sources":["../../src/report/chartExportContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAIjB,MAAM,OAAO,CAAC;AACf,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,eAAe,EAEpB,KAAK,WAAW,EAChB,KAAK,eAAe,EACrB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;AAEvD,MAAM,MAAM,cAAc,GAAG;IAC3B,aAAa,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC;;;OAGG;IACH,WAAW,EAAE,CACX,aAAa,EAAE,MAAM,EACrB,UAAU,CAAC,EAAE,WAAW,EAAE,KACvB,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,YAAY,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,eAAe,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC1C,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,cAAc,EAAE,OAAO,CAAC;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,gBAAgB,EAAE,MAAM,IAAI,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,MAAM,IAAI,CAAC;CAClD,CAAC;AAEF,eAAO,MAAM,0BAA0B,qDACU,CAAC;AAClD,eAAO,MAAM,qBAAqB,gDAA6C,CAAC;AAEhF,wBAAgB,cAAc,IAAI,cAAc,GAAG,IAAI,CAEtD;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,EAAE,EACF,KAAK,EACL,QAAQ,EACR,WAAW,EACX,kBAAkB,EAClB,aAAa,GACd,EAAE,eAAe,GAAG;IACnB,WAAW,CAAC,EAAE,eAAe,EAAE,CAAC;IAChC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACnD,GAAG,WAAW,CAAC,WAAW,CAAC,CA8B3B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createContext, useContext, useEffect, useState, } from "react";
|
|
2
|
+
import { chartPngFilename, } from "./chartExport.js";
|
|
3
|
+
export const ChartExportRegistryContext = createContext(null);
|
|
4
|
+
export const ChartExportApiContext = createContext(null);
|
|
5
|
+
export function useChartExport() {
|
|
6
|
+
return useContext(ChartExportApiContext);
|
|
7
|
+
}
|
|
8
|
+
export function useRegisterChart({ id, title, filename, exportViews, activeExportViewId, setExportView, }) {
|
|
9
|
+
const registry = useContext(ChartExportRegistryContext);
|
|
10
|
+
const [element, setElement] = useState(null);
|
|
11
|
+
const resolvedFilename = filename ?? chartPngFilename(title, id);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!registry || !element) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
return registry.register({
|
|
17
|
+
id,
|
|
18
|
+
title,
|
|
19
|
+
filename: resolvedFilename,
|
|
20
|
+
element,
|
|
21
|
+
exportViews,
|
|
22
|
+
activeExportViewId,
|
|
23
|
+
setExportView,
|
|
24
|
+
});
|
|
25
|
+
}, [
|
|
26
|
+
activeExportViewId,
|
|
27
|
+
element,
|
|
28
|
+
exportViews,
|
|
29
|
+
id,
|
|
30
|
+
registry,
|
|
31
|
+
resolvedFilename,
|
|
32
|
+
setExportView,
|
|
33
|
+
title,
|
|
34
|
+
]);
|
|
35
|
+
return setElement;
|
|
36
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function getDatedChartExportBasename(date?: Date): string;
|
|
2
|
+
export declare function getChartExportFilename(format: "pdf" | "html" | "zip", date?: Date): string;
|
|
3
|
+
export declare function getChartZipFilename(date?: Date): string;
|
|
4
|
+
//# sourceMappingURL=chartExportFilenames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chartExportFilenames.d.ts","sourceRoot":"","sources":["../../src/report/chartExportFilenames.ts"],"names":[],"mappings":"AAAA,wBAAgB,2BAA2B,CAAC,IAAI,OAAa,GAAG,MAAM,CAKrE;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,EAC9B,IAAI,OAAa,GAChB,MAAM,CAMR;AAED,wBAAgB,mBAAmB,CAAC,IAAI,OAAa,GAAG,MAAM,CAE7D"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function getDatedChartExportBasename(date = new Date()) {
|
|
2
|
+
const year = date.getFullYear();
|
|
3
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
4
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
5
|
+
return `migration-export-${year}-${month}-${day}`;
|
|
6
|
+
}
|
|
7
|
+
export function getChartExportFilename(format, date = new Date()) {
|
|
8
|
+
const base = getDatedChartExportBasename(date);
|
|
9
|
+
if (format === "zip") {
|
|
10
|
+
return `${base}-charts.zip`;
|
|
11
|
+
}
|
|
12
|
+
return `${base}.${format}`;
|
|
13
|
+
}
|
|
14
|
+
export function getChartZipFilename(date = new Date()) {
|
|
15
|
+
return getChartExportFilename("zip", date);
|
|
16
|
+
}
|
|
@@ -19,6 +19,8 @@ export declare const REPORT_CARD_EMPTY_STATE_TITLES: {
|
|
|
19
19
|
readonly operatingSystems: "Operating system data not collected";
|
|
20
20
|
readonly migrationStatus: "Migration status data not collected";
|
|
21
21
|
readonly issuesBreakdown: "Issues breakdown data not collected";
|
|
22
|
+
readonly errors: "Error data not collected";
|
|
23
|
+
readonly warnings: "Warning data not collected";
|
|
22
24
|
readonly hostPowerStates: "Host power state data not collected";
|
|
23
25
|
readonly vmPowerStates: "VM power state data not collected";
|
|
24
26
|
};
|