@openshift-migration-advisor/shared-components 0.22.0-dd51551836b7 → 0.23.0-e2d66ca45d64

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/README.md +6 -0
  2. package/dist/charts/MigrationDonutChart.d.ts +18 -1
  3. package/dist/charts/MigrationDonutChart.d.ts.map +1 -1
  4. package/dist/charts/MigrationDonutChart.js +103 -43
  5. package/dist/charts/index.d.ts +1 -1
  6. package/dist/charts/index.d.ts.map +1 -1
  7. package/dist/forms/RadioButtonFormGroup.d.ts.map +1 -1
  8. package/dist/forms/RadioButtonFormGroup.js +2 -2
  9. package/dist/report/FeatureStatusBadge.d.ts +7 -0
  10. package/dist/report/FeatureStatusBadge.d.ts.map +1 -0
  11. package/dist/report/FeatureStatusBadge.js +13 -0
  12. package/dist/report/HostPowerStates.d.ts +9 -0
  13. package/dist/report/HostPowerStates.d.ts.map +1 -0
  14. package/dist/report/HostPowerStates.js +11 -0
  15. package/dist/report/InfrastructureSummary.d.ts +7 -0
  16. package/dist/report/InfrastructureSummary.d.ts.map +1 -0
  17. package/dist/report/InfrastructureSummary.js +5 -0
  18. package/dist/report/OSDistribution.d.ts.map +1 -1
  19. package/dist/report/OSDistribution.js +5 -13
  20. package/dist/report/OsSupportTiersHelpPopover.d.ts.map +1 -1
  21. package/dist/report/OsSupportTiersHelpPopover.js +2 -31
  22. package/dist/report/OsUpgradeNotice.d.ts.map +1 -1
  23. package/dist/report/OsUpgradeNotice.js +1 -5
  24. package/dist/report/PowerStateCard.d.ts +17 -0
  25. package/dist/report/PowerStateCard.d.ts.map +1 -0
  26. package/dist/report/PowerStateCard.js +7 -0
  27. package/dist/report/SupportTierBadge.d.ts.map +1 -1
  28. package/dist/report/SupportTierBadge.js +4 -2
  29. package/dist/report/VCenterClusterDetails.d.ts +10 -0
  30. package/dist/report/VCenterClusterDetails.d.ts.map +1 -0
  31. package/dist/report/VCenterClusterDetails.js +26 -0
  32. package/dist/report/VmPowerStates.d.ts +9 -0
  33. package/dist/report/VmPowerStates.d.ts.map +1 -0
  34. package/dist/report/VmPowerStates.js +11 -0
  35. package/dist/report/constants.d.ts +2 -0
  36. package/dist/report/constants.d.ts.map +1 -1
  37. package/dist/report/constants.js +2 -0
  38. package/dist/report/index.d.ts +10 -0
  39. package/dist/report/index.d.ts.map +1 -1
  40. package/dist/report/index.js +8 -0
  41. package/dist/report/infrastructureSummaryModel.d.ts +82 -0
  42. package/dist/report/infrastructureSummaryModel.d.ts.map +1 -0
  43. package/dist/report/infrastructureSummaryModel.js +139 -0
  44. package/dist/report/powerStates.d.ts +11 -0
  45. package/dist/report/powerStates.d.ts.map +1 -0
  46. package/dist/report/powerStates.js +113 -0
  47. package/package.json +1 -1
  48. package/src/charts/MigrationDonutChart.tsx +232 -111
  49. package/src/charts/index.ts +1 -0
  50. package/src/forms/RadioButtonFormGroup.tsx +10 -3
  51. package/src/report/FeatureStatusBadge.tsx +30 -0
  52. package/src/report/HostPowerStates.tsx +41 -0
  53. package/src/report/InfrastructureSummary.tsx +56 -0
  54. package/src/report/OSDistribution.tsx +60 -67
  55. package/src/report/OsSupportTiersHelpPopover.tsx +32 -61
  56. package/src/report/OsUpgradeNotice.tsx +1 -7
  57. package/src/report/PowerStateCard.tsx +73 -0
  58. package/src/report/SupportTierBadge.tsx +4 -2
  59. package/src/report/VCenterClusterDetails.tsx +211 -0
  60. package/src/report/VmPowerStates.tsx +41 -0
  61. package/src/report/__tests__/HostPowerStates.test.tsx +47 -0
  62. package/src/report/__tests__/InfrastructureSummary.test.tsx +148 -0
  63. package/src/report/__tests__/infrastructureSummaryModel.test.ts +224 -0
  64. package/src/report/__tests__/powerStates.test.ts +70 -0
  65. package/src/report/constants.ts +2 -0
  66. package/src/report/index.ts +56 -0
  67. package/src/report/infrastructureSummaryModel.ts +281 -0
  68. package/src/report/powerStates.ts +169 -0
