Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit e811425

Browse files
authored
fix: LSDV-5065: Set filter button active when dropdown is opened (#1368)
* fix: LSDV-5065: Set filter button active when dropdown is opened * fix tests * fix names * collapse css * add styles back to filter lenth in the filter button
1 parent a7d121c commit e811425

File tree

4 files changed

+62
-18
lines changed

4 files changed

+62
-18
lines changed

src/components/Filter/Filter.styl

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,30 @@
77
color #585858
88
width 220px
99

10+
.filter-button
11+
display flex
12+
height 30px
13+
padding 0 7px 0 0
14+
cursor pointer
15+
align-items center
16+
border-radius 4px
1017

11-
.button__filter-length
12-
font-size 11px
13-
font-weight 500
14-
text-align center
15-
color #030852
16-
width 15px
17-
height 20px
18-
line-height 21px
19-
border-radius 2px
20-
background #d6e4ff
21-
margin-left 3px
18+
&:active
19+
&_active
20+
background rgba(65, 60, 74, 0.08)
21+
22+
&__icon
23+
align-items center
24+
display flex
25+
26+
&__filter-length
27+
font-size 11px
28+
font-weight 500
29+
text-align center
30+
color #030852
31+
width 15px
32+
height 20px
33+
line-height 21px
34+
border-radius 2px
35+
background #d6e4ff
36+
margin-left 3px

src/components/Filter/Filter.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const Filter: FC<FilterInterface> = ({
1717
animated = true,
1818
}) => {
1919
const [filterList, setFilterList] = useState<FilterListInterface[]>([]);
20+
const [active, setActive] = useState(false);
2021

2122
useEffect(() => {
2223
onChange(FilterItems(filterData, filterList));
@@ -102,19 +103,24 @@ export const Filter: FC<FilterInterface> = ({
102103
);
103104
}, [filterList, renderFilterList, addNewFilterListItem]);
104105

106+
const onToggle = useCallback((isOpen: boolean) => {
107+
setActive(isOpen);
108+
}, []);
109+
105110
return (
106111
<Dropdown.Trigger
107112
content={renderFilter}
108113
dataTestId={'dropdown'}
109114
animated={animated}
115+
onToggle={onToggle}
110116
>
111-
<Button data-cy={'filter-button'} type="text" style={{ padding: 0, whiteSpace: 'nowrap' }}>
117+
<Block data-testid={'filter-button'} name={'filter-button'} mod={{ active }}>
112118
<Elem name={'icon'}>
113119
<IconFilter />
114120
</Elem>
115121
<Elem name={'text'}>Filter</Elem>
116122
{filterList.length > 0 && <Elem name={'filter-length'} data-testid={'filter-length'}>{filterList.length}</Elem>}
117-
</Button>
123+
</Block>
118124
</Dropdown.Trigger>
119125
);
120126
};

src/components/Filter/__tests__/Filter.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,27 @@ describe('Filter', () => {
196196

197197
expect(filterLength.textContent).toBe('2');
198198
});
199+
200+
test('Filter button should be selected', () => {
201+
const filter = render(<Filter
202+
onChange={mockOnChange}
203+
filterData={filterData}
204+
availableFilters={[{
205+
label: 'Annotation results',
206+
path: 'labelName',
207+
type: 'String',
208+
},
209+
{
210+
label: 'Confidence score',
211+
path: 'score',
212+
type: 'Number',
213+
}]}
214+
/>);
215+
216+
const FilterButton = filter.getByTestId('filter-button');
217+
218+
fireEvent.click(FilterButton);
219+
220+
expect(FilterButton.classList.contains('dm-filter-button_active')).toBe(true);
221+
});
199222
});

tests/functional/specs/outliner/filter.cy.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe('Filter outliner scenario', () => {
100100
[FF_LSDV_3025]: true,
101101
});
102102

103-
cy.get('[data-cy="filter-button"]').should('be.visible');
103+
cy.get('[data-testid="filter-button"]').should('be.visible');
104104
});
105105

106106
it('Check if filter is filtering', () => {
@@ -113,7 +113,7 @@ describe('Filter outliner scenario', () => {
113113
[FF_LSDV_3025]: true,
114114
});
115115

116-
cy.get('[data-cy="filter-button"]').click();
116+
cy.get('[data-testid="filter-button"]').click();
117117
cy.contains('Add Filter').click();
118118
cy.get('[data-testid="operation-dropdown"]').click();
119119
cy.contains('contains').click();
@@ -144,7 +144,7 @@ describe('Filter outliner scenario', () => {
144144
[FF_LSDV_3025]: true,
145145
});
146146

147-
cy.get('[data-cy="filter-button"]').click();
147+
cy.get('[data-testid="filter-button"]').click();
148148
cy.contains('Add Filter').click();
149149
cy.get('[data-testid="operation-dropdown"]').click();
150150
cy.contains('contains').click();
@@ -162,7 +162,7 @@ describe('Filter outliner scenario', () => {
162162
[FF_LSDV_3025]: true,
163163
});
164164

165-
cy.get('[data-cy="filter-button"]').click();
165+
cy.get('[data-testid="filter-button"]').click();
166166
cy.contains('Add Filter').click();
167167
cy.get('[data-testid="operation-dropdown"]').click();
168168
cy.contains('contains').click();
@@ -180,7 +180,7 @@ describe('Filter outliner scenario', () => {
180180
[FF_LSDV_3025]: true,
181181
});
182182

183-
cy.get('[data-cy="filter-button"]').click();
183+
cy.get('[data-testid="filter-button"]').click();
184184
cy.contains('Add Filter').click();
185185
cy.get('[data-testid="operation-dropdown"]').click();
186186
cy.contains('contains').click();

0 commit comments

Comments
 (0)