Skip to content

Commit eabc1f0

Browse files
committed
refactor: optimize SegmentedControl dependencies and enhance StatusFilterButtonComponent key handling
- Removed unnecessary dependency from SegmentedControl's useEffect for improved performance. - Added a unique key to the SegmentedControl in StatusFilterButtonComponent to ensure proper re-rendering based on inline filters.
1 parent 2ebf878 commit eabc1f0

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Common/SegmentedControl/SegmentedControl.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const SegmentedControl = ({
3434
style.setProperty('--segmented-control-highlight-width', `${offsetWidth}px`)
3535
style.setProperty('--segmented-control-highlight-x-position', `${offsetLeft}px`)
3636
}
37-
}, [segmentValue, size, fullWidth, segments.length])
37+
}, [segmentValue, size, fullWidth])
3838

3939
const handleSegmentChange = (updatedSegment: SegmentType) => {
4040
if (isUnControlledComponent) {

src/Shared/Components/CICDHistory/StatusFilterButtonComponent.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,15 @@ export const StatusFilterButtonComponent = ({
104104

105105
const segmentValue = segments.find(({ value }) => value === selectedTab)?.value || null
106106

107+
const segmentControlKey = inlineFilters.reduce<string>(
108+
(acc, inlineFilter) => `${acc}-${inlineFilter.count}-${inlineFilter.status}`,
109+
`${allResourceKindFilter.status}-${allResourceKindFilter.count}`,
110+
)
111+
107112
return (
108113
<div className="flexbox status-filter__container">
109114
<SegmentedControl
115+
key={segmentControlKey}
110116
segments={segments}
111117
value={segmentValue}
112118
onChange={handleInlineFilterClick}

0 commit comments

Comments
 (0)