Skip to content

Commit 7b61b2d

Browse files
committed
feat: ResourceListTable - update UI for cpu and memory usage
1 parent 9fe3f52 commit 7b61b2d

File tree

3 files changed

+55
-12
lines changed

3 files changed

+55
-12
lines changed

src/components/ResourceBrowser/Constants.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,8 @@ export const NODE_LIST_HEADERS = [
286286
'node group',
287287
'pods',
288288
'taints',
289-
'cpu usage (%)',
290-
'cpu usage (absolute)',
291-
'cpu allocatable',
292-
'mem usage (%)',
293-
'mem usage (absolute)',
294-
'mem allocatable',
289+
'cpu usage',
290+
'mem usage',
295291
'age',
296292
'unschedulable',
297293
] as const
@@ -315,12 +311,8 @@ export const NODE_LIST_HEADERS_TO_KEY_MAP: Record<(typeof NODE_LIST_HEADERS)[num
315311
'node group': 'nodeGroup',
316312
pods: 'podCount',
317313
taints: 'taintCount',
318-
'cpu usage (%)': 'cpu.usagePercentage',
319-
'cpu usage (absolute)': 'cpu.usage',
320-
'cpu allocatable': 'cpu.allocatable',
321-
'mem usage (%)': 'memory.usagePercentage',
322-
'mem usage (absolute)': 'memory.usage',
323-
'mem allocatable': 'memory.allocatable',
314+
'cpu usage': 'cpu.usage',
315+
'mem usage': 'memory.usage',
324316
age: 'age',
325317
unschedulable: 'unschedulable',
326318
} as const

src/components/ResourceBrowser/ResourceList/K8sResourceListTableCellComponent.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { ADD_ENVIRONMENT_FORM_LOCAL_STORAGE_KEY } from '@Pages/GlobalConfigurati
2929
import { AI_BUTTON_CONFIG_MAP, EVENT_LIST, K8S_EMPTY_GROUP, NODE_LIST_HEADERS_TO_KEY_MAP } from '../Constants'
3030
import { ClusterDetailBaseParams } from '../Types'
3131
import { getRenderInvolvedObjectButton, getRenderNodeButton, renderResourceValue } from '../Utils'
32+
import { K8sResourceListTableUsageCell } from './K8sResourceListTableUsageCell'
3233
import NodeActionsMenu from './NodeActionsMenu'
3334
import ResourceBrowserActionMenu from './ResourceBrowserActionMenu'
3435
import { K8sResourceListTableCellComponentProps } from './types'
@@ -210,6 +211,26 @@ const K8sResourceListTableCellComponent = ({
210211
lastSeen: resourceData[EVENT_LIST.dataKeys.lastSeen] as string,
211212
}
212213

214+
if (columnName === 'cpu.usage') {
215+
return (
216+
<K8sResourceListTableUsageCell
217+
percentage={resourceData['cpu.usagePercentage'] as string}
218+
absoluteValue={resourceData['cpu.usage'] as string}
219+
color="var(--B300)"
220+
/>
221+
)
222+
}
223+
224+
if (columnName === 'memory.usage') {
225+
return (
226+
<K8sResourceListTableUsageCell
227+
percentage={resourceData['memory.usagePercentage'] as string}
228+
absoluteValue={resourceData['memory.usage'] as string}
229+
color="var(--V300)"
230+
/>
231+
)
232+
}
233+
213234
return (
214235
<>
215236
{columnName === 'name' ? (
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { SegmentedBarChart } from '@devtron-labs/devtron-fe-common-lib'
2+
3+
export const K8sResourceListTableUsageCell = ({
4+
percentage,
5+
absoluteValue,
6+
color,
7+
}: {
8+
percentage: string
9+
absoluteValue: string
10+
color: string
11+
}) => {
12+
const percentageInNumber = parseInt(percentage, 10)
13+
const usagePercentage = Number.isNaN(percentageInNumber) ? 0 : percentageInNumber
14+
15+
return (
16+
<div className="flexbox-col dc__content-center dc__gap-4">
17+
<div className="flex left dc__gap-8">
18+
<p className="m-0 fs-13 lh-20 cn-9 flex-grow-1">{absoluteValue}</p>
19+
<p className="m-0 fs-13 lh-20 cn-7">{percentage}</p>
20+
</div>
21+
<SegmentedBarChart
22+
entities={[
23+
{ value: usagePercentage, color },
24+
{ value: 100 - usagePercentage, color: 'var(--N200)' },
25+
]}
26+
hideLegend
27+
/>
28+
</div>
29+
)
30+
}

0 commit comments

Comments
 (0)