Skip to content

Commit 9e92935

Browse files
author
Mike Bridge
committed
fix(dashboard): hide "Filters out of scope" section when empty
The "Filters out of scope" collapsible was rendered with a disabled header when no filters were out of scope, showing "Filters out of scope (0)" in the filter bar. The component now is not rendered at all when filtersOutOfScope is empty. - FilterControls.tsx: extract showFiltersOutOfScope condition and add length > 0 check - FiltersDropdownContent: add length > 0 check at the call site - FiltersOutOfScopeCollapsible: remove now-unreachable collapsible="disabled" fallback - Add unit tests covering empty/non-empty/showCollapsePanel cases
1 parent 3a3a653 commit 9e92935

File tree

4 files changed

+78
-3
lines changed

4 files changed

+78
-3
lines changed

superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControls.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ const FilterControls: FC<FilterControlsProps> = ({
222222
chartCustomization: true,
223223
});
224224

225+
const showFiltersOutOfScope =
226+
showCollapsePanel &&
227+
(hideHeader || sectionsOpen.filters) &&
228+
filtersOutOfScope.length > 0;
229+
225230
const toggleSection = useCallback((section: keyof typeof sectionsOpen) => {
226231
setSectionsOpen(prev => ({
227232
...prev,
@@ -343,7 +348,7 @@ const FilterControls: FC<FilterControlsProps> = ({
343348
</SectionContainer>
344349
)}
345350

346-
{showCollapsePanel && (hideHeader || sectionsOpen.filters) && (
351+
{showFiltersOutOfScope && (
347352
<FiltersOutOfScopeCollapsible
348353
filtersOutOfScope={filtersOutOfScope}
349354
renderer={renderer}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import { render, screen } from 'spec/helpers/testing-library';
20+
import { Filter } from '@superset-ui/core';
21+
import { FiltersDropdownContent } from '.';
22+
23+
const buildFilter = (id: string, name: string): Filter =>
24+
({
25+
id,
26+
name,
27+
filterType: 'filter_select',
28+
targets: [{ datasetId: 1, column: { name: 'country' } }],
29+
defaultDataMask: {},
30+
controlValues: {},
31+
cascadeParentIds: [],
32+
scope: { rootPath: ['ROOT_ID'], excluded: [] as string[] },
33+
}) as unknown as Filter;
34+
35+
const baseProps = {
36+
overflowedCrossFilters: [],
37+
filtersInScope: [buildFilter('filter-1', 'In Scope Filter')],
38+
renderer: (filter: any) => <div key={filter.id}>{filter.name}</div>,
39+
rendererCrossFilter: () => null,
40+
showCollapsePanel: true,
41+
forceRenderOutOfScope: false,
42+
};
43+
44+
test('does not render "Filters out of scope" section when filtersOutOfScope is empty', () => {
45+
render(<FiltersDropdownContent {...baseProps} filtersOutOfScope={[]} />);
46+
47+
expect(screen.queryByText(/Filters out of scope/)).not.toBeInTheDocument();
48+
});
49+
50+
test('renders "Filters out of scope" section when one or more filters are out of scope', () => {
51+
render(
52+
<FiltersDropdownContent
53+
{...baseProps}
54+
filtersOutOfScope={[buildFilter('filter-2', 'Out of Scope Filter')]}
55+
/>,
56+
);
57+
58+
expect(screen.getByText(/Filters out of scope/)).toBeInTheDocument();
59+
});
60+
61+
test('does not render "Filters out of scope" section when showCollapsePanel is false', () => {
62+
render(
63+
<FiltersDropdownContent
64+
{...baseProps}
65+
showCollapsePanel={false}
66+
filtersOutOfScope={[buildFilter('filter-2', 'Out of Scope Filter')]}
67+
/>,
68+
);
69+
70+
expect(screen.queryByText(/Filters out of scope/)).not.toBeInTheDocument();
71+
});

superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FiltersDropdownContent/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const FiltersDropdownContent = ({
6161
),
6262
)}
6363
{filtersInScope.map(renderer)}
64-
{showCollapsePanel && (
64+
{showCollapsePanel && filtersOutOfScope.length > 0 && (
6565
<FiltersOutOfScopeCollapsible
6666
filtersOutOfScope={filtersOutOfScope}
6767
renderer={renderer}

superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FiltersOutOfScopeCollapsible/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export const FiltersOutOfScopeCollapsible = ({
3737
ghost
3838
bordered
3939
expandIconPosition="end"
40-
collapsible={filtersOutOfScope.length === 0 ? 'disabled' : undefined}
4140
items={[
4241
{
4342
key: 'out-of-scope-filters',

0 commit comments

Comments
 (0)