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

Commit a7d121c

Browse files
authored
fix: LSDV-5090: Hidden regions notifications is displaying when filter is applied (#1367)
* fix: LSDV-5090: Hidden regions notifications is displaying when filter is applied * fix typo * remove comments * remove duplicated code * add an observe to update regions when created with filtered added * add back inputRef validation * remove extra space
1 parent 46c1bea commit a7d121c

File tree

3 files changed

+120
-20
lines changed

3 files changed

+120
-20
lines changed

src/components/SidePanels/OutlinerPanel/OutlinerPanel.tsx

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ interface OutlinerPanelProps extends PanelProps {
1111
regions: any;
1212
}
1313

14+
interface OutlinerTreeComponentProps {
15+
regions: any;
16+
}
17+
1418
const OutlinerPanelComponent: FC<OutlinerPanelProps> = ({ regions, ...props }) => {
1519
const [group, setGroup] = useState();
1620
const onOrderingChange = useCallback((value) => {
@@ -43,16 +47,7 @@ const OutlinerPanelComponent: FC<OutlinerPanelProps> = ({ regions, ...props }) =
4347
onGroupingChange={onGroupingChange}
4448
onFilterChange={onFilterChange}
4549
/>
46-
{regions?.regions?.length > 0 ? (
47-
<OutlinerTree
48-
regions={regions}
49-
selectedKeys={regions.selection.keys}
50-
/>
51-
) : (
52-
<Elem name="empty">
53-
Regions not added
54-
</Elem>
55-
)}
50+
<OutlinerTreeComponent regions={regions} />
5651
</PanelBase>
5752
);
5853
};
@@ -70,10 +65,6 @@ const OutlinerStandAlone: FC<OutlinerPanelProps> = ({ regions }) => {
7065
regions.setFilteredRegions(value);
7166
}, [regions]);
7267

73-
const hiddenRegions = useMemo(() => {
74-
return (regions?.regions?.length ?? 0) - (regions?.filter?.length ?? 0);
75-
}, [regions?.regions?.length, regions?.filter?.length]);
76-
7768
return (
7869
<Block name="outliner">
7970
<ViewControls
@@ -85,7 +76,23 @@ const OutlinerStandAlone: FC<OutlinerPanelProps> = ({ regions }) => {
8576
onGroupingChange={onGroupingChange}
8677
onFilterChange={onFilterChange}
8778
/>
88-
{(regions?.regions?.length > 0 && regions?.filter?.length === 0) ? (
79+
<OutlinerTreeComponent regions={regions} />
80+
</Block>
81+
);
82+
};
83+
84+
const OutlinerTreeComponent: FC<OutlinerTreeComponentProps> = observer(({ regions }) => {
85+
const allRegionsHidden = regions?.regions?.length > 0 && regions?.filter?.length === 0;
86+
87+
const hiddenRegions = useMemo(() => {
88+
if (!regions?.regions?.length || !regions.filter?.length) return 0;
89+
90+
return regions?.regions?.length - regions?.filter?.length;
91+
}, [regions?.regions?.length, regions?.filter?.length]);
92+
93+
return(
94+
<>
95+
{allRegionsHidden ? (
8996
<Elem name="filters-empty">
9097
<IconInfo width={21} height={20} />
9198
<Elem name="filters-title">All regions hidden</Elem>
@@ -110,9 +117,9 @@ const OutlinerStandAlone: FC<OutlinerPanelProps> = ({ regions }) => {
110117
Regions not added
111118
</Elem>
112119
)}
113-
</Block>
120+
</>
114121
);
115-
};
122+
});
116123

117124
export const OutlinerComponent = observer(OutlinerStandAlone);
118125

src/components/SidePanels/OutlinerPanel/ViewControls.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { SidePanelsContext } from '../SidePanelsContext';
1010
import './ViewControls.styl';
1111
import { Filter } from '../../Filter/Filter';
1212
import { FF_DEV_3873, FF_LSDV_3025, isFF } from '../../../utils/feature-flags';
13+
import { observer } from 'mobx-react';
1314

1415
const { Block, Elem } = BemWithSpecifiContext();
1516

@@ -29,7 +30,7 @@ interface ViewControlsProps {
2930
onFilterChange: (filter: any) => void;
3031
}
3132

32-
export const ViewControls: FC<ViewControlsProps> = ({
33+
export const ViewControls: FC<ViewControlsProps> = observer(({
3334
grouping,
3435
ordering,
3536
regions,
@@ -128,7 +129,7 @@ export const ViewControls: FC<ViewControlsProps> = ({
128129
)}
129130
</Block>
130131
);
131-
};
132+
});
132133

133134
interface LabelInfo {
134135
label: string;

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

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,103 @@ const task = {
8888
};
8989

9090
describe('Filter outliner scenario', () => {
91+
const FF_LSDV_3025 = 'fflag_feat_front_lsdv_3025_outliner_filter_short';
92+
9193
it('Check if filter is visible', () => {
92-
//the test will be created here
9394
LabelStudio.init({
9495
config,
9596
task,
9697
});
98+
99+
LabelStudio.setFeatureFlagsOnPageLoad({
100+
[FF_LSDV_3025]: true,
101+
});
102+
103+
cy.get('[data-cy="filter-button"]').should('be.visible');
104+
});
105+
106+
it('Check if filter is filtering', () => {
107+
LabelStudio.init({
108+
config,
109+
task,
110+
});
111+
112+
LabelStudio.setFeatureFlagsOnPageLoad({
113+
[FF_LSDV_3025]: true,
114+
});
115+
116+
cy.get('[data-cy="filter-button"]').click();
117+
cy.contains('Add Filter').click();
118+
cy.get('[data-testid="operation-dropdown"]').click();
119+
cy.contains('contains').click();
120+
cy.get('[data-testid="filter-input"]').type('Planet');
121+
Sidebar.hasRegions(1);
122+
});
123+
124+
it('Check if filter message is hidden', () => {
125+
LabelStudio.init({
126+
config,
127+
task,
128+
});
129+
130+
LabelStudio.setFeatureFlagsOnPageLoad({
131+
[FF_LSDV_3025]: true,
132+
});
133+
134+
cy.contains('Adjust or remove filters to view').should('not.exist');
135+
});
136+
137+
it('Check if filter message for 1 filter item is showing', () => {
138+
LabelStudio.init({
139+
config,
140+
task,
141+
});
142+
143+
LabelStudio.setFeatureFlagsOnPageLoad({
144+
[FF_LSDV_3025]: true,
145+
});
146+
147+
cy.get('[data-cy="filter-button"]').click();
148+
cy.contains('Add Filter').click();
149+
cy.get('[data-testid="operation-dropdown"]').click();
150+
cy.contains('contains').click();
151+
cy.get('[data-testid="filter-input"]').type('Moonwalker');
152+
cy.contains('There is 1 hidden region').should('be.visible');
153+
});
154+
155+
it('Check if filter message for 2 or more filter items is showing', () => {
156+
LabelStudio.init({
157+
config,
158+
task,
159+
});
160+
161+
LabelStudio.setFeatureFlagsOnPageLoad({
162+
[FF_LSDV_3025]: true,
163+
});
164+
165+
cy.get('[data-cy="filter-button"]').click();
166+
cy.contains('Add Filter').click();
167+
cy.get('[data-testid="operation-dropdown"]').click();
168+
cy.contains('contains').click();
169+
cy.get('[data-testid="filter-input"]').type('Moonwalker ');
170+
cy.contains('There are 2 hidden regions').should('be.visible');
171+
});
172+
173+
it('Check if filter message for all items hidden is showing', () => {
174+
LabelStudio.init({
175+
config,
176+
task,
177+
});
178+
179+
LabelStudio.setFeatureFlagsOnPageLoad({
180+
[FF_LSDV_3025]: true,
181+
});
182+
183+
cy.get('[data-cy="filter-button"]').click();
184+
cy.contains('Add Filter').click();
185+
cy.get('[data-testid="operation-dropdown"]').click();
186+
cy.contains('contains').click();
187+
cy.get('[data-testid="filter-input"]').type('Moonwalker 4');
188+
cy.contains('All regions hidden').should('be.visible');
97189
});
98190
});

0 commit comments

Comments
 (0)