Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit f861b76

Browse files
committed
fix: kubectl top node should show % text
Fixes #4598
1 parent 9a60197 commit f861b76

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

plugins/plugin-kubectl/view-utilization/src/controller/get-node-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ export async function topNode(
211211

212212
const cpuPercentAttr = row.attributes.find(_ => _.key === 'CPU%')
213213
if (cpuPercentAttr) {
214-
cpuPercentAttr.valueDom = bar({ color: BarColor.CPU, fractionString: cpuPercentAttr.value })
214+
cpuPercentAttr.valueDom = bar({ color: BarColor.CPU, fractionString: cpuPercentAttr.value, text: true })
215215
}
216216

217217
const memoryPercentAttr = row.attributes.find(_ => _.key === 'MEMORY%')
218218
if (memoryPercentAttr) {
219-
memoryPercentAttr.valueDom = bar({ color: BarColor.Memory, fractionString: memoryPercentAttr.value })
219+
memoryPercentAttr.valueDom = bar({ color: BarColor.Memory, fractionString: memoryPercentAttr.value, text: true })
220220
}
221221

222222
const allocatableInfo = detailTable.body.find(_ => _.name === row.name)

plugins/plugin-kubectl/view-utilization/src/view/bar.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ function hasFraction(props: BarProps): props is BarProps & WithFraction {
3131
return typeof (props as WithFraction).fraction === 'number'
3232
}
3333

34+
/** Format as a "xy%" string */
35+
function fractionString(props: BarProps): string {
36+
return hasFraction(props) ? 100 * props.fraction + '%' : props.fractionString
37+
}
38+
3439
/**
3540
* Create a bar, and place it in the given container. If the optional
3641
* initialFraction is given, then set the bar's width to that value.
@@ -44,11 +49,11 @@ export function Bar(props: BarProps) {
4449
const liveStyle = {
4550
backgroundColor: props.color,
4651
bodrerRight: '1px solid var(--color-stripe-02)',
47-
width: hasFraction(props) ? 100 * props.fraction + '%' : props.fractionString
52+
width: fractionString(props)
4853
}
4954

5055
return (
51-
<div style={{ display: 'flex', backgroundColor: 'var(--color-stripe-01)', height: '45%' }}>
56+
<div style={{ display: 'flex', backgroundColor: 'var(--color-stripe-01)', height: '1em', width: '5em' }}>
5257
<div style={liveStyle} />
5358
</div>
5459
)
@@ -66,14 +71,13 @@ export function Bar(props: BarProps) {
6671
export function BarContainer(props: {
6772
children?: React.ReactNode
6873
alignment?: 'space-between' | 'center'
74+
flexDirection?: 'column' | 'row'
6975
onClick?: string
7076
}) {
7177
const style = {
7278
display: 'flex',
73-
flexDirection: 'column' as const,
74-
justifyContent: props.alignment || 'space-between',
75-
width: '5em',
76-
height: '1.375em'
79+
flexDirection: props.flexDirection || ('column' as const),
80+
justifyContent: props.alignment || 'space-between'
7781
}
7882

7983
return props.onClick ? (
@@ -89,14 +93,16 @@ export function BarContainer(props: {
8993
* Create a single bar with its own container, and return the container.
9094
*
9195
*/
92-
export function SingletonBar(props: BarProps) {
96+
type BP = BarProps & { text?: boolean }
97+
export function SingletonBar(props: BP) {
9398
return (
94-
<BarContainer alignment="center">
99+
<BarContainer alignment="center" flexDirection="row">
95100
<Bar {...props} />
101+
{props.text && <span className="even-smaller-text sub-text small-left-pad">{fractionString(props)}</span>}
96102
</BarContainer>
97103
)
98104
}
99105

100-
export function singletonBar(props: BarProps) {
106+
export function singletonBar(props: BP) {
101107
return <SingletonBar {...props} />
102108
}

0 commit comments

Comments
 (0)