@openshift-migration-advisor/shared-components 0.27.0 → 0.28.0-09381b4d22e5

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 (68) hide show
  1. package/dist/charts/MigrationDonutChart.d.ts.map +1 -1
  2. package/dist/charts/MigrationDonutChart.js +7 -0
  3. package/dist/report/ChartExportProvider.d.ts +4 -3
  4. package/dist/report/ChartExportProvider.d.ts.map +1 -1
  5. package/dist/report/ChartExportProvider.js +7 -4
  6. package/dist/report/ClustersOverview.d.ts +24 -0
  7. package/dist/report/ClustersOverview.d.ts.map +1 -0
  8. package/dist/report/ClustersOverview.js +228 -0
  9. package/dist/report/ClustersOverviewStyles.d.ts +12 -0
  10. package/dist/report/ClustersOverviewStyles.d.ts.map +1 -0
  11. package/dist/report/ClustersOverviewStyles.js +101 -0
  12. package/dist/report/CpuAndMemoryOverview.d.ts +19 -0
  13. package/dist/report/CpuAndMemoryOverview.d.ts.map +1 -0
  14. package/dist/report/CpuAndMemoryOverview.js +112 -0
  15. package/dist/report/FeatureStatusBadge.js +1 -1
  16. package/dist/report/ReportExportMenu.d.ts +1 -0
  17. package/dist/report/ReportExportMenu.d.ts.map +1 -1
  18. package/dist/report/ReportExportMenu.js +38 -4
  19. package/dist/report/StorageOverview.d.ts +27 -0
  20. package/dist/report/StorageOverview.d.ts.map +1 -0
  21. package/dist/report/StorageOverview.js +319 -0
  22. package/dist/report/VMMigrationStatus.d.ts +33 -0
  23. package/dist/report/VMMigrationStatus.d.ts.map +1 -0
  24. package/dist/report/VMMigrationStatus.js +129 -0
  25. package/dist/report/captureChartElement.d.ts +6 -1
  26. package/dist/report/captureChartElement.d.ts.map +1 -1
  27. package/dist/report/captureChartElement.js +41 -12
  28. package/dist/report/chartExport.d.ts +23 -0
  29. package/dist/report/chartExport.d.ts.map +1 -1
  30. package/dist/report/chartExport.js +21 -1
  31. package/dist/report/chartExportContext.d.ts +6 -2
  32. package/dist/report/chartExportContext.d.ts.map +1 -1
  33. package/dist/report/dashboardStyles.d.ts +6 -0
  34. package/dist/report/dashboardStyles.d.ts.map +1 -1
  35. package/dist/report/dashboardStyles.js +7 -4
  36. package/dist/report/index.d.ts +7 -3
  37. package/dist/report/index.d.ts.map +1 -1
  38. package/dist/report/index.js +4 -0
  39. package/dist/report/pdfExport.d.ts +2 -2
  40. package/dist/report/pdfExport.d.ts.map +1 -1
  41. package/dist/report/pdfExport.js +52 -3
  42. package/dist/report/reportExportOptions.d.ts +13 -2
  43. package/dist/report/reportExportOptions.d.ts.map +1 -1
  44. package/dist/report/reportExportOptions.js +13 -5
  45. package/package.json +2 -2
  46. package/src/charts/MigrationDonutChart.tsx +9 -0
  47. package/src/report/ChartExportProvider.tsx +18 -6
  48. package/src/report/ClustersOverview.tsx +451 -0
  49. package/src/report/ClustersOverviewStyles.ts +110 -0
  50. package/src/report/CpuAndMemoryOverview.tsx +277 -0
  51. package/src/report/FeatureStatusBadge.tsx +1 -1
  52. package/src/report/ReportExportMenu.tsx +69 -13
  53. package/src/report/StorageOverview.tsx +629 -0
  54. package/src/report/VMMigrationStatus.tsx +358 -0
  55. package/src/report/__tests__/ChartExportProvider.test.tsx +110 -2
  56. package/src/report/__tests__/ClustersOverview.test.tsx +241 -0
  57. package/src/report/__tests__/CpuAndMemoryOverview.test.tsx +200 -0
  58. package/src/report/__tests__/StorageOverview.test.tsx +223 -0
  59. package/src/report/__tests__/VMMigrationStatus.test.tsx +178 -0
  60. package/src/report/__tests__/captureChartElement.test.ts +120 -0
  61. package/src/report/__tests__/chartExportPackagers.test.ts +75 -0
  62. package/src/report/captureChartElement.ts +55 -10
  63. package/src/report/chartExport.ts +41 -1
  64. package/src/report/chartExportContext.tsx +9 -1
  65. package/src/report/dashboardStyles.ts +7 -4
  66. package/src/report/index.ts +24 -0
  67. package/src/report/pdfExport.ts +81 -2
  68. package/src/report/reportExportOptions.ts +28 -5
