Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(filter-set): Filter set edge cases #13576

Merged
merged 81 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
2731518
refactor(native-filters): move data mask to root reducer
simcha90 Mar 3, 2021
de6a332
Merge branch 'master' of github.com:apache/superset into filtersState…
simcha90 Mar 3, 2021
6652d19
refactor: update rest stuff for dataMask
simcha90 Mar 3, 2021
266a0a3
refactor: add ownCrrentState to explore
simcha90 Mar 3, 2021
5344dd4
fix: fix immer reducer
simcha90 Mar 4, 2021
2b4bd8f
Merge branch 'master' of github.com:apache/superset into filtersState…
simcha90 Mar 4, 2021
dabfd24
fix: merge with master
simcha90 Mar 4, 2021
802823c
refactor: support explore dataMask
simcha90 Mar 4, 2021
8aed240
refactor: support explore dataMask
simcha90 Mar 4, 2021
a0fa114
docs: add comment
simcha90 Mar 4, 2021
eaec7ef
refactor: remove json stringify
simcha90 Mar 4, 2021
cba3467
fix: fix failed cases
simcha90 Mar 4, 2021
04d6398
feat: filter bat buttons start
simcha90 Mar 4, 2021
af9e35a
fix: fix CR notes
simcha90 Mar 4, 2021
64fb87d
fix: fix cascade filters
simcha90 Mar 4, 2021
57c954f
fix: fix CR notes
simcha90 Mar 4, 2021
bd9b767
Merge branch 'filtersState_to_data_mask' of github.com:simchaNielsen/…
simcha90 Mar 4, 2021
bff44d1
refactor: add clear all
simcha90 Mar 7, 2021
09b594a
fix: fix CR notes
simcha90 Mar 7, 2021
c522391
Merge branch 'master' of github.com:apache/superset into filtersState…
simcha90 Mar 7, 2021
1bf1552
Merge branch 'filtersState_to_data_mask' of github.com:simchaNielsen/…
simcha90 Mar 7, 2021
0527067
fix: fix CR notes
simcha90 Mar 7, 2021
9abe26e
Merge branch 'filtersState_to_data_mask' of github.com:simchaNielsen/…
simcha90 Mar 7, 2021
2d12c37
fix: fix CR notes
simcha90 Mar 7, 2021
84d8cbd
Merge branch 'filtersState_to_data_mask' of github.com:simchaNielsen/…
simcha90 Mar 7, 2021
a9202b1
feat: buttons in filter bar
simcha90 Mar 7, 2021
9ae46b9
Merge branch 'master' of github.com:apache/superset into filter_bar_a…
simcha90 Mar 7, 2021
cdcae95
lint: update imports
simcha90 Mar 7, 2021
6c91054
feat: add tabs for filter sets
simcha90 Mar 7, 2021
844adaa
Merge branch 'master' of github.com:apache/superset into filter-set_tabs
simcha90 Mar 7, 2021
93e5d97
Merge branch 'master' of github.com:apache/superset into filter-set_tabs
simcha90 Mar 7, 2021
04259c2
feat: add buttons to filter set
simcha90 Mar 7, 2021
c053836
Merge branch 'master' of github.com:apache/superset into filter_set_d…
simcha90 Mar 7, 2021
26a0f28
feat: first phase add filter sets
simcha90 Mar 8, 2021
60b1374
fix: undo FF
simcha90 Mar 8, 2021
7985f5d
refactor: continue filter sets
simcha90 Mar 8, 2021
6671c1d
Merge branch 'master' of github.com:apache/superset into filter_set_d…
simcha90 Mar 8, 2021
3af62be
fix: fix CR notes
simcha90 Mar 8, 2021
d7e6b23
Merge branch 'filter_set_design' of github.com:simchaNielsen/incubato…
simcha90 Mar 8, 2021
038e5cc
refactor: header
simcha90 Mar 8, 2021
c7a9849
fix: fix CR notes
simcha90 Mar 8, 2021
d47a1ea
fix: fix CR notes
simcha90 Mar 8, 2021
02800d9
Merge branch 'filter_set_design' of github.com:simchaNielsen/incubato…
simcha90 Mar 8, 2021
4182f51
refactor: continue filter sets
simcha90 Mar 8, 2021
68e32d8
lint: fix lint
simcha90 Mar 8, 2021
f0904de
Merge branch 'filter_set_design' of github.com:simchaNielsen/incubato…
simcha90 Mar 8, 2021
eb8e9b9
refactor: continue filter sets
simcha90 Mar 9, 2021
bdbd0f9
fix: fix filter bar opening
simcha90 Mar 9, 2021
18d39bb
Merge branch 'filter_set_design' of github.com:simchaNielsen/incubato…
simcha90 Mar 9, 2021
33adb45
refactor: continue filter sets
simcha90 Mar 9, 2021
cc82b6a
Merge branch 'master' of github.com:apache/superset into filter_set_d…
simcha90 Mar 9, 2021
8bd69ed
Merge branch 'filter_set_design' of github.com:simchaNielsen/incubato…
simcha90 Mar 9, 2021
376386b
refactor: continue filter sets
simcha90 Mar 9, 2021
db7eccb
refactor: continue filter sets
simcha90 Mar 9, 2021
5d6d39e
Merge branch 'master' of github.com:apache/superset into filter_set_d…
simcha90 Mar 9, 2021
33e182d
feat: filters sets history
simcha90 Mar 9, 2021
5fa0e07
feat: filters sets history
simcha90 Mar 9, 2021
7539f03
fix: filter set name
simcha90 Mar 9, 2021
d887995
refactor: fix expand filters case
simcha90 Mar 9, 2021
a6884a2
Merge branch 'master' of github.com:apache/superset into filter_set_d…
simcha90 Mar 9, 2021
01439b6
fix: fix CR notes
simcha90 Mar 9, 2021
c075d9a
refactor: filter sets
simcha90 Mar 9, 2021
52a66aa
refactor: filter sets
simcha90 Mar 10, 2021
0ee5881
Merge branch 'filter_set_design_2' of github.com:simchaNielsen/incuba…
simcha90 Mar 10, 2021
27c0ca1
refactor: filter sets
simcha90 Mar 10, 2021
34b26b6
refactor: filter sets
simcha90 Mar 10, 2021
a21a394
refactor: update sets
simcha90 Mar 10, 2021
041fe8b
Merge branch 'master' of github.com:apache/superset into filter_set_u…
simcha90 Mar 10, 2021
24dcd16
feat: edit filter set
simcha90 Mar 10, 2021
d8e1bd9
refactor: add warning icon
simcha90 Mar 10, 2021
e558783
fix: fix CR notes
simcha90 Mar 10, 2021
accd1f2
Update superset-frontend/src/dashboard/components/nativeFilters/Filte…
simcha90 Mar 10, 2021
5b3803a
fix: fix CR notes
simcha90 Mar 10, 2021
e882100
Merge branch 'master' of github.com:apache/superset into filter_set_m…
simcha90 Mar 10, 2021
2ada369
feat: filter set edge cases
simcha90 Mar 11, 2021
6a1cfb7
Merge branch 'master' of github.com:apache/superset into filter_set_m…
simcha90 Mar 11, 2021
d66e3ff
lint: fix lint
simcha90 Mar 11, 2021
51c5395
lint: fix TS
simcha90 Mar 14, 2021
3030e8d
refactor: fix CR notes
simcha90 Mar 15, 2021
d4c3fb0
fix: fix CR notes
simcha90 Mar 15, 2021
6c72bbb
fix: fix CR notes
simcha90 Mar 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/* eslint-disable no-param-reassign */
import { styled, t } from '@superset-ui/core';
import { HandlerFunction, styled, t } from '@superset-ui/core';
import React, { useState, useEffect, useMemo } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import cx from 'classnames';
Expand Down Expand Up @@ -52,6 +52,11 @@ const BarWrapper = styled.div`
`;

