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

refactor(self-trigger): Split native filters state #13137

Merged
merged 51 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
65e5dfd
feat: add cross filters
simcha90 Jan 21, 2021
5d5d9e1
refactor: fix CR notes
simcha90 Jan 24, 2021
e4ec409
lint: fix lint
simcha90 Jan 24, 2021
cadcb2d
lint: fix lint
simcha90 Jan 24, 2021
6db310b
Merge branch 'master' of github.com:apache/superset into cross-filters
simcha90 Jan 26, 2021
d5747b6
Merge branch 'master' of github.com:apache/superset into cross-filters
simcha90 Feb 7, 2021
f063b2e
feat: POC adding filters set feature
simcha90 Feb 9, 2021
4a42e58
Merge branch 'master' of github.com:apache/superset into cross-filters
simcha90 Feb 9, 2021
a477026
chore: pre-commit
Feb 9, 2021
a5d9def
refactor: under chage
simcha90 Feb 10, 2021
cfc7254
Merge branch 'master' of github.com:apache/superset into cross-filters
simcha90 Feb 10, 2021
0c6e69b
Merge branch 'master' of github.com:apache/superset into filter_set
simcha90 Feb 10, 2021
5f1ed67
lint: fix TS
simcha90 Feb 10, 2021
654023f
fix: fix FF name
simcha90 Feb 10, 2021
2bb95ce
Merge branch 'master' of github.com:apache/superset into cross-filters
simcha90 Feb 11, 2021
64768ca
refactor: move to behaviors
simcha90 Feb 11, 2021
d931e06
lint: fix lint
simcha90 Feb 11, 2021
a4777f4
refactor: update state of native filters
simcha90 Feb 14, 2021
c55646b
Merge branch 'master' of github.com:apache/superset into filter_set
simcha90 Feb 14, 2021
fda083f
refactor: finish refactor nativeFilter state
simcha90 Feb 14, 2021
3b97007
feat: split native filters state
simcha90 Feb 15, 2021
dac5d3b
Merge branch 'master' of github.com:apache/superset into private-state
simcha90 Feb 15, 2021
d2cb5c8
refactor: refactor Time filter to use new API
simcha90 Feb 16, 2021
3ec8d1d
Merge branch 'master' of github.com:apache/superset into private-state
simcha90 Feb 17, 2021
b36dadc
refactor: refactor Time filter to use new API
simcha90 Feb 17, 2021
c591fa8
Merge branch 'master' of github.com:apache/superset into filter_set
simcha90 Feb 17, 2021
dbafc6f
refactor: fix CR notes
simcha90 Feb 17, 2021
2369057
fix: fix update values in filter bar
simcha90 Feb 17, 2021
e3ac34c
refactor: save filter sets in meta
simcha90 Feb 17, 2021
bbe2402
Merge branch 'master' of github.com:apache/superset into filter_sets_…
simcha90 Feb 17, 2021
96fd817
feat(filter-sets): save filters sets in metadata
simcha90 Feb 18, 2021
29d0f24
Merge branch 'master' of github.com:apache/superset into filter_sets_…
simcha90 Feb 18, 2021
bfadb66
Merge branch 'master' of github.com:apache/superset into private-state
simcha90 Feb 18, 2021
9839c23
refactor: partially fix ts
simcha90 Feb 18, 2021
c7ff7ee
Merge branch 'filter_sets_meta' of github.com:simchaNielsen/incubator…
simcha90 Feb 18, 2021
c53d78a
refactor: merge conflicts
simcha90 Feb 18, 2021
58ab5e0
Merge branch 'master' of github.com:apache/superset into private-state
simcha90 Feb 18, 2021
f050ae4
refactor: add behaviors property
simcha90 Feb 21, 2021
896d09c
refactor: add behaviors property
simcha90 Feb 21, 2021
cb415a6
fix: undo py changes
simcha90 Feb 21, 2021
cf00f3e
fix: under some changes
simcha90 Feb 21, 2021
01ae685
Merge branch 'master' of github.com:apache/superset into private-state
simcha90 Mar 1, 2021
86a316b
refactor: synx with master
simcha90 Mar 1, 2021
328f34d
fix: undo FF
simcha90 Mar 1, 2021
89f262c
fix: undo FF
simcha90 Mar 1, 2021
9e9ee78
lint: ts-ignore
simcha90 Mar 1, 2021
4a87b62
chore: update lock file
simcha90 Mar 1, 2021
f91db58
refactor: update enum
simcha90 Mar 1, 2021
d784f35
refactor: naming of enum
simcha90 Mar 1, 2021
0baaa17
test: fix test
simcha90 Mar 1, 2021
c2fe5a0
test: update mocks
simcha90 Mar 1, 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
662 changes: 371 additions & 291 deletions superset-frontend/package-lock.json

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions superset-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,34 @@
"@babel/runtime-corejs3": "^7.12.5",
"@data-ui/sparkline": "^0.0.84",
"@emotion/core": "^10.0.35",
"@superset-ui/chart-controls": "^0.17.12",
"@superset-ui/core": "^0.17.11",
"@superset-ui/legacy-plugin-chart-calendar": "^0.17.12",
"@superset-ui/legacy-plugin-chart-chord": "^0.17.12",
"@superset-ui/legacy-plugin-chart-country-map": "^0.17.12",
"@superset-ui/legacy-plugin-chart-event-flow": "^0.17.12",
"@superset-ui/legacy-plugin-chart-force-directed": "^0.17.12",
"@superset-ui/legacy-plugin-chart-heatmap": "^0.17.12",
"@superset-ui/legacy-plugin-chart-histogram": "^0.17.12",
"@superset-ui/legacy-plugin-chart-horizon": "^0.17.12",
"@superset-ui/legacy-plugin-chart-map-box": "^0.17.12",
"@superset-ui/legacy-plugin-chart-paired-t-test": "^0.17.12",
"@superset-ui/legacy-plugin-chart-parallel-coordinates": "^0.17.12",
"@superset-ui/legacy-plugin-chart-partition": "^0.17.12",
"@superset-ui/legacy-plugin-chart-pivot-table": "^0.17.12",
"@superset-ui/legacy-plugin-chart-rose": "^0.17.12",
"@superset-ui/legacy-plugin-chart-sankey": "^0.17.12",
"@superset-ui/legacy-plugin-chart-sankey-loop": "^0.17.12",
"@superset-ui/legacy-plugin-chart-sunburst": "^0.17.12",
"@superset-ui/legacy-plugin-chart-treemap": "^0.17.12",
"@superset-ui/legacy-plugin-chart-world-map": "^0.17.12",
"@superset-ui/legacy-preset-chart-big-number": "^0.17.12",
"@superset-ui/chart-controls": "^0.17.13",
"@superset-ui/core": "^0.17.13",
"@superset-ui/legacy-plugin-chart-calendar": "^0.17.13",
"@superset-ui/legacy-plugin-chart-chord": "^0.17.13",
"@superset-ui/legacy-plugin-chart-country-map": "^0.17.13",
"@superset-ui/legacy-plugin-chart-event-flow": "^0.17.13",
"@superset-ui/legacy-plugin-chart-force-directed": "^0.17.13",
"@superset-ui/legacy-plugin-chart-heatmap": "^0.17.13",
"@superset-ui/legacy-plugin-chart-histogram": "^0.17.13",
"@superset-ui/legacy-plugin-chart-horizon": "^0.17.13",
"@superset-ui/legacy-plugin-chart-map-box": "^0.17.13",
"@superset-ui/legacy-plugin-chart-paired-t-test": "^0.17.13",
"@superset-ui/legacy-plugin-chart-parallel-coordinates": "^0.17.13",
"@superset-ui/legacy-plugin-chart-partition": "^0.17.13",
"@superset-ui/legacy-plugin-chart-pivot-table": "^0.17.13",
"@superset-ui/legacy-plugin-chart-rose": "^0.17.13",
"@superset-ui/legacy-plugin-chart-sankey": "^0.17.13",
"@superset-ui/legacy-plugin-chart-sankey-loop": "^0.17.13",
"@superset-ui/legacy-plugin-chart-sunburst": "^0.17.13",
"@superset-ui/legacy-plugin-chart-treemap": "^0.17.13",
"@superset-ui/legacy-plugin-chart-world-map": "^0.17.13",
"@superset-ui/legacy-preset-chart-big-number": "^0.17.13",
"@superset-ui/legacy-preset-chart-deckgl": "^0.4.6",
"@superset-ui/legacy-preset-chart-nvd3": "^0.17.12",
"@superset-ui/plugin-chart-echarts": "^0.17.12",
"@superset-ui/plugin-chart-table": "^0.17.12",
"@superset-ui/plugin-chart-word-cloud": "^0.17.12",
"@superset-ui/preset-chart-xy": "^0.17.12",
"@superset-ui/legacy-preset-chart-nvd3": "^0.17.13",
"@superset-ui/plugin-chart-echarts": "^0.17.13",
"@superset-ui/plugin-chart-table": "^0.17.13",
"@superset-ui/plugin-chart-word-cloud": "^0.17.13",
"@superset-ui/preset-chart-xy": "^0.17.13",
"@vx/responsive": "^0.0.195",
"abortcontroller-polyfill": "^1.1.9",
"antd": "^4.9.4",
Expand Down
42 changes: 23 additions & 19 deletions superset-frontend/spec/fixtures/mockNativeFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,31 @@ export const nativeFilters: NativeFiltersState = {
},
},
filtersState: {
'NATIVE_FILTER-e7Q8zKixx': {
id: 'NATIVE_FILTER-e7Q8zKixx',
currentState: {
value: ['East Asia & Pacific'],
},
extraFormData: {
append_form_data: {
filters: [
{
col: 'region',
op: 'IN',
val: ['East Asia & Pacific'],
},
],
crossFilters: {},
ownFilters: {},
nativeFilters: {
'NATIVE_FILTER-e7Q8zKixx': {
id: 'NATIVE_FILTER-e7Q8zKixx',
extraFormData: {
append_form_data: {
filters: [
{
col: 'region',
op: 'IN',
val: ['East Asia & Pacific'],
},
],
},
},
currentState: {
value: ['East Asia & Pacific'],
},
},
},
'NATIVE_FILTER-x9QPw0so1': {
id: 'NATIVE_FILTER-x9QPw0so1',
extraFormData: {},
currentState: {},
'NATIVE_FILTER-x9QPw0so1': {
id: 'NATIVE_FILTER-x9QPw0so1',
extraFormData: {},
currentState: {},
},
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ describe('getFormDataWithExtraFilters', () => {
} as unknown) as Filter,
},
filtersState: {
[filterId]: {
id: filterId,
extraFormData: {},
currentState: {},
crossFilters: {},
ownFilters: {},
nativeFilters: {
[filterId]: {
id: filterId,
extraFormData: {},
currentState: {},
},
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/chart/ChartContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import { bindActionCreators } from 'redux';
import * as actions from './chartAction';
import { logEvent } from '../logger/actions';
import Chart from './Chart';
import { setExtraFormData } from '../dashboard/actions/nativeFilters';
import { updateExtraFormData } from '../dashboard/actions/nativeFilters';

function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(
{
...actions,
setExtraFormData,
updateExtraFormData,
logEvent,
},
dispatch,
Expand Down
18 changes: 11 additions & 7 deletions superset-frontend/src/chart/ChartRenderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { snakeCase } from 'lodash';
import PropTypes from 'prop-types';
import React from 'react';
import { SuperChart, logging } from '@superset-ui/core';
import { SuperChart, logging, Behavior } from '@superset-ui/core';
import { Logger, LOG_ACTIONS_RENDER_CHART } from '../logger/LogUtils';

const propTypes = {
Expand All @@ -42,9 +42,10 @@ const propTypes = {
refreshOverlayVisible: PropTypes.bool,
// dashboard callbacks
addFilter: PropTypes.func,
setExtraFormData: PropTypes.func,
setDataMask: PropTypes.func,
onFilterMenuOpen: PropTypes.func,
onFilterMenuClose: PropTypes.func,
ownCurrentState: PropTypes.object,
};

const BLANK = {};
Expand Down Expand Up @@ -74,12 +75,12 @@ class ChartRenderer extends React.Component {
setControlValue: this.handleSetControlValue,
onFilterMenuOpen: this.props.onFilterMenuOpen,
onFilterMenuClose: this.props.onFilterMenuClose,
setExtraFormData: ({ extraFormData, currentState }) =>
this.props.actions?.setExtraFormData(
setDataMask: filtersState => {
this.props.actions?.updateExtraFormData(
this.props.chartId,
extraFormData,
currentState,
),
filtersState,
);
},
};
}

Expand Down Expand Up @@ -185,6 +186,7 @@ class ChartRenderer extends React.Component {
annotationData,
datasource,
initialValues,
ownCurrentState,
formData,
queriesResponse,
} = this.props;
Expand Down Expand Up @@ -224,7 +226,9 @@ class ChartRenderer extends React.Component {
datasource={datasource}
initialValues={initialValues}
formData={formData}
ownCurrentState={ownCurrentState}
hooks={this.hooks}
behaviors={[Behavior.CROSS_FILTER]}
queriesData={queriesResponse}
onRenderSuccess={this.handleRenderSuccess}
onRenderFailure={this.handleRenderFailure}
Expand Down
49 changes: 23 additions & 26 deletions superset-frontend/src/dashboard/actions/nativeFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
* under the License.
*/

import { ExtraFormData, makeApi } from '@superset-ui/core';
import { makeApi, DataMask } from '@superset-ui/core';
import { Dispatch } from 'redux';
import { FilterConfiguration } from 'src/dashboard/components/nativeFilters/types';
import { dashboardInfoChanged } from './dashboardInfo';
import {
CurrentFilterState,
FiltersState,
FilterState,
FiltersSet,
NativeFilterState,
FilterStateType,
} from '../reducers/types';

export const SET_FILTER_CONFIG_BEGIN = 'SET_FILTER_CONFIG_BEGIN';
Expand Down Expand Up @@ -142,51 +143,49 @@ export const setFilterSetsConfiguration = (
}
};

export const SET_EXTRA_FORM_DATA = 'SET_EXTRA_FORM_DATA';
export interface SetExtraFormData {
type: typeof SET_EXTRA_FORM_DATA;
export const UPDATE_EXTRA_FORM_DATA = 'UPDATE_EXTRA_FORM_DATA';
export interface UpdateExtraFormData {
type: typeof UPDATE_EXTRA_FORM_DATA;
filterId: string;
extraFormData: ExtraFormData;
currentState: CurrentFilterState;
nativeFilters?: Omit<FilterState, 'id'>;
crossFilters?: Omit<FilterState, 'id'>;
ownFilters?: Omit<FilterState, 'id'>;
}

export const SAVE_FILTER_SETS = 'SAVE_FILTER_SETS';
export interface SaveFilterSets {
type: typeof SAVE_FILTER_SETS;
name: string;
filtersState: NativeFilterState;
filtersState: Pick<FiltersState, FilterStateType.NativeFilters>;
filtersSetId: string;
}

export const SET_FILTERS_STATE = 'SET_FILTERS_STATE';
export interface SetFiltersState {
type: typeof SET_FILTERS_STATE;
filtersState: NativeFilterState;
filtersState: FiltersState;
}

/**
* Sets the selected option(s) for a given filter
* @param filterId the id of the native filter
* @param extraFormData the selection translated into extra form data
* @param currentState
* @param filterId the id of the nativeFilters filter
* @param filterState
*/
export function setExtraFormData(
export function updateExtraFormData(
filterId: string,
extraFormData: ExtraFormData,
currentState: CurrentFilterState,
): SetExtraFormData {
filterState: DataMask,
): UpdateExtraFormData {
return {
type: SET_EXTRA_FORM_DATA,
type: UPDATE_EXTRA_FORM_DATA,
filterId,
extraFormData,
currentState,
...filterState,
};
}

export function saveFilterSets(
name: string,
filtersSetId: string,
filtersState: NativeFilterState,
filtersState: Pick<FiltersState, FilterStateType.NativeFilters>,
): SaveFilterSets {
return {
type: SAVE_FILTER_SETS,
Expand All @@ -196,9 +195,7 @@ export function saveFilterSets(
};
}

export function setFiltersState(
filtersState: NativeFilterState,
): SetFiltersState {
export function setFiltersState(filtersState: FiltersState): SetFiltersState {
return {
type: SET_FILTERS_STATE,
filtersState,
Expand All @@ -213,5 +210,5 @@ export type AnyFilterAction =
| SetFilterSetsConfigComplete
| SetFilterSetsConfigFail
| SetFiltersState
| SetExtraFormData
| SaveFilterSets;
| SaveFilterSets
| UpdateExtraFormData;
23 changes: 17 additions & 6 deletions superset-frontend/src/dashboard/components/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { areObjectsEqual } from '../../reduxUtils';
import '../stylesheets/index.less';
import getLocationHash from '../util/getLocationHash';
import isDashboardEmpty from '../util/isDashboardEmpty';
import { getAffectedOwnDataCharts } from '../util/charts/getOwnDataCharts';

const propTypes = {
actions: PropTypes.shape({
Expand All @@ -56,6 +57,7 @@ const propTypes = {
slices: PropTypes.objectOf(slicePropShape).isRequired,
activeFilters: PropTypes.object.isRequired,
datasources: PropTypes.object.isRequired,
ownDataCharts: PropTypes.object.isRequired,
layout: PropTypes.object.isRequired,
impressionId: PropTypes.string.isRequired,
initMessages: PropTypes.array,
Expand Down Expand Up @@ -88,7 +90,8 @@ class Dashboard extends React.PureComponent {

constructor(props) {
super(props);
this.appliedFilters = props.activeFilters || {};
this.appliedFilters = props.activeFilters ?? {};
this.appliedOwnDataCharts = props.ownDataCharts ?? {};
this.onVisibilityChange = this.onVisibilityChange.bind(this);
}

Expand Down Expand Up @@ -147,9 +150,13 @@ class Dashboard extends React.PureComponent {
componentDidUpdate() {
const { hasUnsavedChanges, editMode } = this.props.dashboardState;

const { appliedFilters } = this;
const { activeFilters } = this.props;
if (!editMode && !areObjectsEqual(appliedFilters, activeFilters)) {
const { appliedFilters, appliedOwnDataCharts } = this;
const { activeFilters, ownDataCharts } = this.props;
if (
!editMode &&
(!areObjectsEqual(appliedOwnDataCharts, ownDataCharts) ||
!areObjectsEqual(appliedFilters, activeFilters))
) {
this.applyFilters();
}

Expand Down Expand Up @@ -188,14 +195,17 @@ class Dashboard extends React.PureComponent {

applyFilters() {
const { appliedFilters } = this;
const { activeFilters } = this.props;
const { activeFilters, ownDataCharts } = this.props;

// refresh charts if a filter was removed, added, or changed
const currFilterKeys = Object.keys(activeFilters);
const appliedFilterKeys = Object.keys(appliedFilters);

const allKeys = new Set(currFilterKeys.concat(appliedFilterKeys));
const affectedChartIds = [];
const affectedChartIds = getAffectedOwnDataCharts(
ownDataCharts,
this.appliedOwnDataCharts,
);
[...allKeys].forEach(filterKey => {
if (!currFilterKeys.includes(filterKey)) {
// filterKey is removed?
Expand Down Expand Up @@ -234,6 +244,7 @@ class Dashboard extends React.PureComponent {
// remove dup in affectedChartIds
this.refreshCharts([...new Set(affectedChartIds)]);
this.appliedFilters = activeFilters;
this.appliedOwnDataCharts = ownDataCharts;
}

refreshCharts(ids) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ export const selectNativeIndicatorsForChart = (
layoutItem => dashboardLayout[layoutItem]?.meta?.chartId === chartId,
);
const column = nativeFilter.targets[0]?.column?.name;
const filterState = nativeFilters.filtersState[nativeFilter.id];
const filterState =
nativeFilters.filtersState.nativeFilters?.[nativeFilter.id];
let value = filterState?.currentState?.value ?? [];
if (!Array.isArray(value)) {
value = [value];
Expand Down
Loading