Fixes for eslint "guard-for-in"

Signed-off-by: Matt Ray <github@mattray.dev>
This commit is contained in:
Matt Ray
2023-06-19 18:41:52 +10:00
committed by Fredrik Adelöw
parent 4d0d3e3207
commit 09ab43fcef
4 changed files with 58 additions and 41 deletions
@@ -81,10 +81,12 @@ function toBarLabels(allocationRange) {
const labels = []
for (const key in keyToFill) {
labels.push({
dataKey: key,
fill: keyToFill[key],
})
if (Object.hasOwn(keyToFill, key)) {
labels.push({
dataKey: key,
fill: keyToFill[key],
})
}
}
return reverse(labels)
@@ -95,24 +97,30 @@ function toBar(datum) {
const bar = {}
for (const key in top) {
const allocation = top[key]
const start = new Date(allocation.start)
bar.start = `${start.getUTCFullYear()}-${start.getUTCMonth()+1}-${start.getUTCDate()}`
bar[allocation.name] = allocation.totalCost
if (Object.hasOwn(top, key)) {
const allocation = top[key]
const start = new Date(allocation.start)
bar.start = `${start.getUTCFullYear()}-${start.getUTCMonth()+1}-${start.getUTCDate()}`
bar[allocation.name] = allocation.totalCost
}
}
for (const key in other) {
const allocation = other[key]
const start = new Date(allocation.start)
bar.start = `${start.getUTCFullYear()}-${start.getUTCMonth()+1}-${start.getUTCDate()}`
bar[allocation.name] = allocation.totalCost
if (Object.hasOwn(other, key)) {
const allocation = other[key]
const start = new Date(allocation.start)
bar.start = `${start.getUTCFullYear()}-${start.getUTCMonth()+1}-${start.getUTCDate()}`
bar[allocation.name] = allocation.totalCost
}
}
for (const key in idle) {
const allocation = idle[key]
const start = new Date(allocation.start)
bar.start = `${start.getUTCFullYear()}-${start.getUTCMonth()+1}-${start.getUTCDate()}`
bar[allocation.name] = allocation.totalCost
if (Object.hasOwn(idle, key)) {
const allocation = idle[key]
const start = new Date(allocation.start)
bar.start = `${start.getUTCFullYear()}-${start.getUTCMonth()+1}-${start.getUTCDate()}`
bar[allocation.name] = allocation.totalCost
}
}
return bar
@@ -23,36 +23,42 @@ function toPieData(top, other, idle) {
const slices = []
for (const i in top) {
const allocation = top[i]
const fill = allocation.name === "__unallocated__"
? "#212121"
: primary[i % primary.length]
if (Object.hasOwn(top, i)) {
const allocation = top[i]
const fill = allocation.name === "__unallocated__"
? "#212121"
: primary[i % primary.length]
slices.push({
name: allocation.name,
value: allocation.totalCost,
fill: fill,
})
slices.push({
name: allocation.name,
value: allocation.totalCost,
fill: fill,
})
}
}
for (const i in other) {
const allocation = other[i]
const fill = browns[i % browns.length]
slices.push({
name: allocation.name,
value: allocation.totalCost,
fill: fill,
})
if (Object.hasOwn(other, i)) {
const allocation = other[i]
const fill = browns[i % browns.length]
slices.push({
name: allocation.name,
value: allocation.totalCost,
fill: fill,
})
}
}
for (const i in idle) {
const allocation = idle[i]
const fill = greyscale[i % greyscale.length]
slices.push({
name: allocation.name,
value: allocation.totalCost,
fill: fill,
})
if (Object.hasOwn(idle, i)) {
const allocation = idle[i]
const fill = greyscale[i % greyscale.length]
slices.push({
name: allocation.name,
value: allocation.totalCost,
fill: fill,
})
}
}
return slices
@@ -156,6 +156,7 @@ const Details = ({
setRows(data)
} catch (e) {
/* eslint no-console: ["error", { allow: ["warn"] }] */
console.warn(`Error fetching details for (${controllerKind}, ${controller}):`, e)
setErrors([{
primary: "Error fetching details",
@@ -174,8 +174,10 @@ export const OpenCostReport = () => {
if (resp.data && resp.data.length > 0) {
const allocationRange = resp.data
for (const i in allocationRange) {
// update cluster aggregations to use clusterName/clusterId names
allocationRange[i] = sortBy(allocationRange[i], a => a.totalCost)
if (Object.hasOwn(allocationRange, i)) {
// update cluster aggregations to use clusterName/clusterId names
allocationRange[i] = sortBy(allocationRange[i], a => a.totalCost)
}
}
setAllocationData(allocationRange)
} else {