@@ -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,169 @@
1
+ import type { MigrationDonutChartDatum } from "../charts/MigrationDonutChart.js";
2
+
3
+ export type PowerStateChartModel = {
4
+ slices: MigrationDonutChartDatum[];
5
+ legend: Record<string, string>;
6
+ total: number;
7
+ };
8
+
9
+ const HOST_POWER_CATEGORIES = [
10
+ "Powered on",
11
+ "Powered off",
12
+ "Standby",
13
+ "Not responding",
14
+ "Maintenance",
15
+ ] as const;
16
+
17
+ type HostPowerCategory = (typeof HOST_POWER_CATEGORIES)[number];
18
+
19
+ const HOST_POWER_KEY_ALIASES: Record<string, HostPowerCategory> = {
20
+ poweredon: "Powered on",
21
+ powered_on: "Powered on",
22
+ green: "Powered on",
23
+ poweredoff: "Powered off",
24
+ powered_off: "Powered off",
25
+ standby: "Standby",
26
+ stand_by: "Standby",
27
+ notresponding: "Not responding",
28
+ not_responding: "Not responding",
29
+ gray: "Not responding",
30
+ grey: "Not responding",
31
+ red: "Not responding",
32
+ maintenance: "Maintenance",
33
+ inmaintenance: "Maintenance",
34
+ inmaintenancemode: "Maintenance",
35
+ };
36
+
37
+ export const HOST_POWER_COLORS: Record<string, string> = {
38
+ "Powered on": "#0066cc",
39
+ "Powered off": "#dca614",
40
+ Standby: "#f0ab00",
41
+ "Not responding": "#c9190b",
42
+ Maintenance: "#002f5d",
43
+ };
44
+
45
+ const VM_POWER_CATEGORIES = ["Powered off", "Powered on", "Suspended"] as const;
46
+
47
+ type VmPowerCategory = (typeof VM_POWER_CATEGORIES)[number];
48
+
49
+ const VM_POWER_KEY_ALIASES: Record<string, VmPowerCategory> = {
50
+ poweredoff: "Powered off",
51
+ powered_off: "Powered off",
52
+ poweredon: "Powered on",
53
+ powered_on: "Powered on",
54
+ suspended: "Suspended",
55
+ };
56
+
57
+ export const VM_POWER_COLORS: Record<string, string> = {
58
+ "Powered off": "#0066cc",
59
+ "Powered on": "#dca614",
60
+ Suspended: "#5e40be",
61
+ };
62
+
63
+ const OTHER_COLOR = "#6a6e73";
64
+
65
+ const normalizeKey = (key: string): string =>
66
+ key
67
+ .trim()
68
+ .toLowerCase()
69
+ .replace(/[\s-]+/g, "");
70
+
71
+ const formatUnknownLabel = (key: string): string => {
72
+ const spaced = key
73
+ .replace(/[_-]+/g, " ")
74
+ .replace(/([a-z])([A-Z])/g, "$1 $2")
75
+ .trim();
76
+ if (!spaced) {
77
+ return "Unknown";
78
+ }
79
+ return spaced.charAt(0).toUpperCase() + spaced.slice(1);
80
+ };
81
+
82
+ const toSlice = (
83
+ name: string,
84
+ count: number,
85
+ unit: string,
86
+ ): MigrationDonutChartDatum => ({
87
+ name,
88
+ count,
89
+ legendCategory: name,
90
+ countDisplay: `${count} ${count === 1 ? unit.replace(/s$/, "") : unit}`,
91
+ });
92
+
93
+ const sumCounts = (counts: Record<string, number>): number =>
94
+ Object.values(counts).reduce((total, count) => total + (count || 0), 0);
95
+
96
+ export const buildHostPowerStateChart = (
97
+ hostPowerStates?: Record<string, number>,
98
+ ): PowerStateChartModel => {
99
+ const counts: Record<string, number> = Object.fromEntries(
100
+ HOST_POWER_CATEGORIES.map((category) => [category, 0]),
101
+ );
102
+
103
+ for (const [key, count] of Object.entries(hostPowerStates ?? {})) {
104
+ const mapped = HOST_POWER_KEY_ALIASES[normalizeKey(key)];
105
+ const label = mapped ?? formatUnknownLabel(key);
106
+ counts[label] = (counts[label] ?? 0) + (count || 0);
107
+ }
108
+
109
+ const orderedLabels = [
110
+ ...HOST_POWER_CATEGORIES,
111
+ ...Object.keys(counts).filter(
112
+ (label) => !HOST_POWER_CATEGORIES.includes(label as HostPowerCategory),
113
+ ),
114
+ ];
115
+
116
+ const slices = orderedLabels.map((label) =>
117
+ toSlice(label, counts[label] ?? 0, "hosts"),
118
+ );
119
+
120
+ const legend: Record<string, string> = {};
121
+ for (const label of orderedLabels) {
122
+ legend[label] = HOST_POWER_COLORS[label] ?? OTHER_COLOR;
123
+ }
124
+
125
+ return {
126
+ slices,
127
+ legend,
128
+ total: sumCounts(counts),
129
+ };
130
+ };
131
+
132
+ export const buildVmPowerStateChart = (
133
+ powerStates?: Record<string, number>,
134
+ ): PowerStateChartModel => {
135
+ const counts: Record<string, number> = {
136
+ "Powered off": 0,
137
+ "Powered on": 0,
138
+ };
139
+
140
+ for (const [key, count] of Object.entries(powerStates ?? {})) {
141
+ const mapped = VM_POWER_KEY_ALIASES[normalizeKey(key)];
142
+ const label = mapped ?? formatUnknownLabel(key);
143
+ counts[label] = (counts[label] ?? 0) + (count || 0);
144
+ }
145
+
146
+ const orderedLabels = [
147
+ ...VM_POWER_CATEGORIES.filter(
148
+ (category) => category !== "Suspended" || (counts[category] ?? 0) > 0,
149
+ ),
150
+ ...Object.keys(counts).filter(
151
+ (label) => !VM_POWER_CATEGORIES.includes(label as VmPowerCategory),
152
+ ),
153
+ ];
154
+
155
+ const slices = orderedLabels.map((label) =>
156
+ toSlice(label, counts[label] ?? 0, "VMs"),
157
+ );
158
+
159
+ const legend: Record<string, string> = {};
160
+ for (const label of orderedLabels) {
161
+ legend[label] = VM_POWER_COLORS[label] ?? OTHER_COLOR;
162
+ }
163
+
164
+ return {
165
+ slices,
166
+ legend,
167
+ total: sumCounts(counts),
168
+ };
169
+ };