Skip to content

Commit

Permalink
ECOPROJECT-2338: Migration assesment discovery report update (#46)
Browse files Browse the repository at this point in the history
* Change bart chart for pie chart

Signed-off-by: Montse Ortega <[email protected]>

* Add usage bar in Storage table

Signed-off-by: Montse Ortega <[email protected]>

* Changes in legend's label in the pie charts

Signed-off-by: Montse Ortega <[email protected]>

* Changes in titles in discovery report

Signed-off-by: Montse Ortega <[email protected]>

---------

Signed-off-by: Montse Ortega <[email protected]>
  • Loading branch information
ammont82 authored Nov 27, 2024
1 parent 3b24be8 commit 248c3e1
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 25 deletions.
82 changes: 57 additions & 25 deletions apps/demo/src/migration-wizard/steps/discovery/DiscoveryStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Badge,
Flex,
FlexItem,
Progress,
} from "@patternfly/react-core";
import {
CogsIcon,
Expand All @@ -34,7 +35,7 @@ import type {
} from "@migration-planner-ui/api-client/models";
import { useDiscoverySources } from "#/migration-wizard/contexts/discovery-sources/Context";
import { ReportTable } from "./ReportTable";
import { ReportBarChart } from "./ReportBarChart";
import { ReportPieChart } from "./ReportPieChart";

export const DiscoveryStep: React.FC = () => {
const discoverSourcesContext = useDiscoverySources();
Expand Down Expand Up @@ -72,26 +73,41 @@ export const DiscoveryStep: React.FC = () => {
};

const computeStatsViewData: TreeViewDataItem = {
title: "Compute",
title: "Compute per VM",
icon: <MicrochipIcon />,
id: "compute",
name: (
<Flex
fullWidth={{ default: "fullWidth" }}
spaceItems={{ default: "spaceItemsXl" }}
>
<FlexItem>
<ReportBarChart histogram={cpuCores.histogram} title="CPU Cores" />
</FlexItem>
<FlexItem>
<ReportBarChart histogram={ramGB.histogram} title="Memory" />
</FlexItem>
</Flex>
),
name: "",
children: [
{
title: "Details",
id: "compute-details",
name: (
<Flex
fullWidth={{ default: "fullWidth" }}
spaceItems={{ default: "spaceItems4xl" }}
>
<FlexItem>
<ReportPieChart
histogram={cpuCores.histogram}
title="CPU Cores"
legendLabel="CPU Cores"
/>
</FlexItem>
<FlexItem>
<ReportPieChart
histogram={ramGB.histogram}
title="Memory"
legendLabel="GB"
/>
</FlexItem>
</Flex>
),
},
],
};

const diskStatsViewData: TreeViewDataItem = {
title: "Disk size",
title: "Disk size per VM",
icon: <HddIcon />,
name: (
<>
Expand All @@ -108,18 +124,20 @@ export const DiscoveryStep: React.FC = () => {
name: (
<Flex
fullWidth={{ default: "fullWidth" }}
spaceItems={{ default: "spaceItemsXl" }}
spaceItems={{ default: "spaceItems4xl" }}
>
<FlexItem>
<ReportBarChart
<ReportPieChart
histogram={diskGB.histogram}
title="Disk capacity per VM"
title="Disk capacity"
legendLabel="GB"
/>
</FlexItem>
<FlexItem>
<ReportBarChart
<ReportPieChart
histogram={diskCount.histogram}
title="Number of disks per VM"
title="Number of disks"
legendLabel="Disks"
/>
</FlexItem>
</Flex>
Expand Down Expand Up @@ -283,10 +301,24 @@ export const DiscoveryStep: React.FC = () => {
{
title: "Datastores",
name: (
<ReportTable<InfraDatastoresInner>
data={datastores}
columns={["Total", "Free", "Type"]}
fields={["totalCapacityGB", "freeCapacityGB", "type"]}
<ReportTable<
InfraDatastoresInner & {
usage: JSX.Element;
}
>
data={datastores.map((ds) => ({
...ds,
usage: (
<div style={{ width: "200px" }}>
<Progress
value={(ds.freeCapacityGB / ds.totalCapacityGB) * 100}
size="sm"
/>
</div>
),
}))}
columns={["Total", "Free", "Type", "Usage %"]}
fields={["totalCapacityGB", "freeCapacityGB", "type", "usage"]}
/>
),
id: "datastores",
Expand Down
75 changes: 75 additions & 0 deletions apps/demo/src/migration-wizard/steps/discovery/ReportPieChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React from "react";
import { ChartPie } from "@patternfly/react-charts";
import { TextContent, Text } from "@patternfly/react-core";

type ChartBarDataEntry = {
name: string;
x: string;
y: number;
};


function histogramToPieChartData(
histogram: ReportPieChart.Histogram,
legendLabel: string,
): ChartBarDataEntry[] {
const { data } = histogram;
return data
.filter(y => y > 0) // Filtrar valores mayores que 0
.map((y, idx) => ({
name: legendLabel,
x: `${idx + 1} ${legendLabel}`, // Cambia esto según tus necesidades
y,
})).sort((a, b) => a.y - b.y);
}

function getLegendData( histogram: ReportPieChart.Histogram,legendLabel:string): { name: string; }[] {
return histogramToPieChartData(histogram, '').map(d => ({ name: `${d.x} ${legendLabel}: ${d.y} VM` }))
}

// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace ReportPieChart {
export type Histogram = {
data: number[];
minValue: number;
step: number;

};

export type Props = {
histogram: Histogram;
title: string;
legendLabel: string;
};
}

export function ReportPieChart(props: ReportPieChart.Props): React.ReactNode {
const { title, histogram,legendLabel } = props;
return (
<>
<TextContent style={{ textAlign: "center" }}>
<Text>{title}</Text>
</TextContent>
<ChartPie
name={title.toLowerCase().split(" ").join("-")}
ariaDesc={title + " chart"}
ariaTitle={title + " chart"}
constrainToVisibleArea
data={histogramToPieChartData(histogram, legendLabel)}
height={230}
labels={({ datum }) => `${datum.x}: ${datum.y}`}
legendData={getLegendData(histogram,legendLabel)}
legendOrientation="vertical"
legendPosition="right"
padding={{
bottom: 20,
left: 20,
right: 140, // Adjusted to accommodate legend
top: 20,
}}
width={450}
colorScale={['#73BCF7','#73C5C5','#F9E0A2','#BDE5B8','#D2D2D2','#F4B678','#CBC1FF','#FF7468','#7CDBF3','#E4F5BC']}/>

</>
);
}

0 comments on commit 248c3e1

Please sign in to comment.