@@ -0,0 +1,277 @@
1
+ import { css } from "@emotion/css";
2
+ import {
3
+ Card,
4
+ CardBody,
5
+ CardTitle,
6
+ Dropdown,
7
+ DropdownItem,
8
+ DropdownList,
9
+ Flex,
10
+ FlexItem,
11
+ MenuToggle,
12
+ type MenuToggleElement,
13
+ } from "@patternfly/react-core";
14
+ import { DataProcessorIcon } from "@patternfly/react-icons";
15
+ import type { FC, Ref } from "react";
16
+ import { useMemo, useState } from "react";
17
+ import {
18
+ MigrationDonutChart,
19
+ type MigrationDonutChartDatum,
20
+ type MigrationDonutChartLegendVariant,
21
+ } from "../charts/MigrationDonutChart.js";
22
+ import { CardEmptyState } from "./CardEmptyState.js";
23
+ import { ChartHeaderActions } from "./ChartDownloadButton.js";
24
+ import { ChartExportSurface } from "./ChartExportSurface.js";
25
+ import { chartExportViewsFromLabels } from "./chartExport.js";
26
+ import { REPORT_CARD_EMPTY_STATE_TITLES } from "./constants.js";
27
+ import { dashboardStyles } from "./dashboardStyles.js";
28
+
29
+ export interface CpuAndMemoryOverviewProps {
30
+ cpuTierDistribution?: Record<string, number>;
31
+ memoryTierDistribution?: Record<string, number>;
32
+ memoryTotalGB?: number;
33
+ cpuTotalCores?: number;
34
+ /**
35
+ * Memory-tier slice click. The argument is the distribution key.
36
+ * Agent-ui maps it to a VM memory filter; ui-app omits it.
37
+ */
38
+ onTierSelect?: (tierLabel: string) => void;
39
+ /** Center-title click. Agent-ui opens the VM list with no extra filters. */
40
+ onTitleClick?: () => void;
41
+ /** `"html"` in agent-ui; ui-app passes `"chart"`. */
42
+ legendVariant?: MigrationDonutChartLegendVariant;
43
+ }
44
+
45
+ type ViewMode = "memoryTiers" | "vcpuTiers";
46
+
47
+ const VIEW_MODE_LABELS: Record<ViewMode, string> = {
48
+ memoryTiers: "VM distribution by memory size tier",
49
+ vcpuTiers: "VM distribution by vCPU count tier",
50
+ };
51
+
52
+ const VIEW_SUBTITLES: Record<ViewMode, string> = {
53
+ memoryTiers: "Memory size tiers",
54
+ vcpuTiers: "vCPU count tiers",
55
+ };
56
+
57
+ /**
58
+ * Categorical order shared by the agent-ui and ui-app CPU/memory donuts.
59
+ */
60
+ const TIER_COLORS = [
61
+ "#0066cc",
62
+ "#5e40be",
63
+ "#b6a6e9",
64
+ "#73c5c5",
65
+ "#b98412",
66
+ "#28a745",
67
+ "#f0ad4e",
68
+ "#d9534f",
69
+ "#009596",
70
+ "#6a6e73",
71
+ ];
72
+
73
+ const CHART_ID = "cpu-memory-overview";
74
+ const CHART_TITLE = "CPU & memory";
75
+
76
+ const cardSubtitle = css`
77
+ color: var(--pf-t--global--text--color--subtle);
78
+ font-size: 0.85rem;
79
+ `;
80
+
81
+ const menuToggleMinWidth = css`
82
+ min-width: 290px;
83
+ `;
84
+
85
+ const titleRow = css`
86
+ width: 100%;
87
+ `;
88
+
89
+ const isViewMode = (value: string | number | undefined): value is ViewMode =>
90
+ value === "memoryTiers" || value === "vcpuTiers";
91
+
92
+ const tierSortKey = (label: string): number => {
93
+ const value = Number.parseInt(label.trim(), 10);
94
+ return Number.isFinite(value) ? value : Number.MAX_SAFE_INTEGER;
95
+ };
96
+
97
+ const hasUnit = (label: string, unit: "GB" | "cores"): boolean =>
98
+ unit === "GB" ? /gb$/i.test(label) : /cores?$/i.test(label);
99
+
100
+ const slicesFromDistribution = (
101
+ distribution: Record<string, number> | undefined,
102
+ unit: "GB" | "cores",
103
+ ): MigrationDonutChartDatum[] =>
104
+ Object.entries(distribution ?? {})
105
+ .filter(([, count]) => Number(count) > 0)
106
+ .sort(([left], [right]) => tierSortKey(left) - tierSortKey(right))
107
+ .map(([tier, count]) => {
108
+ const trimmed = tier.trim();
109
+ const name = hasUnit(trimmed, unit) ? trimmed : `${trimmed} ${unit}`;
110
+ const vmCount = Number(count);
111
+ return {
112
+ name,
113
+ count: vmCount,
114
+ countDisplay: `${vmCount} VMs`,
115
+ legendCategory: tier,
116
+ };
117
+ });
118
+
119
+ const legendFor = (categories: string[]): Record<string, string> => {
120
+ const legend: Record<string, string> = {};
121
+ categories.forEach((category, index) => {
122
+ const color = TIER_COLORS[index % TIER_COLORS.length];
123
+ if (color) {
124
+ legend[category] = color;
125
+ }
126
+ });
127
+ return legend;
128
+ };
129
+
130
+ export const CpuAndMemoryOverview: FC<CpuAndMemoryOverviewProps> = ({
131
+ cpuTierDistribution,
132
+ memoryTierDistribution,
133
+ memoryTotalGB,
134
+ cpuTotalCores,
135
+ onTierSelect,
136
+ onTitleClick,
137
+ legendVariant = "html",
138
+ }) => {
139
+ const [viewMode, setViewMode] = useState<ViewMode>("memoryTiers");
140
+ const [isDropdownOpen, setIsDropdownOpen] = useState(false);
141
+
142
+ const memorySlices = useMemo(
143
+ () => slicesFromDistribution(memoryTierDistribution, "GB"),
144
+ [memoryTierDistribution],
145
+ );
146
+ const vcpuSlices = useMemo(
147
+ () => slicesFromDistribution(cpuTierDistribution, "cores"),
148
+ [cpuTierDistribution],
149
+ );
150
+
151
+ const activeSlices = viewMode === "memoryTiers" ? memorySlices : vcpuSlices;
152
+ const legend = useMemo(
153
+ () => legendFor(activeSlices.map((slice) => slice.legendCategory)),
154
+ [activeSlices],
155
+ );
156
+ const totalVMs = useMemo(
157
+ () => activeSlices.reduce((sum, slice) => sum + slice.count, 0),
158
+ [activeSlices],
159
+ );
160
+
161
+ const chartTitle = `${CHART_TITLE} — ${VIEW_MODE_LABELS[viewMode]}`;
162
+ const subTitle =
163
+ viewMode === "memoryTiers"
164
+ ? typeof memoryTotalGB === "number"
165
+ ? `${memoryTotalGB.toLocaleString()} GB`
166
+ : undefined
167
+ : typeof cpuTotalCores === "number"
168
+ ? `${cpuTotalCores.toLocaleString()} Cores`
169
+ : undefined;
170
+ const emptyTitle =
171
+ viewMode === "memoryTiers"
172
+ ? REPORT_CARD_EMPTY_STATE_TITLES.memory
173
+ : REPORT_CARD_EMPTY_STATE_TITLES.cpu;
174
+
175
+ return (
176
+ <ChartExportSurface
177
+ id={CHART_ID}
178
+ title={chartTitle}
179
+ exportViews={chartExportViewsFromLabels(CHART_TITLE, VIEW_MODE_LABELS)}
180
+ activeExportViewId={viewMode}
181
+ onExportViewChange={(viewId) => {
182
+ if (isViewMode(viewId)) {
183
+ setViewMode(viewId);
184
+ }
185
+ }}
186
+ >
187
+ <Card className={dashboardStyles.card}>
188
+ <CardTitle>
189
+ <Flex
190
+ className={titleRow}
191
+ justifyContent={{ default: "justifyContentSpaceBetween" }}
192
+ alignItems={{ default: "alignItemsCenter" }}
193
+ >
194
+ <FlexItem>
195
+ <div>
196
+ <div>
197
+ <DataProcessorIcon /> {CHART_TITLE}
198
+ </div>
199
+ <div className={cardSubtitle}>{VIEW_SUBTITLES[viewMode]}</div>
200
+ </div>
201
+ </FlexItem>
202
+ <ChartHeaderActions chartId={CHART_ID} title={chartTitle}>
203
+ <Dropdown
204
+ isOpen={isDropdownOpen}
205
+ onSelect={(_event, value) => {
206
+ if (isViewMode(value)) {
207
+ setViewMode(value);
208
+ }
209
+ setIsDropdownOpen(false);
210
+ }}
211
+ onOpenChange={setIsDropdownOpen}
212
+ toggle={(toggleRef: Ref<MenuToggleElement>) => (
213
+ <MenuToggle
214
+ ref={toggleRef}
215
+ onClick={() => setIsDropdownOpen((open) => !open)}
216
+ isExpanded={isDropdownOpen}
217
+ className={menuToggleMinWidth}
218
+ >
219
+ {VIEW_MODE_LABELS[viewMode]}
220
+ </MenuToggle>
221
+ )}
222
+ >
223
+ <DropdownList>
224
+ <DropdownItem value="memoryTiers" key="memoryTiers">
225
+ {VIEW_MODE_LABELS.memoryTiers}
226
+ </DropdownItem>
227
+ <DropdownItem value="vcpuTiers" key="vcpuTiers">
228
+ {VIEW_MODE_LABELS.vcpuTiers}
229
+ </DropdownItem>
230
+ </DropdownList>
231
+ </Dropdown>
232
+ </ChartHeaderActions>
233
+ </Flex>
234
+ </CardTitle>
235
+ <CardBody className={dashboardStyles.cardBodyScrollable}>
236
+ {activeSlices.length === 0 ? (
237
+ <CardEmptyState title={emptyTitle} />
238
+ ) : (
239
+ <MigrationDonutChart
240
+ legendVariant={legendVariant}
241
+ data={activeSlices}
242
+ legend={legend}
243
+ height={300}
244
+ width={420}
245
+ donutThickness={18}
246
+ titleFontSize={34}
247
+ title={`${totalVMs} VMs`}
248
+ subTitle={subTitle}
249
+ subTitleColor="var(--pf-t--global--text--color--subtle)"
250
+ legendLabelFormatter={({ x, countDisplay }) =>
251
+ `${x} (${countDisplay})`
252
+ }
253
+ tooltipLabelFormatter={({ datum, percent }) =>
254
+ `${datum.countDisplay}\n${percent.toFixed(1)}%`
255
+ }
256
+ itemsPerRow={
257
+ legendVariant === "chart"
258
+ ? Math.ceil(activeSlices.length / 2)
259
+ : undefined
260
+ }
261
+ labelFontSize={legendVariant === "chart" ? 18 : undefined}
262
+ marginLeft={legendVariant === "chart" ? "52%" : undefined}
263
+ onItemClick={
264
+ viewMode === "memoryTiers" && onTierSelect
265
+ ? (item) => onTierSelect(item.legendCategory)
266
+ : undefined
267
+ }
268
+ onTitleClick={onTitleClick}
269
+ />
270
+ )}
271
+ </CardBody>
272
+ </Card>
273
+ </ChartExportSurface>
274
+ );
275
+ };
276
+
277
+ CpuAndMemoryOverview.displayName = "CpuAndMemoryOverview";
@@ -21,7 +21,7 @@ export const FeatureStatusBadge: FC<FeatureStatusBadgeProps> = ({ status }) => {
21
21
  }
