Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix not displaying any pie charts when missing only some data #6671

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/renderer/components/+cluster/cluster-pie-charts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ function createLabels(rawLabelData: [string, number | undefined][]): string[] {
return rawLabelData.map(([key, value]) => `${key}: ${value?.toFixed(2) || "N/A"}`);
}

const checkedBytesToUnits = (value: number | undefined) => (
typeof value === "number"
? bytesToUnits(value)
: "N/A"
);

interface Dependencies {
clusterOverviewStore: ClusterOverviewStore;
nodeStore: NodeStore;
Expand Down Expand Up @@ -59,20 +65,16 @@ const NonInjectedClusterPieCharts = observer(({
if (
typeof cpuCapacity !== "number" ||
typeof cpuAllocatableCapacity !== "number" ||
typeof cpuLimits !== "number" ||
typeof podCapacity !== "number" ||
typeof podAllocatableCapacity !== "number" ||
typeof memoryAllocatableCapacity !== "number" ||
typeof memoryCapacity !== "number" ||
typeof memoryLimits !== "number" ||
typeof memoryUsage !== "number" ||
typeof memoryRequests !== "number"
) {
return null;
}

const cpuLimitsOverload = cpuLimits > cpuAllocatableCapacity;
const memoryLimitsOverload = memoryLimits > memoryAllocatableCapacity;
const defaultColor = activeTheme.get().colors.pieChartDefaultColor;

const cpuData: PieChartData = {
Expand Down Expand Up @@ -104,7 +106,7 @@ const NonInjectedClusterPieCharts = observer(({
{
data: [
cpuLimits,
cpuLimitsOverload ? 0 : cpuAllocatableCapacity - cpuLimits,
Math.max(0, cpuAllocatableCapacity - (cpuLimits ?? cpuAllocatableCapacity)),
],
backgroundColor: [
"#3d90ce",
Expand Down Expand Up @@ -151,7 +153,7 @@ const NonInjectedClusterPieCharts = observer(({
{
data: [
memoryLimits,
memoryLimitsOverload ? 0 : memoryAllocatableCapacity - memoryLimits,
Math.max(0, memoryAllocatableCapacity - (memoryLimits ?? memoryAllocatableCapacity)),
],
backgroundColor: [
"#3d90ce",
Expand All @@ -164,7 +166,7 @@ const NonInjectedClusterPieCharts = observer(({
labels: [
`Usage: ${bytesToUnits(memoryUsage)}`,
`Requests: ${bytesToUnits(memoryRequests)}`,
`Limits: ${bytesToUnits(memoryLimits)}`,
`Limits: ${checkedBytesToUnits(memoryLimits)}`,
`Allocatable Capacity: ${bytesToUnits(memoryAllocatableCapacity)}`,
`Capacity: ${bytesToUnits(memoryCapacity)}`,
],
Expand Down Expand Up @@ -208,7 +210,7 @@ const NonInjectedClusterPieCharts = observer(({
defaultColor,
]}
/>
{cpuLimitsOverload && renderLimitWarning()}
{((cpuLimits ?? cpuAllocatableCapacity) > cpuAllocatableCapacity) && renderLimitWarning()}
</div>
<div className={cssNames(styles.chart, "flex column align-center box grow")}>
<PieChart
Expand All @@ -222,7 +224,7 @@ const NonInjectedClusterPieCharts = observer(({
defaultColor,
]}
/>
{memoryLimitsOverload && renderLimitWarning()}
{((memoryLimits ?? memoryAllocatableCapacity) > memoryAllocatableCapacity) && renderLimitWarning()}
</div>
<div className={cssNames(styles.chart, "flex column align-center box grow")}>
<PieChart
Expand Down