@openshift-migration-advisor/shared-components 0.25.0-883f4c9ae996 → 0.25.0-db3dbade32ea
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/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/HostsOverview.d.ts +13 -0
- package/dist/report/HostsOverview.d.ts.map +1 -0
- package/dist/report/HostsOverview.js +84 -0
- 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/ReportTable.d.ts +14 -0
- package/dist/report/ReportTable.d.ts.map +1 -0
- package/dist/report/ReportTable.js +23 -0
- 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/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 +5 -0
- package/dist/report/index.d.ts.map +1 -1
- package/dist/report/index.js +5 -0
- package/package.json +1 -1
- package/src/report/ErrorTable.tsx +85 -0
- package/src/report/HostsOverview.tsx +185 -0
- package/src/report/NetworkOverview.tsx +405 -0
- package/src/report/ReportTable.tsx +81 -0
- package/src/report/WarningsTable.tsx +75 -0
- package/src/report/__tests__/HostsOverview.test.tsx +145 -0
- package/src/report/__tests__/NetworkOverview.test.tsx +269 -0
- package/src/report/constants.ts +2 -0
- package/src/report/index.ts +23 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Card,
|
|
3
|
+
CardBody,
|
|
4
|
+
CardTitle,
|
|
5
|
+
Flex,
|
|
6
|
+
FlexItem,
|
|
7
|
+
Icon,
|
|
8
|
+
} from "@patternfly/react-core";
|
|
9
|
+
import { ExclamationCircleIcon } from "@patternfly/react-icons";
|
|
10
|
+
import type React from "react";
|
|
11
|
+
import { CardEmptyState } from "./CardEmptyState.js";
|
|
12
|
+
import { ChartHeaderActions } from "./ChartDownloadButton.js";
|
|
13
|
+
import { ChartExportSurface } from "./ChartExportSurface.js";
|
|
14
|
+
import { REPORT_CARD_EMPTY_STATE_TITLES } from "./constants.js";
|
|
15
|
+
import { dashboardStyles } from "./dashboardStyles.js";
|
|
16
|
+
import { ReportTable } from "./ReportTable.js";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Minimal shape of a migration issue consumed by {@link ErrorTable}. Declared
|
|
20
|
+
* locally so this package does not depend on a specific SDK (`agent-sdk` or
|
|
21
|
+
* `planner-sdk`); callers pass the subset of `MigrationIssue` fields read here.
|
|
22
|
+
*/
|
|
23
|
+
export interface MigrationIssueLike {
|
|
24
|
+
label: string;
|
|
25
|
+
assessment: string;
|
|
26
|
+
count: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ErrorTableProps {
|
|
30
|
+
errors: MigrationIssueLike[];
|
|
31
|
+
/** Optional drill-down callback invoked with an issue's `label`. */
|
|
32
|
+
onConcernClick?: (concernLabel: string) => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const ErrorTable: React.FC<ErrorTableProps> = ({
|
|
36
|
+
errors,
|
|
37
|
+
onConcernClick,
|
|
38
|
+
}) => {
|
|
39
|
+
const handleRowClick = (issue: MigrationIssueLike) => {
|
|
40
|
+
if (issue.label && onConcernClick) {
|
|
41
|
+
onConcernClick(issue.label);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const chartId = "errors-table";
|
|
46
|
+
const chartTitle = "Errors";
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<ChartExportSurface id={chartId} title={chartTitle}>
|
|
50
|
+
<Card className={dashboardStyles.card}>
|
|
51
|
+
<CardTitle>
|
|
52
|
+
<Flex
|
|
53
|
+
justifyContent={{ default: "justifyContentSpaceBetween" }}
|
|
54
|
+
alignItems={{ default: "alignItemsCenter" }}
|
|
55
|
+
>
|
|
56
|
+
<FlexItem>
|
|
57
|
+
<Icon status="danger">
|
|
58
|
+
<ExclamationCircleIcon />
|
|
59
|
+
</Icon>{" "}
|
|
60
|
+
Errors
|
|
61
|
+
</FlexItem>
|
|
62
|
+
<ChartHeaderActions chartId={chartId} title={chartTitle} />
|
|
63
|
+
</Flex>
|
|
64
|
+
</CardTitle>
|
|
65
|
+
<CardBody className={dashboardStyles.cardBodyScrollable}>
|
|
66
|
+
{errors.length === 0 ? (
|
|
67
|
+
<CardEmptyState title={REPORT_CARD_EMPTY_STATE_TITLES.errors} />
|
|
68
|
+
) : (
|
|
69
|
+
<div>
|
|
70
|
+
<ReportTable<MigrationIssueLike>
|
|
71
|
+
data={errors}
|
|
72
|
+
columns={["Description", "Total VMs"]}
|
|
73
|
+
fields={["assessment", "count"]}
|
|
74
|
+
onRowClick={onConcernClick ? handleRowClick : undefined}
|
|
75
|
+
clickableFields={onConcernClick ? ["assessment"] : []}
|
|
76
|
+
/>
|
|
77
|
+
</div>
|
|
78
|
+
)}
|
|
79
|
+
</CardBody>
|
|
80
|
+
</Card>
|
|
81
|
+
</ChartExportSurface>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
ErrorTable.displayName = "ErrorTable";
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { css } from "@emotion/css";
|
|
2
|
+
import {
|
|
3
|
+
Card,
|
|
4
|
+
CardBody,
|
|
5
|
+
CardTitle,
|
|
6
|
+
Flex,
|
|
7
|
+
FlexItem,
|
|
8
|
+
} from "@patternfly/react-core";
|
|
9
|
+
import { ServerIcon } from "@patternfly/react-icons";
|
|
10
|
+
import {
|
|
11
|
+
chart_color_blue_300,
|
|
12
|
+
chart_color_green_300,
|
|
13
|
+
chart_color_purple_100,
|
|
14
|
+
chart_color_purple_300,
|
|
15
|
+
chart_color_teal_200,
|
|
16
|
+
chart_color_yellow_400,
|
|
17
|
+
} from "@patternfly/react-tokens";
|
|
18
|
+
import type { FC } from "react";
|
|
19
|
+
import { useMemo } from "react";
|
|
20
|
+
import {
|
|
21
|
+
MigrationDonutChart,
|
|
22
|
+
type MigrationDonutChartDatum,
|
|
23
|
+
type MigrationDonutChartLegendVariant,
|
|
24
|
+
} from "../charts/MigrationDonutChart.js";
|
|
25
|
+
import { CardEmptyState } from "./CardEmptyState.js";
|
|
26
|
+
import { ChartHeaderActions } from "./ChartDownloadButton.js";
|
|
27
|
+
import { ChartExportSurface } from "./ChartExportSurface.js";
|
|
28
|
+
import { REPORT_CARD_EMPTY_STATE_TITLES } from "./constants.js";
|
|
29
|
+
import { dashboardStyles } from "./dashboardStyles.js";
|
|
30
|
+
|
|
31
|
+
/** Smallest host shape this card reads. Apps pass SDK hosts structurally. */
|
|
32
|
+
export interface HostLike {
|
|
33
|
+
model?: string | number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface HostsOverviewProps {
|
|
37
|
+
hosts?: HostLike[];
|
|
38
|
+
/** `"html"` in agent-ui; ui-app passes `"chart"`. */
|
|
39
|
+
legendVariant?: MigrationDonutChartLegendVariant;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const TOP_HOST_MODELS = 5;
|
|
43
|
+
const OTHER_MODELS_LABEL = "Other models";
|
|
44
|
+
const UNKNOWN_MODEL_LABEL = "Unknown model";
|
|
45
|
+
const CHART_ID = "hosts-overview";
|
|
46
|
+
const CHART_TITLE = "Host distribution by model";
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Same categorical order as the ui-app host-model donut, mapped onto
|
|
50
|
+
* PatternFly `chart_color_*` tokens (nearest token where the old hex
|
|
51
|
+
* was not itself a token).
|
|
52
|
+
*/
|
|
53
|
+
const HOST_MODEL_COLORS = [
|
|
54
|
+
chart_color_blue_300.value,
|
|
55
|
+
chart_color_purple_300.value,
|
|
56
|
+
chart_color_purple_100.value,
|
|
57
|
+
chart_color_teal_200.value,
|
|
58
|
+
chart_color_yellow_400.value,
|
|
59
|
+
chart_color_green_300.value,
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
const cardSubtitle = css`
|
|
63
|
+
color: var(--pf-t--global--text--color--subtle);
|
|
64
|
+
font-size: 0.85rem;
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
const hostModelLabel = (model: HostLike["model"]): string => {
|
|
68
|
+
const raw =
|
|
69
|
+
typeof model === "string"
|
|
70
|
+
? model
|
|
71
|
+
: typeof model === "number"
|
|
72
|
+
? String(model)
|
|
73
|
+
: "";
|
|
74
|
+
const trimmed = raw.trim();
|
|
75
|
+
return trimmed !== "" ? trimmed : UNKNOWN_MODEL_LABEL;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const buildHostModelDonut = (
|
|
79
|
+
hosts: HostLike[],
|
|
80
|
+
): {
|
|
81
|
+
slices: MigrationDonutChartDatum[];
|
|
82
|
+
legend: Record<string, string>;
|
|
83
|
+
totalHosts: number;
|
|
84
|
+
} => {
|
|
85
|
+
const counts = new Map<string, number>();
|
|
86
|
+
for (const host of hosts) {
|
|
87
|
+
const label = hostModelLabel(host?.model);
|
|
88
|
+
counts.set(label, (counts.get(label) ?? 0) + 1);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const entries = [...counts.entries()]
|
|
92
|
+
.map(([model, count]) => ({ model, count }))
|
|
93
|
+
.sort((a, b) => b.count - a.count);
|
|
94
|
+
|
|
95
|
+
const top = entries.slice(0, TOP_HOST_MODELS);
|
|
96
|
+
const restSum = entries
|
|
97
|
+
.slice(TOP_HOST_MODELS)
|
|
98
|
+
.reduce((sum, entry) => sum + entry.count, 0);
|
|
99
|
+
|
|
100
|
+
const slices: MigrationDonutChartDatum[] = top.map((entry) => ({
|
|
101
|
+
name: entry.model,
|
|
102
|
+
count: entry.count,
|
|
103
|
+
countDisplay: `${entry.count} hosts`,
|
|
104
|
+
legendCategory: entry.model,
|
|
105
|
+
}));
|
|
106
|
+
|
|
107
|
+
if (restSum > 0) {
|
|
108
|
+
slices.push({
|
|
109
|
+
name: OTHER_MODELS_LABEL,
|
|
110
|
+
count: restSum,
|
|
111
|
+
countDisplay: `${restSum} hosts`,
|
|
112
|
+
legendCategory: OTHER_MODELS_LABEL,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const legend: Record<string, string> = {};
|
|
117
|
+
slices.forEach((slice, index) => {
|
|
118
|
+
const color = HOST_MODEL_COLORS[index % HOST_MODEL_COLORS.length];
|
|
119
|
+
if (color) {
|
|
120
|
+
legend[slice.legendCategory] = color;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
return { slices, legend, totalHosts: hosts.length };
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const HostsOverview: FC<HostsOverviewProps> = ({
|
|
128
|
+
hosts,
|
|
129
|
+
legendVariant = "html",
|
|
130
|
+
}) => {
|
|
131
|
+
const { slices, legend, totalHosts } = useMemo(
|
|
132
|
+
() => buildHostModelDonut(Array.isArray(hosts) ? hosts : []),
|
|
133
|
+
[hosts],
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<ChartExportSurface id={CHART_ID} title={CHART_TITLE}>
|
|
138
|
+
<Card className={dashboardStyles.card}>
|
|
139
|
+
<CardTitle>
|
|
140
|
+
<Flex
|
|
141
|
+
justifyContent={{ default: "justifyContentSpaceBetween" }}
|
|
142
|
+
alignItems={{ default: "alignItemsCenter" }}
|
|
143
|
+
>
|
|
144
|
+
<FlexItem>
|
|
145
|
+
<div>
|
|
146
|
+
<div>
|
|
147
|
+
<ServerIcon /> {CHART_TITLE}
|
|
148
|
+
</div>
|
|
149
|
+
<div className={cardSubtitle}>Top 5 models</div>
|
|
150
|
+
</div>
|
|
151
|
+
</FlexItem>
|
|
152
|
+
<ChartHeaderActions chartId={CHART_ID} title={CHART_TITLE} />
|
|
153
|
+
</Flex>
|
|
154
|
+
</CardTitle>
|
|
155
|
+
<CardBody className={dashboardStyles.cardBodyScrollable}>
|
|
156
|
+
{slices.length === 0 ? (
|
|
157
|
+
<CardEmptyState title={REPORT_CARD_EMPTY_STATE_TITLES.hosts} />
|
|
158
|
+
) : (
|
|
159
|
+
<MigrationDonutChart
|
|
160
|
+
legendVariant={legendVariant}
|
|
161
|
+
data={slices}
|
|
162
|
+
height={300}
|
|
163
|
+
width={420}
|
|
164
|
+
donutThickness={18}
|
|
165
|
+
titleFontSize={34}
|
|
166
|
+
legend={legend}
|
|
167
|
+
legendWidth={680}
|
|
168
|
+
title={`${totalHosts}`}
|
|
169
|
+
subTitle="Hosts"
|
|
170
|
+
subTitleColor="var(--pf-t--global--text--color--subtle)"
|
|
171
|
+
itemsPerRow={2}
|
|
172
|
+
labelFontSize={16}
|
|
173
|
+
marginLeft="0%"
|
|
174
|
+
tooltipLabelFormatter={({ datum, percent }) =>
|
|
175
|
+
`${datum.countDisplay}\n${percent.toFixed(1)}%`
|
|
176
|
+
}
|
|
177
|
+
/>
|
|
178
|
+
)}
|
|
179
|
+
</CardBody>
|
|
180
|
+
</Card>
|
|
181
|
+
</ChartExportSurface>
|
|
182
|
+
);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
HostsOverview.displayName = "HostsOverview";
|
|
@@ -0,0 +1,405 @@
|
|
|
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 { TopologyIcon } from "@patternfly/react-icons";
|
|
15
|
+
import {
|
|
16
|
+
chart_color_black_500,
|
|
17
|
+
chart_color_blue_300,
|
|
18
|
+
chart_color_green_300,
|
|
19
|
+
chart_color_orange_100,
|
|
20
|
+
chart_color_purple_100,
|
|
21
|
+
chart_color_purple_300,
|
|
22
|
+
chart_color_red_orange_200,
|
|
23
|
+
chart_color_teal_200,
|
|
24
|
+
chart_color_teal_400,
|
|
25
|
+
chart_color_yellow_400,
|
|
26
|
+
} from "@patternfly/react-tokens";
|
|
27
|
+
import type { FC, Ref } from "react";
|
|
28
|
+
import { useMemo, useState } from "react";
|
|
29
|
+
import {
|
|
30
|
+
MigrationDonutChart,
|
|
31
|
+
type MigrationDonutChartDatum,
|
|
32
|
+
type MigrationDonutChartLegendVariant,
|
|
33
|
+
} from "../charts/MigrationDonutChart.js";
|
|
34
|
+
import { CardEmptyState } from "./CardEmptyState.js";
|
|
35
|
+
import { ChartHeaderActions } from "./ChartDownloadButton.js";
|
|
36
|
+
import { ChartExportSurface } from "./ChartExportSurface.js";
|
|
37
|
+
import { chartExportViewsFromLabels } from "./chartExport.js";
|
|
38
|
+
import { REPORT_CARD_EMPTY_STATE_TITLES } from "./constants.js";
|
|
39
|
+
import { dashboardStyles } from "./dashboardStyles.js";
|
|
40
|
+
|
|
41
|
+
/** Network fields this card reads. Apps pass SDK networks structurally. */
|
|
42
|
+
export interface NetworkLike {
|
|
43
|
+
vmsCount?: number;
|
|
44
|
+
vlanId?: string | number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Infra fields this card reads. */
|
|
48
|
+
export interface NetworkInfraLike {
|
|
49
|
+
networks?: NetworkLike[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Deprecated NIC histogram used when `distributionByNicCount` is absent. */
|
|
53
|
+
export interface NicCountHistogram {
|
|
54
|
+
data?: number[];
|
|
55
|
+
minValue?: number;
|
|
56
|
+
step?: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** NIC summary fields this card reads from the VM resource breakdown. */
|
|
60
|
+
export interface NicCountSummary {
|
|
61
|
+
total?: number;
|
|
62
|
+
histogram?: NicCountHistogram;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface NetworkOverviewProps {
|
|
66
|
+
infra?: NetworkInfraLike;
|
|
67
|
+
nicCount?: NicCountSummary;
|
|
68
|
+
distributionByNicCount?: Record<string, number>;
|
|
69
|
+
/** `"html"` in agent-ui; ui-app passes `"chart"`. */
|
|
70
|
+
legendVariant?: MigrationDonutChartLegendVariant;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
type ViewMode = "networkDistribution" | "nicCount";
|
|
74
|
+
|
|
75
|
+
const VIEW_MODE_LABELS: Record<ViewMode, string> = {
|
|
76
|
+
networkDistribution: "VM distribution by network",
|
|
77
|
+
nicCount: "VM distribution by NIC count",
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const TOP_NETWORKS = 4;
|
|
81
|
+
const REST_OF_NETWORKS_LABEL = "Rest of networks";
|
|
82
|
+
const CHART_ID = "network-overview";
|
|
83
|
+
const CHART_TITLE = "Networks";
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Categorical order from the ui-app network donut, mapped onto PatternFly
|
|
87
|
+
* `chart_color_*` tokens (nearest token where the old hex was not a token).
|
|
88
|
+
*/
|
|
89
|
+
const NETWORK_COLORS = [
|
|
90
|
+
chart_color_blue_300.value,
|
|
91
|
+
chart_color_purple_300.value,
|
|
92
|
+
chart_color_purple_100.value,
|
|
93
|
+
chart_color_teal_200.value,
|
|
94
|
+
chart_color_yellow_400.value,
|
|
95
|
+
chart_color_green_300.value,
|
|
96
|
+
chart_color_orange_100.value,
|
|
97
|
+
chart_color_red_orange_200.value,
|
|
98
|
+
chart_color_teal_400.value,
|
|
99
|
+
chart_color_black_500.value,
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
const cardSubtitle = css`
|
|
103
|
+
color: var(--pf-t--global--text--color--subtle);
|
|
104
|
+
font-size: 0.85rem;
|
|
105
|
+
`;
|
|
106
|
+
|
|
107
|
+
const menuToggleMinWidth = css`
|
|
108
|
+
min-width: 250px;
|
|
109
|
+
`;
|
|
110
|
+
|
|
111
|
+
const titleRow = css`
|
|
112
|
+
width: 100%;
|
|
113
|
+
`;
|
|
114
|
+
|
|
115
|
+
const isViewMode = (value: string | number | undefined): value is ViewMode =>
|
|
116
|
+
value === "networkDistribution" || value === "nicCount";
|
|
117
|
+
|
|
118
|
+
const legendFor = (categories: string[]): Record<string, string> => {
|
|
119
|
+
const legend: Record<string, string> = {};
|
|
120
|
+
categories.forEach((category, index) => {
|
|
121
|
+
const color = NETWORK_COLORS[index % NETWORK_COLORS.length];
|
|
122
|
+
if (color) {
|
|
123
|
+
legend[category] = color;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return legend;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const vlanLabel = (vlanId: NetworkLike["vlanId"]): string => {
|
|
130
|
+
if (typeof vlanId !== "string" && typeof vlanId !== "number") {
|
|
131
|
+
return "-";
|
|
132
|
+
}
|
|
133
|
+
const value = String(vlanId).trim();
|
|
134
|
+
return value !== "" ? value : "-";
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const buildNetworkDonut = (
|
|
138
|
+
networks: NetworkLike[] | undefined,
|
|
139
|
+
): {
|
|
140
|
+
slices: MigrationDonutChartDatum[];
|
|
141
|
+
legend: Record<string, string>;
|
|
142
|
+
title: string;
|
|
143
|
+
vlanBySlice: Record<string, string>;
|
|
144
|
+
} => {
|
|
145
|
+
const items = (Array.isArray(networks) ? networks : [])
|
|
146
|
+
.map((network) => ({
|
|
147
|
+
vmsCount:
|
|
148
|
+
typeof network?.vmsCount === "number" ? network.vmsCount : Number.NaN,
|
|
149
|
+
vlanId: vlanLabel(network?.vlanId),
|
|
150
|
+
}))
|
|
151
|
+
.filter(
|
|
152
|
+
(network) => Number.isFinite(network.vmsCount) && network.vmsCount >= 0,
|
|
153
|
+
)
|
|
154
|
+
.sort((a, b) => b.vmsCount - a.vmsCount);
|
|
155
|
+
|
|
156
|
+
const totalVMs = items.reduce((sum, network) => sum + network.vmsCount, 0);
|
|
157
|
+
const top = items.slice(0, TOP_NETWORKS);
|
|
158
|
+
const restSum = items
|
|
159
|
+
.slice(TOP_NETWORKS)
|
|
160
|
+
.reduce((sum, network) => sum + network.vmsCount, 0);
|
|
161
|
+
|
|
162
|
+
const vlanBySlice: Record<string, string> = {};
|
|
163
|
+
const slices: MigrationDonutChartDatum[] = top.map((network, index) => {
|
|
164
|
+
const name = `Network ${index + 1}`;
|
|
165
|
+
vlanBySlice[name] = network.vlanId;
|
|
166
|
+
return {
|
|
167
|
+
name,
|
|
168
|
+
count: network.vmsCount,
|
|
169
|
+
countDisplay: `${network.vmsCount} VMs`,
|
|
170
|
+
legendCategory: name,
|
|
171
|
+
};
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
if (restSum > 0) {
|
|
175
|
+
slices.push({
|
|
176
|
+
name: REST_OF_NETWORKS_LABEL,
|
|
177
|
+
count: restSum,
|
|
178
|
+
countDisplay: `${restSum} VMs`,
|
|
179
|
+
legendCategory: REST_OF_NETWORKS_LABEL,
|
|
180
|
+
});
|
|
181
|
+
vlanBySlice[REST_OF_NETWORKS_LABEL] = "-";
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
slices,
|
|
186
|
+
legend: legendFor(slices.map((slice) => slice.legendCategory)),
|
|
187
|
+
title: `${totalVMs}`,
|
|
188
|
+
vlanBySlice,
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const nicBucketLabel = (bucket: string): string => {
|
|
193
|
+
const count = Number.parseInt(bucket, 10);
|
|
194
|
+
if (bucket.endsWith("+")) {
|
|
195
|
+
return `${count}+ NIC`;
|
|
196
|
+
}
|
|
197
|
+
return count === 1 ? "1 NIC" : `${count} NIC`;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const compareNicBuckets = (
|
|
201
|
+
a: { bucket: string },
|
|
202
|
+
b: { bucket: string },
|
|
203
|
+
): number => {
|
|
204
|
+
const aPlus = a.bucket.endsWith("+");
|
|
205
|
+
const bPlus = b.bucket.endsWith("+");
|
|
206
|
+
if (aPlus !== bPlus) {
|
|
207
|
+
return aPlus ? 1 : -1;
|
|
208
|
+
}
|
|
209
|
+
const aNum = Number.parseInt(a.bucket, 10);
|
|
210
|
+
const bNum = Number.parseInt(b.bucket, 10);
|
|
211
|
+
if (Number.isFinite(aNum) && Number.isFinite(bNum)) {
|
|
212
|
+
return aNum - bNum;
|
|
213
|
+
}
|
|
214
|
+
return a.bucket.localeCompare(b.bucket);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const slicesFromBuckets = (
|
|
218
|
+
entries: { bucket: string; count: number }[],
|
|
219
|
+
): MigrationDonutChartDatum[] =>
|
|
220
|
+
entries.map((entry) => {
|
|
221
|
+
const label = nicBucketLabel(entry.bucket);
|
|
222
|
+
return {
|
|
223
|
+
name: label,
|
|
224
|
+
count: entry.count,
|
|
225
|
+
countDisplay: `${entry.count} VMs`,
|
|
226
|
+
legendCategory: label,
|
|
227
|
+
};
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
const buildNicDonut = (
|
|
231
|
+
distributionByNicCount: Record<string, number> | undefined,
|
|
232
|
+
nicCount: NicCountSummary | undefined,
|
|
233
|
+
): {
|
|
234
|
+
slices: MigrationDonutChartDatum[];
|
|
235
|
+
legend: Record<string, string>;
|
|
236
|
+
title: string;
|
|
237
|
+
} => {
|
|
238
|
+
if (distributionByNicCount != null) {
|
|
239
|
+
const entries = Object.entries(distributionByNicCount)
|
|
240
|
+
.map(([bucket, value]) => ({
|
|
241
|
+
bucket,
|
|
242
|
+
count: Number.isFinite(Number(value)) ? Number(value) : 0,
|
|
243
|
+
}))
|
|
244
|
+
.filter((entry) => entry.count > 0)
|
|
245
|
+
.sort(compareNicBuckets);
|
|
246
|
+
const slices = slicesFromBuckets(entries);
|
|
247
|
+
const total = entries.reduce((sum, entry) => sum + entry.count, 0);
|
|
248
|
+
return {
|
|
249
|
+
slices,
|
|
250
|
+
legend: legendFor(slices.map((slice) => slice.legendCategory)),
|
|
251
|
+
title: `${total}`,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const histogram = nicCount?.histogram;
|
|
256
|
+
const data = Array.isArray(histogram?.data) ? histogram.data : [];
|
|
257
|
+
const minValue =
|
|
258
|
+
typeof histogram?.minValue === "number" ? histogram.minValue : 0;
|
|
259
|
+
const step = typeof histogram?.step === "number" ? histogram.step : 1;
|
|
260
|
+
const buckets = data
|
|
261
|
+
.map((count, index) => ({
|
|
262
|
+
bucket: String(minValue + index * step),
|
|
263
|
+
count: Number(count) || 0,
|
|
264
|
+
}))
|
|
265
|
+
.filter((entry) => entry.count > 0)
|
|
266
|
+
.sort((a, b) => Number(a.bucket) - Number(b.bucket));
|
|
267
|
+
const slices = slicesFromBuckets(buckets);
|
|
268
|
+
const total =
|
|
269
|
+
typeof nicCount?.total === "number"
|
|
270
|
+
? nicCount.total
|
|
271
|
+
: buckets.reduce((sum, entry) => sum + entry.count, 0);
|
|
272
|
+
|
|
273
|
+
return {
|
|
274
|
+
slices,
|
|
275
|
+
legend: legendFor(slices.map((slice) => slice.legendCategory)),
|
|
276
|
+
title: `${total}`,
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
export const NetworkOverview: FC<NetworkOverviewProps> = ({
|
|
281
|
+
infra,
|
|
282
|
+
nicCount,
|
|
283
|
+
distributionByNicCount,
|
|
284
|
+
legendVariant = "html",
|
|
285
|
+
}) => {
|
|
286
|
+
const [viewMode, setViewMode] = useState<ViewMode>("networkDistribution");
|
|
287
|
+
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
|
288
|
+
|
|
289
|
+
const networkChart = useMemo(
|
|
290
|
+
() => buildNetworkDonut(infra?.networks),
|
|
291
|
+
[infra?.networks],
|
|
292
|
+
);
|
|
293
|
+
const nicChart = useMemo(
|
|
294
|
+
() => buildNicDonut(distributionByNicCount, nicCount),
|
|
295
|
+
[distributionByNicCount, nicCount],
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
const chartTitle = `${CHART_TITLE} — ${VIEW_MODE_LABELS[viewMode]}`;
|
|
299
|
+
const activeChart =
|
|
300
|
+
viewMode === "networkDistribution" ? networkChart : nicChart;
|
|
301
|
+
const emptyTitle =
|
|
302
|
+
viewMode === "networkDistribution"
|
|
303
|
+
? REPORT_CARD_EMPTY_STATE_TITLES.networks
|
|
304
|
+
: REPORT_CARD_EMPTY_STATE_TITLES.nicCount;
|
|
305
|
+
|
|
306
|
+
return (
|
|
307
|
+
<ChartExportSurface
|
|
308
|
+
id={CHART_ID}
|
|
309
|
+
title={chartTitle}
|
|
310
|
+
exportViews={chartExportViewsFromLabels(CHART_TITLE, VIEW_MODE_LABELS)}
|
|
311
|
+
activeExportViewId={viewMode}
|
|
312
|
+
onExportViewChange={(viewId) => {
|
|
313
|
+
if (isViewMode(viewId)) {
|
|
314
|
+
setViewMode(viewId);
|
|
315
|
+
}
|
|
316
|
+
}}
|
|
317
|
+
>
|
|
318
|
+
<Card className={dashboardStyles.card}>
|
|
319
|
+
<CardTitle>
|
|
320
|
+
<Flex
|
|
321
|
+
className={titleRow}
|
|
322
|
+
justifyContent={{ default: "justifyContentSpaceBetween" }}
|
|
323
|
+
alignItems={{ default: "alignItemsCenter" }}
|
|
324
|
+
>
|
|
325
|
+
<FlexItem>
|
|
326
|
+
<div>
|
|
327
|
+
<div>
|
|
328
|
+
<TopologyIcon /> {CHART_TITLE}
|
|
329
|
+
</div>
|
|
330
|
+
{viewMode === "networkDistribution" && (
|
|
331
|
+
<div className={cardSubtitle}>Top 5 networks</div>
|
|
332
|
+
)}
|
|
333
|
+
</div>
|
|
334
|
+
</FlexItem>
|
|
335
|
+
<ChartHeaderActions chartId={CHART_ID} title={chartTitle}>
|
|
336
|
+
<Dropdown
|
|
337
|
+
isOpen={isDropdownOpen}
|
|
338
|
+
onSelect={(_event, value) => {
|
|
339
|
+
if (isViewMode(value)) {
|
|
340
|
+
setViewMode(value);
|
|
341
|
+
}
|
|
342
|
+
setIsDropdownOpen(false);
|
|
343
|
+
}}
|
|
344
|
+
onOpenChange={setIsDropdownOpen}
|
|
345
|
+
toggle={(toggleRef: Ref<MenuToggleElement>) => (
|
|
346
|
+
<MenuToggle
|
|
347
|
+
ref={toggleRef}
|
|
348
|
+
onClick={() => setIsDropdownOpen((open) => !open)}
|
|
349
|
+
isExpanded={isDropdownOpen}
|
|
350
|
+
className={menuToggleMinWidth}
|
|
351
|
+
>
|
|
352
|
+
{VIEW_MODE_LABELS[viewMode]}
|
|
353
|
+
</MenuToggle>
|
|
354
|
+
)}
|
|
355
|
+
>
|
|
356
|
+
<DropdownList>
|
|
357
|
+
<DropdownItem
|
|
358
|
+
value="networkDistribution"
|
|
359
|
+
key="networkDistribution"
|
|
360
|
+
>
|
|
361
|
+
{VIEW_MODE_LABELS.networkDistribution}
|
|
362
|
+
</DropdownItem>
|
|
363
|
+
<DropdownItem value="nicCount" key="nicCount">
|
|
364
|
+
{VIEW_MODE_LABELS.nicCount}
|
|
365
|
+
</DropdownItem>
|
|
366
|
+
</DropdownList>
|
|
367
|
+
</Dropdown>
|
|
368
|
+
</ChartHeaderActions>
|
|
369
|
+
</Flex>
|
|
370
|
+
</CardTitle>
|
|
371
|
+
<CardBody className={dashboardStyles.cardBodyScrollable}>
|
|
372
|
+
{activeChart.slices.length === 0 ? (
|
|
373
|
+
<CardEmptyState title={emptyTitle} />
|
|
374
|
+
) : (
|
|
375
|
+
<MigrationDonutChart
|
|
376
|
+
legendVariant={legendVariant}
|
|
377
|
+
data={activeChart.slices}
|
|
378
|
+
legend={activeChart.legend}
|
|
379
|
+
height={300}
|
|
380
|
+
width={420}
|
|
381
|
+
donutThickness={18}
|
|
382
|
+
titleFontSize={34}
|
|
383
|
+
title={activeChart.title}
|
|
384
|
+
subTitle="VMs"
|
|
385
|
+
subTitleColor="var(--pf-t--global--text--color--subtle)"
|
|
386
|
+
itemsPerRow={Math.ceil(activeChart.slices.length / 2)}
|
|
387
|
+
labelFontSize={18}
|
|
388
|
+
marginLeft="0%"
|
|
389
|
+
tooltipLabelFormatter={({ datum, percent }) => {
|
|
390
|
+
const summary = `${datum.countDisplay}\n${percent.toFixed(1)}%`;
|
|
391
|
+
if (viewMode !== "networkDistribution") {
|
|
392
|
+
return summary;
|
|
393
|
+
}
|
|
394
|
+
const vlan = networkChart.vlanBySlice[datum.legendCategory];
|
|
395
|
+
return `${summary}\nVLAN: ${vlan ?? "-"}`;
|
|
396
|
+
}}
|
|
397
|
+
/>
|
|
398
|
+
)}
|
|
399
|
+
</CardBody>
|
|
400
|
+
</Card>
|
|
401
|
+
</ChartExportSurface>
|
|
402
|
+
);
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
NetworkOverview.displayName = "NetworkOverview";
|