Skip to content

Commit 97d0945

Browse files
authored
Merge pull request #468 from devtron-labs/feat/cluster-map-v2
chore: segmented bar updated for proportional
2 parents 0d9460e + 8eb3e9b commit 97d0945

File tree

5 files changed

+89
-16
lines changed

5 files changed

+89
-16
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/SegmentedBarChart/SegmentedBarChart.tsx

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,55 @@ const SegmentedBarChart: React.FC<SegmentedBarChartProps> = ({
2424
rootClassName,
2525
countClassName,
2626
labelClassName,
27+
isProportional,
2728
}) => {
2829
const total = entities.reduce((sum, entity) => entity.value + sum, 0)
2930
const filteredEntities = entities.filter((entity) => entity.value)
3031

3132
const calcSegmentWidth = (entity: Entity) => `${(entity.value / total) * 100}%`
3233

33-
return (
34-
<div className={`flexbox-col w-100 dc__gap-12 ${rootClassName}`}>
35-
<div className="flexbox dc__gap-16">
36-
{entities?.map((entity) => (
37-
<div className="flexbox dc__gap-4 dc__align-items-center">
38-
<div className="dot" style={{ backgroundColor: entity.color, width: '10px', height: '10px' }} />
39-
<span className={countClassName} data-testid={`segmented-bar-chart-${entity.label}-value`}>
40-
{entity.value}
41-
</span>
42-
<span className={labelClassName} data-testid={`segmented-bar-chart-${entity.label}-label`}>
43-
{entity.label}
44-
</span>
34+
const renderLabel = (label: string) => (
35+
<span className={labelClassName} data-testid={`segmented-bar-chart-${label}-label`}>
36+
{label}
37+
</span>
38+
)
39+
40+
const renderValue = (value: string | number, label: string) => (
41+
<span className={countClassName} data-testid={`segmented-bar-chart-${label}-value`}>
42+
{isProportional ? `${value}/${total}` : value}
43+
</span>
44+
)
45+
46+
const renderContent = () => {
47+
if (isProportional) {
48+
return entities
49+
.filter((entity) => !!entity.value)
50+
.map((entity) => (
51+
<div className="flexbox-col">
52+
{renderValue(entity.value, entity.label)}
53+
<div className="flex left dc__gap-6">
54+
<span style={{ backgroundColor: entity.color }} className="h-12 dc__border-radius-2 w-4" />
55+
{renderLabel(entity.label)}
56+
</div>
4557
</div>
46-
))}
58+
))
59+
}
60+
return entities.map((entity) => (
61+
<div className={`${isProportional ? 'flexbox-col' : 'flexbox dc__gap-4 dc__align-items-center'}`}>
62+
<div className="dot" style={{ backgroundColor: entity.color, width: '10px', height: '10px' }} />
63+
{renderValue(entity.value, entity.label)}
64+
{renderLabel(entity.label)}
4765
</div>
66+
))
67+
}
68+
69+
if (!entities.length) {
70+
return null
71+
}
72+
73+
return (
74+
<div className={`flexbox-col w-100 dc__gap-12 ${rootClassName}`}>
75+
<div className={`flexbox ${isProportional ? 'dc__gap-24' : 'dc__gap-16'}`}>{renderContent()}</div>
4876
<div className="flexbox dc__gap-2">
4977
{filteredEntities?.map((entity, index, map) => (
5078
<div

src/Common/SegmentedBarChart/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ export interface SegmentedBarChartProps {
2525
rootClassName?: string
2626
countClassName?: string
2727
labelClassName?: string
28+
isProportional?: boolean
2829
}

src/Pages/ResourceBrowser/types.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,47 @@ export enum ClusterStatusType {
99
UNHEALTHY = 'unhealthy',
1010
CONNECTION_FAILED = 'connection failed',
1111
}
12+
13+
export interface ResourceDetail {
14+
name: string
15+
capacity: string
16+
allocatable: string
17+
usage: string
18+
request: string
19+
limit: string
20+
usagePercentage: string
21+
requestPercentage: string
22+
limitPercentage: string
23+
}
24+
25+
export interface NodeTaintType {
26+
effect: string
27+
key: string
28+
value: string
29+
}
30+
31+
export interface NodeDetailsType {
32+
nodeName: string
33+
nodeGroup: string
34+
taints?: NodeTaintType[]
35+
}
36+
37+
export interface ClusterCapacityType {
38+
name: string
39+
nodeCount: number
40+
nodeK8sVersions: string[]
41+
cpu: ResourceDetail
42+
memory: ResourceDetail
43+
serverVersion: string
44+
nodeDetails?: NodeDetailsType[]
45+
nodeErrors: Record<string, string>[]
46+
status?: ClusterStatusType
47+
isProd: boolean
48+
}
49+
50+
export interface ClusterDetail extends ClusterCapacityType {
51+
id: number
52+
errorInNodeListing: string
53+
nodeNames?: string[]
54+
isVirtualCluster?: boolean
55+
}

0 commit comments

Comments
 (0)