Skip to content

Commit 512f371

Browse files
committed
Merge branch 'feat/resource-scan-v2' into demo/resource-browser
2 parents 5f29562 + 6c321c0 commit 512f371

File tree

9 files changed

+84
-3
lines changed

9 files changed

+84
-3
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": "0.0.75-beta-30",
3+
"version": "0.0.75-beta-35",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react'
2+
import { SegmentedBarChartProps, Entity } from './types'
3+
import { FALLBACK_ENTITY } from './constants'
4+
import './styles.scss'
5+
6+
const SegmentedBarChart: React.FC<SegmentedBarChartProps> = ({
7+
entities = [FALLBACK_ENTITY],
8+
rootClassName,
9+
countClassName,
10+
labelClassName,
11+
}) => {
12+
const total = entities.reduce((sum, entity) => entity.value + sum, 0)
13+
14+
const calcSegmentWidth = (entity: Entity) => {
15+
if (!entity.value) {
16+
return '100%'
17+
}
18+
return `${(entity.value / total) * 100}%`
19+
}
20+
21+
return (
22+
<div className={`flexbox-col w-100 dc__gap-12 ${rootClassName}`}>
23+
<div className="flexbox dc__gap-16">
24+
{entities?.map((entity) => (
25+
<div className="flexbox dc__gap-4 dc__align-items-center">
26+
<div className="dot" style={{ backgroundColor: entity.color, width: '10px', height: '10px' }} />
27+
<span className={countClassName}>{entity.value}</span>
28+
<span className={labelClassName}>{entity.label}</span>
29+
</div>
30+
))}
31+
</div>
32+
<div className="flexbox dc__gap-2">
33+
{entities?.map((entity, index, map) => (
34+
<div
35+
key={entity.label}
36+
className={`h-8 ${index === 0 ? 'dc__left-radius-4' : ''} ${
37+
index === map.length - 1 ? 'dc__right-radius-4' : ''
38+
}`}
39+
style={{ backgroundColor: entity.color, width: calcSegmentWidth(entity) }}
40+
/>
41+
))}
42+
</div>
43+
</div>
44+
)
45+
}
46+
47+
export default SegmentedBarChart
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const FALLBACK_ENTITY = {
2+
color: '#B1B7BC',
3+
label: '-',
4+
value: 0,
5+
}

src/Common/SegmentedBarChart/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default as SegmentedBarChart } from './SegmentedBarChart'
2+
export { type SegmentedBarChartProps } from './types'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.rounded-ends {
2+
&:first-child {
3+
border-radius: 100% 0 0 100%;
4+
}
5+
6+
&:last-child {
7+
border-radius: 0 100% 100% 0;
8+
}
9+
}
10+
11+
.dot {
12+
border-radius: 100%;
13+
}

src/Common/SegmentedBarChart/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export type Entity = {
2+
color: string
3+
label: string
4+
value: number
5+
}
6+
7+
export interface SegmentedBarChartProps {
8+
entities: NonNullable<Entity[]>
9+
rootClassName?: string
10+
countClassName?: string
11+
labelClassName?: string
12+
}

src/Common/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ export * from './CustomInput'
5151
export * from './DraggableWrapper'
5252
export * from './Pagination'
5353
export * from './Markdown'
54+
export * from './SegmentedBarChart'

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export interface customEnv {
5151
SERVICE_WORKER_TIMEOUT?: string
5252
ENABLE_RESOURCE_SCAN?: boolean
5353
FEATURE_USER_DEFINED_GITOPS_REPO_ENABLE: boolean
54+
ENABLE_RESOURCE_SCAN_V2?: boolean
5455
}
5556
declare global {
5657
interface Window {

0 commit comments

Comments
 (0)