Skip to content

Commit

Permalink
refactor(native-filters): Move filtersState to dataMask redux root (
Browse files Browse the repository at this point in the history
  • Loading branch information
simcha90 authored Mar 7, 2021
1 parent d0714a0 commit 45972e9
Show file tree
Hide file tree
Showing 33 changed files with 428 additions and 323 deletions.
11 changes: 7 additions & 4 deletions superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions superset-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"geolib": "^2.0.24",
"global-box": "^1.2.0",
"html-webpack-plugin": "^4.5.1",
"immer": "^8.0.1",
"immutable": "^4.0.0-rc.12",
"interweave": "^11.2.0",
"jquery": "^3.5.1",
Expand Down
65 changes: 34 additions & 31 deletions superset-frontend/spec/fixtures/mockNativeFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
import { NativeFiltersState } from 'src/dashboard/reducers/types';
import { DataMaskStateWithId } from '../../src/dataMask/types';

export const nativeFilters: NativeFiltersState = {
filterSets: {},
Expand Down Expand Up @@ -72,33 +73,34 @@ export const nativeFilters: NativeFiltersState = {
isInstant: true,
},
},
filtersState: {
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'],
};

export const dataMaskWith2Filters: DataMaskStateWithId = {
crossFilters: {},
ownFilters: {},
nativeFilters: {
'NATIVE_FILTER-e7Q8zKixx': {
id: 'NATIVE_FILTER-e7Q8zKixx',
extraFormData: {
append_form_data: {
filters: [
{
col: 'region',
op: 'IN',
val: ['East Asia & Pacific'],
},
],
},
},
'NATIVE_FILTER-x9QPw0so1': {
id: 'NATIVE_FILTER-x9QPw0so1',
extraFormData: {},
currentState: {},
currentState: {
value: ['East Asia & Pacific'],
},
},
'NATIVE_FILTER-x9QPw0so1': {
id: 'NATIVE_FILTER-x9QPw0so1',
extraFormData: {},
currentState: {},
},
},
};

Expand Down Expand Up @@ -132,14 +134,15 @@ export const singleNativeFiltersState = {
isRequired: false,
},
},
filtersState: {
nativeFilters: {
[NATIVE_FILTER_ID]: {
id: NATIVE_FILTER_ID,
extraFormData,
currentState: {
value: ['No, not an ethnic minority'],
},
};

export const dataMaskWith1Filter = {
nativeFilters: {
[NATIVE_FILTER_ID]: {
id: NATIVE_FILTER_ID,
extraFormData,
currentState: {
value: ['No, not an ethnic minority'],
},
},
},
Expand Down
6 changes: 5 additions & 1 deletion superset-frontend/spec/fixtures/mockState.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
*/
import datasources from 'spec/fixtures/mockDatasource';
import messageToasts from 'spec/javascripts/messageToasts/mockMessageToasts';
import { nativeFiltersInfo } from 'spec/javascripts/dashboard/fixtures/mockNativeFilters';
import {
nativeFiltersInfo,
mockDataMaskInfo,
} from 'spec/javascripts/dashboard/fixtures/mockNativeFilters';
import chartQueries from './mockChartQueries';
import { dashboardLayout } from './mockDashboardLayout';
import dashboardInfo from './mockDashboardInfo';
Expand All @@ -31,6 +34,7 @@ export default {
sliceEntities: sliceEntitiesForChart,
charts: chartQueries,
nativeFilters: nativeFiltersInfo,
dataMask: mockDataMaskInfo,
dashboardInfo,
dashboardFilters: emptyFilters,
dashboardState,
Expand Down
4 changes: 3 additions & 1 deletion superset-frontend/spec/fixtures/mockStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
} from './mockDashboardLayout';
import { sliceId } from './mockChartQueries';
import { dashboardFilters } from './mockDashboardFilters';
import { nativeFilters } from './mockNativeFilters';
import { nativeFilters, dataMaskWith2Filters } from './mockNativeFilters';

export const storeWithState = state =>
createStore(rootReducer, state, compose(applyMiddleware(thunk)));
Expand Down Expand Up @@ -77,6 +77,7 @@ export const getMockStoreWithFilters = () =>
createStore(rootReducer, {
...mockState,
dashboardFilters,
dataMask: dataMaskWith2Filters,
charts: {
...mockState.charts,
[sliceIdWithAppliedFilter]: {
Expand All @@ -102,6 +103,7 @@ export const getMockStoreWithNativeFilters = () =>
createStore(rootReducer, {
...mockState,
nativeFilters,
dataMask: dataMaskWith2Filters,
charts: {
...mockState.charts,
[sliceIdWithAppliedFilter]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
NATIVE_FILTER_ID,
layoutForSingleNativeFilter,
singleNativeFiltersState,
dataMaskWith1Filter,
} from 'spec/fixtures/mockNativeFilters';
import dashboardInfo from 'spec/fixtures/mockDashboardInfo';
import { dashboardLayout } from 'spec/fixtures/mockDashboardLayout';
Expand Down Expand Up @@ -154,7 +155,8 @@ describe('Dashboard', () => {
activeFilters: {
...OVERRIDE_FILTERS,
...getActiveNativeFilters({
nativeFilters: singleNativeFiltersState,
dataMask: dataMaskWith1Filter,
filters: singleNativeFiltersState.filters,
layout: layoutForSingleNativeFilter,
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
export const nativeFiltersInfo = {
import { DataMaskStateWithId, DataMaskType } from 'src/dataMask/types';
import { NativeFiltersState } from 'src/dashboard/reducers/types';

export const nativeFiltersInfo: NativeFiltersState = {
filterSets: {},
filters: {
DefaultsID: {
cascadeParentIds: [],
id: 'DefaultsID',
name: 'test',
type: 'filter_select',
filterType: 'filter_select',
targets: [
{
datasetId: 0,
Expand All @@ -37,17 +42,22 @@ export const nativeFiltersInfo = {
excluded: [],
},
isInstant: true,
allowsMultipleValues: true,
isRequired: false,
controlValues: {
allowsMultipleValues: true,
isRequired: false,
},
},
},
filtersState: {
nativeFilters: {
DefaultsID: {
id: 'DefaultId',
currentState: {
value: [],
},
};

export const mockDataMaskInfo: DataMaskStateWithId = {
[DataMaskType.CrossFilters]: {},
[DataMaskType.OwnFilters]: {},
[DataMaskType.NativeFilters]: {
DefaultsID: {
id: 'DefaultId',
currentState: {
value: [],
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ describe('getFormDataWithExtraFilters', () => {
},
} as unknown) as Filter,
},
filtersState: {
crossFilters: {},
ownFilters: {},
nativeFilters: {
[filterId]: {
id: filterId,
extraFormData: {},
currentState: {},
},
},
dataMask: {
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 { updateExtraFormData } from '../dashboard/actions/nativeFilters';
import { updateDataMask } from '../dataMask/actions';

function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(
{
...actions,
updateExtraFormData,
updateDataMask,
logEvent,
},
dispatch,
Expand Down
8 changes: 3 additions & 5 deletions superset-frontend/src/chart/ChartRenderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,8 @@ class ChartRenderer extends React.Component {
setControlValue: this.handleSetControlValue,
onFilterMenuOpen: this.props.onFilterMenuOpen,
onFilterMenuClose: this.props.onFilterMenuClose,
setDataMask: filtersState => {
this.props.actions?.updateExtraFormData(
this.props.chartId,
filtersState,
);
setDataMask: dataMask => {
this.props.actions?.updateDataMask(this.props.chartId, dataMask);
},
};
}
Expand All @@ -97,6 +94,7 @@ class ChartRenderer extends React.Component {
return (
this.hasQueryResponseChange ||
nextProps.annotationData !== this.props.annotationData ||
nextProps.ownCurrentState !== this.props.ownCurrentState ||
nextProps.height !== this.props.height ||
nextProps.width !== this.props.width ||
nextProps.triggerRender ||
Expand Down
6 changes: 3 additions & 3 deletions superset-frontend/src/chart/chartAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { logEvent } from '../logger/actions';
import { Logger, LOG_ACTIONS_LOAD_CHART } from '../logger/LogUtils';
import { getClientErrorObject } from '../utils/getClientErrorObject';
import { allowCrossDomain as domainShardingEnabled } from '../utils/hostNamesConfig';
import { updateExtraFormData } from '../dashboard/actions/nativeFilters';
import { updateDataMask } from '../dataMask/actions';

export const CHART_UPDATE_STARTED = 'CHART_UPDATE_STARTED';
export function chartUpdateStarted(queryController, latestQueryFormData, key) {
Expand Down Expand Up @@ -366,8 +366,8 @@ export function exploreJSON(
};
if (dashboardId) requestParams.dashboard_id = dashboardId;

const setDataMask = filtersState => {
dispatch(updateExtraFormData(formData.slice_id, filtersState));
const setDataMask = dataMask => {
dispatch(updateDataMask(formData.slice_id, dataMask));
};
const chartDataRequest = getChartDataRequest({
setDataMask,
Expand Down
Loading

0 comments on commit 45972e9

Please sign in to comment.