Skip to content

Commit 100c634

Browse files
authored
Merge pull request #541 from devtron-labs/feat/animate-segmented-bar
feat: add animation in segmented bar
2 parents 42c15b5 + 2f8d4e7 commit 100c634

File tree

12 files changed

+56
-53
lines changed

12 files changed

+56
-53
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.6.1",
3+
"version": "1.6.2",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/Dialogs/ConfirmationDialog.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import {
2323
ConfirmationDialogType,
2424
} from './Types'
2525

26+
/**
27+
* @deprecated use confirmation modal instead
28+
*/
2629
const ConfirmationDialog = ({ className = '', children, close }: ConfirmationDialogType) => (
2730
<VisibleModal2 className="confirmation-dialog" close={close}>
2831
<div onClick={stopPropagation} className={`confirmation-dialog__body ${className}`}>{children}</div>

src/Common/SegmentedBarChart/SegmentedBarChart.tsx

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import React from 'react'
18+
import { motion } from 'framer-motion'
1819
import { SegmentedBarChartProps, Entity } from './types'
1920
import { FALLBACK_ENTITY } from './constants'
2021
import './styles.scss'
@@ -26,9 +27,10 @@ const SegmentedBarChart: React.FC<SegmentedBarChartProps> = ({
2627
labelClassName,
2728
isProportional,
2829
swapLegendAndBar = false,
30+
showAnimationOnBar = false,
2931
}) => {
3032
const total = entities.reduce((sum, entity) => entity.value + sum, 0)
31-
const filteredEntities = entities.filter((entity) => entity.value)
33+
const filteredEntities = entities.filter((entity) => !!entity.value)
3234

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

@@ -46,20 +48,20 @@ const SegmentedBarChart: React.FC<SegmentedBarChartProps> = ({
4648

4749
const renderContent = () => {
4850
if (isProportional) {
49-
return entities
50-
.filter((entity) => !!entity.value)
51-
.map((entity) => (
52-
<div className="flexbox-col">
53-
{renderValue(entity.value, entity.label)}
54-
<div className="flex left dc__gap-6">
55-
<span style={{ backgroundColor: entity.color }} className="h-12 dc__border-radius-2 w-4" />
56-
{renderLabel(entity.label)}
57-
</div>
51+
return filteredEntities.map((entity, idx) => (
52+
// eslint-disable-next-line react/no-array-index-key
53+
<div key={idx} className="flexbox-col">
54+
{renderValue(entity.value, entity.label)}
55+
<div className="flex left dc__gap-6">
56+
<span style={{ backgroundColor: entity.color }} className="h-12 dc__border-radius-2 w-4" />
57+
{renderLabel(entity.label)}
5858
</div>
59-
))
59+
</div>
60+
))
6061
}
61-
return entities.map((entity) => (
62-
<div className={`${isProportional ? 'flexbox-col' : 'flexbox dc__gap-4 dc__align-items-center'}`}>
62+
return entities.map((entity, idx) => (
63+
// eslint-disable-next-line react/no-array-index-key
64+
<div key={idx} className="flexbox dc__gap-4 dc__align-items-center">
6365
<div className="dot" style={{ backgroundColor: entity.color, width: '10px', height: '10px' }} />
6466
{renderValue(entity.value, entity.label)}
6567
{renderLabel(entity.label)}
@@ -78,8 +80,17 @@ const SegmentedBarChart: React.FC<SegmentedBarChartProps> = ({
7880
)
7981

8082
const renderBar = () => (
81-
<div className="flexbox dc__gap-2">
82-
{filteredEntities?.map((entity, index, map) => (
83+
<motion.div
84+
{...(showAnimationOnBar
85+
? {
86+
initial: { width: 0 },
87+
animate: { width: '100%' },
88+
transition: { duration: 0.6 },
89+
}
90+
: {})}
91+
className="flexbox dc__gap-2"
92+
>
93+
{filteredEntities.map((entity, index, map) => (
8394
<div
8495
key={entity.label}
8596
className={`h-8 ${index === 0 ? 'dc__left-radius-4' : ''} ${
@@ -88,7 +99,7 @@ const SegmentedBarChart: React.FC<SegmentedBarChartProps> = ({
8899
style={{ backgroundColor: entity.color, width: calcSegmentWidth(entity) }}
89100
/>
90101
))}
91-
</div>
102+
</motion.div>
92103
)
93104

94105
return (

src/Common/SegmentedBarChart/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ export interface SegmentedBarChartProps {
2727
labelClassName?: string
2828
isProportional?: boolean
2929
swapLegendAndBar?: boolean
30+
showAnimationOnBar?: boolean
3031
}

src/Shared/Components/CICDHistory/DeploymentHistoryConfigDiff/DeploymentHistoryConfigDiffCompare.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ export const DeploymentHistoryConfigDiffCompare = ({
7070
// Set fullscreen for comparing deployment history config
7171
setFullScreenView(true)
7272
// Set default initial sorting
73-
handleSorting(DEPLOYMENT_CONFIG_DIFF_SORT_KEY)
73+
if (sortBy !== DEPLOYMENT_CONFIG_DIFF_SORT_KEY) {
74+
handleSorting(DEPLOYMENT_CONFIG_DIFF_SORT_KEY)
75+
}
7476

7577
return () => {
7678
setConvertVariables(false)

src/Shared/Components/ConfirmationModal/ConfirmationModal.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,20 @@ const ConfirmationModalBody = ({
8282
initial={{ y: 100, opacity: 0, scale: 0.75 }}
8383
animate={{ y: 0, opacity: 1, scale: 1 }}
8484
>
85-
<div className="flexbox-col dc__gap-12 p-20">
85+
<div className="flexbox-col dc__gap-16 p-20">
8686
{cloneElement(RenderIcon, {
8787
className: `${RenderIcon.props?.className ?? ''} icon-dim-48 dc__no-shrink`,
8888
})}
89-
<span className="cn-9 fs-16 fw-6 lh-24 dc__word-break">{title}</span>
9089

91-
{typeof subtitle === 'string' ? (
92-
<span className="cn-8 fs-13 fw-4 lh-20 dc__word-break">{subtitle}</span>
93-
) : (
94-
subtitle
95-
)}
90+
<div className="flexbox-col dc__gap-8">
91+
<span className="cn-9 fs-16 fw-6 lh-24 dc__word-break">{title}</span>
92+
93+
{typeof subtitle === 'string' ? (
94+
<span className="cn-8 fs-13 fw-4 lh-20 dc__word-break">{subtitle}</span>
95+
) : (
96+
subtitle
97+
)}
98+
</div>
9699

97100
{children}
98101

src/Shared/Components/Security/SecurityDetailsCards/SecurityCard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ const SecurityCard = ({
119119
labelClassName="fs-13 fw-4 lh-20 cn-9"
120120
countClassName="fs-13 fw-6 lh-20 cn-7"
121121
swapLegendAndBar
122+
showAnimationOnBar
122123
/>
123124
)}
124125
{subtitle && <span className="cn-9 fs-13 lh-20">{subtitle}</span>}

src/Shared/Components/Security/SecurityModal/SecurityModal.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ const SecurityModal: React.FC<SecurityModalPropsType> = ({
138138
<div className="flexbox-col p-20 dc__gap-16">
139139
{!entities?.length ? null : (
140140
<InfoCard
141+
// Added key so that segmented chart animation is visible on changing category/ subCategory
142+
key={`${state.category}-${state.subCategory}`}
141143
entities={entities}
142144
lastScanTimeString={lastScanTimeString}
143145
scanToolName={scanToolName}

src/Shared/Components/Security/SecurityModal/components/InfoCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { InfoCardPropsType } from '../types'
2424

2525
const InfoCard: React.FC<InfoCardPropsType> = ({ entities, lastScanTimeString, scanToolName, scanToolUrl }) => (
2626
<div className="info-card">
27-
<SegmentedBarChart entities={entities} rootClassName="p-16 fs-13" countClassName="fw-6" />
27+
<SegmentedBarChart entities={entities} rootClassName="p-16 fs-13" countClassName="fw-6" showAnimationOnBar />
2828

2929
{(lastScanTimeString || scanToolName) && (
3030
<>

0 commit comments

Comments
 (0)