const Bar = styled.div`
& .ant-typography-edit-content {
left: 0;
margin-top: 0;
width: 100%;
}
position: absolute;
top: 0;
left: 0;
Expand Down Expand Up @@ -169,6 +174,11 @@ interface FiltersBarProps {
directPathToChild?: string[];
}

enum TabIds {
AllFilters = 'allFilters',
FilterSets = 'filterSets',
}

const FilterBar: React.FC<FiltersBarProps> = ({
filtersOpen,
toggleFiltersBar,
Expand All @@ -183,8 +193,10 @@ const FilterBar: React.FC<FiltersBarProps> = ({
const dispatch = useDispatch();
const filterSets = useFilterSets();
const filterSetFilterValues = Object.values(filterSets);
const [isFilterSetChanged, setIsFilterSetChanged] = useState(false);
const [tab, setTab] = useState(TabIds.AllFilters);
const filters = useFilters();
const filterValues = Object.values(filters);
const filterValues = Object.values<Filter>(filters);
const dataMaskApplied = useDataMask();
const canEdit = useSelector<any, boolean>(
({ dashboardInfo }) => dashboardInfo.dash_edit_perm,
Expand Down Expand Up @@ -212,8 +224,8 @@ const FilterBar: React.FC<FiltersBarProps> = ({
}
const areFiltersInitialized = filterValues.every(filterValue =>
areObjectsEqual(
filterValue.defaultValue,
dataMaskSelected[filterValue.id]?.currentState?.value,
filterValue?.defaultValue,
dataMaskSelected[filterValue?.id]?.currentState?.value,
),
);
if (areFiltersInitialized) {
Expand Down Expand Up @@ -245,6 +257,7 @@ const FilterBar: React.FC<FiltersBarProps> = ({
filter: Pick<Filter, 'id'> & Partial<Filter>,
dataMask: Partial<DataMaskState>,
) => {
setIsFilterSetChanged(tab !== TabIds.AllFilters);
setDataMaskSelected(draft => {
const children = cascadeChildren[filter.id] || [];
// force instant updating on initialization or for parent filters
Expand Down Expand Up @@ -338,12 +351,13 @@ const FilterBar: React.FC<FiltersBarProps> = ({
{isFeatureEnabled(FeatureFlag.DASHBOARD_NATIVE_FILTERS_SET) ? (
<StyledTabs
centered
defaultActiveKey="allFilters"
activeKey={editFilterSetId ? 'allFilters' : undefined}
onChange={setTab as HandlerFunction}
defaultActiveKey={TabIds.AllFilters}
activeKey={editFilterSetId ? TabIds.AllFilters : undefined}
>
<Tabs.TabPane
tab={t(`All Filters (${filterValues.length})`)}
key="allFilters"
key={TabIds.AllFilters}
>
{editFilterSetId && (
<EditSection
Expand All @@ -358,12 +372,13 @@ const FilterBar: React.FC<FiltersBarProps> = ({
<Tabs.TabPane
disabled={!!editFilterSetId}
tab={t(`Filter Sets (${filterSetFilterValues.length})`)}
key="filterSets"
key={TabIds.FilterSets}
>
<FilterSets
onEditFilterSet={setEditFilterSetId}
disabled={!isApplyDisabled}
dataMaskSelected={dataMaskSelected}
isFilterSetChanged={isFilterSetChanged}
onFilterSelectionChange={handleFilterSelectionChange}
/>
</Tabs.TabPane>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import React, { FC, useMemo } from 'react';
import React, { FC, useMemo, useState } from 'react';
import { HandlerFunction, styled, t } from '@superset-ui/core';
import { Typography, Tooltip } from 'src/common/components';
import { useDispatch } from 'react-redux';
Expand All @@ -25,8 +25,9 @@ import { setFilterSetsConfiguration } from 'src/dashboard/actions/nativeFilters'
import { DataMaskUnit } from 'src/dataMask/types';
import { WarningOutlined } from '@ant-design/icons';
import { ActionButtons } from './Footer';
import { useDataMask, useFilterSets } from '../state';
import { useDataMask, useFilters, useFilterSets } from '../state';
import { APPLY_FILTERS_HINT, findExistingFilterSet } from './utils';
import { useFilterSetNameDuplicated } from './state';

const Wrapper = styled.div`
display: grid;
Expand Down Expand Up @@ -73,13 +74,26 @@ const EditSection: FC<EditSectionProps> = ({
const dataMaskApplied = useDataMask();
const dispatch = useDispatch();
const filterSets = useFilterSets();
const filters = useFilters();
const filterSetFilterValues = Object.values(filterSets);

const [filterSetName, setFilterSetName] = useState(
filterSets[filterSetId].name,
);

const isFilterSetNameDuplicated = useFilterSetNameDuplicated(
filterSetName,
filterSets[filterSetId].name,
);

const handleSave = () => {
dispatch(
setFilterSetsConfiguration(
filterSetFilterValues.map(filterSet => {
const newFilterSet = {
...filterSet,
name: filterSetName,
nativeFilters: filters,
dataMask: { nativeFilters: { ...dataMaskApplied } },
};
return filterSetId === filterSet.id ? newFilterSet : filterSet;
Expand All @@ -92,20 +106,30 @@ const EditSection: FC<EditSectionProps> = ({
const foundFilterSet = useMemo(
() =>
findExistingFilterSet({
dataMaskApplied,
dataMaskSelected,
filterSetFilterValues,
}),
[dataMaskApplied, dataMaskSelected, filterSetFilterValues],
[dataMaskSelected, filterSetFilterValues],
);

const isDuplicateFilterSet =
foundFilterSet && foundFilterSet.id !== filterSetId;

const resultDisabled =
disabled || isDuplicateFilterSet || isFilterSetNameDuplicated;

return (
<Wrapper>
<Title strong>{t('Editing filter set:')}</Title>
<Title>{filterSets[filterSetId].name}</Title>
<Title
editable={{
editing: true,
icon: <span />,
onChange: setFilterSetName,
}}
>
{filterSetName}
</Title>
<ActionButtons>
<Button
ghost
Expand All @@ -117,15 +141,17 @@ const EditSection: FC<EditSectionProps> = ({
{t('Cancel')}
</Button>
<Tooltip
placement="top"
placement="right"
title={
(isFilterSetNameDuplicated &&
t('Filter set with this name already exists')) ||
(isDuplicateFilterSet && t('Filter set already exists')) ||
(disabled && APPLY_FILTERS_HINT)
}
>
<ActionButton disabled={disabled || isDuplicateFilterSet}>
<ActionButton disabled={resultDisabled}>
<Button
disabled={disabled || isDuplicateFilterSet}
disabled={resultDisabled}
buttonStyle="primary"
htmlType="submit"
buttonSize="small"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { FilterSet } from 'src/dashboard/reducers/types';
import { DataMaskUnit } from 'src/dataMask/types';
import { CheckOutlined, EllipsisOutlined } from '@ant-design/icons';
import { HandlerFunction, styled, supersetTheme, t } from '@superset-ui/core';
import { Tooltip } from 'src/common/components/Tooltip';
import FiltersHeader from './FiltersHeader';
import { Filter } from '../../types';

const TitleText = styled.div`
display: flex;
Expand All @@ -41,36 +41,42 @@ const IconsBlock = styled.div`
`;

type FilterSetUnitProps = {
filters: Filter[];
editMode?: boolean;
isApplied?: boolean;
filterSet?: FilterSet;
filterSetName?: string;
dataMaskApplied?: DataMaskUnit;
dataMaskSelected?: DataMaskUnit;
setFilterSetName?: (name: string) => void;
onDelete?: HandlerFunction;
onEdit?: HandlerFunction;
onInvalidate?: HandlerFunction;
};

const FilterSetUnit: FC<FilterSetUnitProps> = ({
filters,
editMode,
setFilterSetName,
onDelete,
onEdit,
filterSetName,
dataMaskApplied,
dataMaskSelected,
filterSet,
isApplied,
onInvalidate,
}) => {
const menu = (
<Menu>
<Menu.Item onClick={onEdit}>{t('Edit')}</Menu.Item>
<Menu.Item onClick={onInvalidate}>
simcha90 marked this conversation as resolved.
Show resolved Hide resolved
<Tooltip placement="right" title={t('It will remove invalid filters')}>
simcha90 marked this conversation as resolved.
Show resolved Hide resolved
{t('Rebuild')}
</Tooltip>
</Menu.Item>
<Menu.Item onClick={onDelete} danger>
{t('Delete')}
</Menu.Item>
</Menu>
);

return (
<>
<TitleText>
Expand Down Expand Up @@ -107,9 +113,8 @@ const FilterSetUnit: FC<FilterSetUnitProps> = ({
</IconsBlock>
</TitleText>
<FiltersHeader
expanded={!filterSet}
dataMask={filterSet?.dataMask?.nativeFilters ?? dataMaskApplied}
filters={filters}
filterSet={filterSet}
dataMask={filterSet?.dataMask?.nativeFilters ?? dataMaskSelected}
/>
</>
);
Expand Down
Loading