@openshift-migration-advisor/shared-components 0.23.0 → 0.25.0
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 +6 -0
- package/dist/charts/index.d.ts +1 -1
- package/dist/charts/index.d.ts.map +1 -1
- package/dist/forms/RadioButtonFormGroup.d.ts.map +1 -1
- package/dist/forms/RadioButtonFormGroup.js +2 -2
- package/dist/report/FeatureStatusBadge.d.ts +7 -0
- package/dist/report/FeatureStatusBadge.d.ts.map +1 -0
- package/dist/report/FeatureStatusBadge.js +13 -0
- package/dist/report/HostPowerStates.d.ts +9 -0
- package/dist/report/HostPowerStates.d.ts.map +1 -0
- package/dist/report/HostPowerStates.js +11 -0
- package/dist/report/InfrastructureSummary.d.ts +7 -0
- package/dist/report/InfrastructureSummary.d.ts.map +1 -0
- package/dist/report/InfrastructureSummary.js +5 -0
- package/dist/report/OSDistribution.d.ts.map +1 -1
- package/dist/report/OSDistribution.js +5 -13
- package/dist/report/OsSupportTiersHelpPopover.d.ts.map +1 -1
- package/dist/report/OsSupportTiersHelpPopover.js +2 -31
- package/dist/report/OsUpgradeNotice.d.ts.map +1 -1
- package/dist/report/OsUpgradeNotice.js +1 -5
- package/dist/report/PowerStateCard.d.ts +17 -0
- package/dist/report/PowerStateCard.d.ts.map +1 -0
- package/dist/report/PowerStateCard.js +7 -0
- package/dist/report/SupportTierBadge.d.ts.map +1 -1
- package/dist/report/SupportTierBadge.js +4 -2
- package/dist/report/VCenterClusterDetails.d.ts +10 -0
- package/dist/report/VCenterClusterDetails.d.ts.map +1 -0
- package/dist/report/VCenterClusterDetails.js +26 -0
- package/dist/report/VmPowerStates.d.ts +9 -0
- package/dist/report/VmPowerStates.d.ts.map +1 -0
- package/dist/report/VmPowerStates.js +11 -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/index.d.ts +10 -0
- package/dist/report/index.d.ts.map +1 -1
- package/dist/report/index.js +8 -0
- package/dist/report/infrastructureSummaryModel.d.ts +82 -0
- package/dist/report/infrastructureSummaryModel.d.ts.map +1 -0
- package/dist/report/infrastructureSummaryModel.js +139 -0
- package/dist/report/powerStates.d.ts +11 -0
- package/dist/report/powerStates.d.ts.map +1 -0
- package/dist/report/powerStates.js +113 -0
- package/package.json +1 -1
- package/src/charts/index.ts +1 -0
- package/src/forms/RadioButtonFormGroup.tsx +10 -3
- package/src/report/FeatureStatusBadge.tsx +30 -0
- package/src/report/HostPowerStates.tsx +41 -0
- package/src/report/InfrastructureSummary.tsx +56 -0
- package/src/report/OSDistribution.tsx +60 -67
- package/src/report/OsSupportTiersHelpPopover.tsx +32 -62
- package/src/report/OsUpgradeNotice.tsx +1 -7
- package/src/report/PowerStateCard.tsx +73 -0
- package/src/report/SupportTierBadge.tsx +4 -2
- package/src/report/VCenterClusterDetails.tsx +211 -0
- package/src/report/VmPowerStates.tsx +41 -0
- package/src/report/__tests__/HostPowerStates.test.tsx +47 -0
- package/src/report/__tests__/InfrastructureSummary.test.tsx +148 -0
- package/src/report/__tests__/infrastructureSummaryModel.test.ts +224 -0
- package/src/report/__tests__/powerStates.test.ts +70 -0
- package/src/report/constants.ts +2 -0
- package/src/report/index.ts +56 -0
- package/src/report/infrastructureSummaryModel.ts +281 -0
- package/src/report/powerStates.ts +169 -0
|
@@ -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
|
+
};
|