Skip to content

Commit 8f7150f

Browse files
committed
fix: update selected options on url change
1 parent 9f7d1c9 commit 8f7150f

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

src/Shared/Components/FilterButton/FilterButton.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2024. Devtron Inc.
33
*/
44

5-
import React, { cloneElement, useState } from 'react'
5+
import React, { cloneElement, useEffect, useState } from 'react'
66
import ReactSelect, { MenuListProps, components } from 'react-select'
77
import { Option } from '@Common/MultiSelectCustomization'
88
import { OptionType } from '@Common/Types'
@@ -74,12 +74,22 @@ const FilterButton: React.FC<FilterButtonPropsType> = ({
7474
handleApplyChange,
7575
getFormattedFilterLabelValue,
7676
menuAlignFromRight,
77+
controlWidth,
7778
}) => {
7879
const [menuIsOpen, setMenuIsOpen] = useState<boolean>(false)
7980
const [selectedOptions, setSelectedOptions] = useState<OptionType[]>(
8081
appliedFilters.map((filter) => ({ value: filter, label: getFormattedFilterLabelValue?.(filter) || filter })),
8182
)
8283

84+
useEffect(() => {
85+
setSelectedOptions(
86+
appliedFilters.map((filter) => ({
87+
value: filter,
88+
label: getFormattedFilterLabelValue?.(filter) || filter,
89+
})),
90+
)
91+
}, [appliedFilters])
92+
8393
const handleMenuOpen = () => {
8494
setMenuIsOpen(true)
8595
}
@@ -117,7 +127,7 @@ const FilterButton: React.FC<FilterButtonPropsType> = ({
117127
Option,
118128
ValueContainer,
119129
}}
120-
styles={getFilterStyle(menuAlignFromRight)}
130+
styles={getFilterStyle(controlWidth, menuAlignFromRight)}
121131
// @ts-ignore NOTE: passing this to use in FilterSelectMenuList
122132
handleApplyFilter={handleApply}
123133
menuIsOpen={menuIsOpen}

src/Shared/Components/FilterButton/types.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export interface FilterButtonPropsType {
88
disabled?: boolean
99
getFormattedFilterLabelValue?: (identifier: string) => string
1010
menuAlignFromRight?: boolean
11+
controlWidth?: string
1112
}
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CommonGroupedDropdownStyles } from '../ReactSelect'
22

3-
export const getFilterStyle = (menuAlignFromRight: boolean) => ({
3+
export const getFilterStyle = (controlWidth?: string, menuAlignFromRight?: boolean) => ({
44
...CommonGroupedDropdownStyles,
55
menu: (base) => ({
66
...base,
@@ -9,8 +9,16 @@ export const getFilterStyle = (menuAlignFromRight: boolean) => ({
99
}),
1010
control: (base, state) => ({
1111
...CommonGroupedDropdownStyles.control(base, state),
12-
width: 'max-content',
13-
maxWidth: '200px',
14-
minWidth: '150px',
12+
maxHeight: '36px',
13+
minHeight: '36px',
14+
fontSize: '12px',
15+
paddingLeft: '8px',
16+
width: controlWidth || '150px',
17+
}),
18+
container: (base) => ({
19+
...base,
20+
height: '36px',
21+
width: controlWidth || '150px',
22+
maxHeight: '36px',
1523
}),
1624
})

0 commit comments

Comments
 (0)