22
22
 
23
23
  return (
24
- <Label color="grey" isCompact icon={<TimesCircleIcon />}>
24
+ <Label variant="outline" isCompact icon={<TimesCircleIcon />}>
25
25
  Disabled
26
26
  </Label>
27
27
  );
@@ -1,5 +1,7 @@
1
1
  import {
2
+ Divider,
2
3
  Dropdown,
4
+ DropdownGroup,
3
5
  DropdownItem,
4
6
  DropdownList,
5
7
  MenuToggle,
@@ -7,13 +9,41 @@ import {
7
9
  Spinner,
8
10
  } from "@patternfly/react-core";
9
11
  import { DownloadIcon } from "@patternfly/react-icons";
10
- import { type FC, type Ref, useState } from "react";
12
+ import { type FC, type ReactNode, type Ref, useMemo, useState } from "react";
11
13
  import {
12
14
  type ReportExportOption,
15
+ type ReportExportSection,
13
16
  type StandardReportExportHandlers,
14
17
  standardReportExportOptions,
15
18
  } from "./reportExportOptions.js";
16
19
 
20
+ function sectionGroupKey(section?: ReportExportSection): string | undefined {
21
+ return section?.id;
22
+ }
23
+
24
+ function groupExportOptions(options: ReportExportOption[]): {
25
+ section?: ReportExportSection;
26
+ options: ReportExportOption[];
27
+ }[] {
28
+ const groups: {
29
+ section?: ReportExportSection;
30
+ options: ReportExportOption[];
31
+ }[] = [];
32
+
33
+ for (const option of options) {
34
+ const sectionKey = sectionGroupKey(option.section);
35
+ const last = groups.length > 0 ? groups[groups.length - 1] : undefined;
36
+ const lastKey = last ? sectionGroupKey(last.section) : undefined;
37
+ if (last && lastKey === sectionKey) {
38
+ last.options.push(option);
39
+ } else {
40
+ groups.push({ section: option.section, options: [option] });
41
+ }
42
+ }
43
+
44
+ return groups;
45
+ }
46
+
17
47
  export interface ReportExportMenuProps {
18
48
  options: ReportExportOption[];
19
49
  isLoading?: boolean;
@@ -31,10 +61,44 @@ export const ReportExportMenu: FC<ReportExportMenuProps> = ({
31
61
  }) => {
32
62
  const [isDropdownOpen, setIsDropdownOpen] = useState(false);
33
63
 
64
+ const optionGroups = useMemo(() => groupExportOptions(options), [options]);
65
+
34
66
  if (options.length === 0) {
35
67
  return null;
36
68
  }
37
69
 
70
+ const menuItems: ReactNode[] = [];
71
+ optionGroups.forEach((group, index) => {
72
+ if (index > 0) {
73
+ const dividerKey =
74
+ group.section?.id ?? group.options[0]?.key ?? "ungrouped";
75
+ menuItems.push(
76
+ <Divider key={`divider-before-${dividerKey}`} component="li" />,
77
+ );
78
+ }
79
+
80
+ const items = group.options.map((option) => (
81
+ <DropdownItem
82
+ key={option.key}
83
+ isDisabled={option.isDisabled}
84
+ description={option.description}
85
+ onClick={option.onSelect}
86
+ >
87
+ {option.label}
88
+ </DropdownItem>
89
+ ));
90
+
91
+ if (group.section) {
92
+ menuItems.push(
93
+ <DropdownGroup key={group.section.id} label={group.section.label}>
94
+ {items}
95
+ </DropdownGroup>,
96
+ );
97
+ } else {
98
+ menuItems.push(...items);
99
+ }
100
+ });
101
+
38
102
  return (
39
103
  <Dropdown
40
104
  isOpen={isDropdownOpen}
@@ -70,18 +134,7 @@ export const ReportExportMenu: FC<ReportExportMenuProps> = ({
70
134
  </MenuToggle>
71
135
  )}
72
136
  >
73
- <DropdownList>
74
- {options.map((option) => (
75
- <DropdownItem
76
- key={option.key}
77
- isDisabled={option.isDisabled}
78
- description={option.description}
79
- onClick={option.onSelect}
80
- >
81
- {option.label}
82
- </DropdownItem>
83
- ))}
84
- </DropdownList>
137
+ <DropdownList>{menuItems}</DropdownList>
85
138
  </Dropdown>
86
139
  );
87
140
  };
@@ -94,6 +147,7 @@ export interface ExportReportButtonProps extends StandardReportExportHandlers {
94
147
  loadingLabel?: string | null;
95
148
  isDisabled?: boolean;
96
149
  toggleLabel?: string;
150
+ assessmentSectionLabel?: string;
97
151
  }
98
152
 
99
153
  export const ExportReportButton: FC<ExportReportButtonProps> = ({
@@ -101,6 +155,7 @@ export const ExportReportButton: FC<ExportReportButtonProps> = ({
101
155
  onExportPng,
102
156
  onExportHtml,
103
157
  extraOptions = [],
158
+ assessmentSectionLabel,
104
159
  ...menuProps
105
160
  }) => (
106
161
  <ReportExportMenu
@@ -109,6 +164,7 @@ export const ExportReportButton: FC<ExportReportButtonProps> = ({
109
164
  onExportPdf,
110
165
  onExportPng,
111
166
  onExportHtml,
167
+ assessmentSectionLabel,
112
168
  }),
113
169
  ...extraOptions,
114
170
  ]}