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

[dashboard] fix chart showing loading icon when slice's immune fields is changed #7895

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -66,6 +66,24 @@ describe('Dashboard', () => {
});

describe('refreshExcept', () => {
const overrideDashboardState = {
...dashboardState,
filters: {
1: { region: [] },
2: { country_name: ['USA'] },
3: { region: [], country_name: ['USA'] },
},
refresh: true,
};

const overrideDashboardInfo = {
...dashboardInfo,
metadata: {
...dashboardInfo.metadata,
filter_immune_slice_fields: { [chartQueries[chartId].id]: ['region'] },
},
};

const overrideCharts = {
...chartQueries,
1001: {
Expand Down Expand Up @@ -108,6 +126,32 @@ describe('Dashboard', () => {
spy.restore();
expect(spy.callCount).toBe(0);
});

it('should not call triggerQuery for filter_immune_slice_fields', () => {
const wrapper = setup({
dashboardState: overrideDashboardState,
dashboardInfo: overrideDashboardInfo,
});
const spy = sinon.spy(props.actions, 'triggerQuery');
wrapper.instance().refreshExcept('1');
expect(spy.callCount).toBe(0);
spy.restore();
});

it('should call triggerQuery if filter has more filter-able fields', () => {
const wrapper = setup({
dashboardState: overrideDashboardState,
dashboardInfo: overrideDashboardInfo,
});
const spy = sinon.spy(props.actions, 'triggerQuery');

// if filter have additional fields besides immune ones,
// should apply filter.
wrapper.instance().refreshExcept('3');
expect(spy.callCount).toBe(1);

spy.restore();
});
});

describe('componentWillReceiveProps', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
export default {
id: 1234,
slug: 'dashboardSlug',
metadata: {},
metadata: {
filter_immune_slices: [],
filter_immune_slice_fields: {},
},
userId: 'mock_user_id',
dash_edit_perm: true,
dash_save_perm: true,
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 { id as sliceId } from './mockChartQueries';
import { sliceId } from './mockChartQueries';
import { BUILDER_PANE_TYPE } from '../../../../src/dashboard/util/constants';

export default {
Expand Down
7 changes: 2 additions & 5 deletions superset/assets/src/chart/Chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { Alert } from 'react-bootstrap';

import { isFeatureEnabled, FeatureFlag } from 'src/featureFlags';
import { Logger, LOG_ACTIONS_RENDER_CHART_CONTAINER } from '../logger/LogUtils';
import { safeStringify } from '../utils/safeStringify';
import Loading from '../components/Loading';
import RefreshChartOverlay from '../components/RefreshChartOverlay';
import StackTraceMessage from '../components/StackTraceMessage';
Expand Down Expand Up @@ -82,10 +81,8 @@ class Chart extends React.PureComponent {
}
}

componentDidUpdate(prevProps) {
if (this.props.triggerQuery &&
safeStringify(prevProps.formData) !== safeStringify(this.props.formData)
) {
componentDidUpdate() {
if (this.props.triggerQuery) {
this.runQuery();
}
}
Expand Down
28 changes: 25 additions & 3 deletions superset/assets/src/dashboard/components/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
/* eslint-disable camelcase */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then we can probably get rid of this comment

import React from 'react';
import PropTypes from 'prop-types';
import { t } from '@superset-ui/translation';
Expand Down Expand Up @@ -143,11 +144,32 @@ class Dashboard extends React.PureComponent {
}

refreshExcept(filterKey) {
const immune = this.props.dashboardInfo.metadata.filter_immune_slices || [];
const { filters } = this.props.dashboardState || {};
const currentFilteredNames =
filterKey && filters[filterKey] ? Object.keys(filters[filterKey]) : [];
const filter_immune_slices = this.props.dashboardInfo.metadata
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase for the const

.filter_immune_slices;
const filter_immune_slice_fields = this.props.dashboardInfo.metadata
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase for the const

.filter_immune_slice_fields;

this.getAllCharts().forEach(chart => {
// filterKey is a string, immune array contains numbers
if (String(chart.id) !== filterKey && immune.indexOf(chart.id) === -1) {
// filterKey is a string, filter_immune_slices array contains numbers
if (
String(chart.id) === filterKey ||
filter_immune_slices.includes(chart.id)
) {
return;
}

const filter_immune_slice_fields_names =
filter_immune_slice_fields[chart.id] || [];
// has filter-able field names
if (
currentFilteredNames.length === 0 ||
currentFilteredNames.some(
name => !filter_immune_slice_fields_names.includes(name),
)
) {
this.props.actions.triggerQuery(true, chart.id);
}
});
Expand Down
4 changes: 2 additions & 2 deletions superset/assets/src/dashboard/reducers/getInitialState.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ export default function(bootstrapData) {
slug: dashboard.slug,
metadata: {
filter_immune_slice_fields:
dashboard.metadata.filter_immune_slice_fields,
filter_immune_slices: dashboard.metadata.filter_immune_slices,
dashboard.metadata.filter_immune_slice_fields || {},
filter_immune_slices: dashboard.metadata.filter_immune_slices || [],
timed_refresh_immune_slices:
dashboard.metadata.timed_refresh_immune_slices,
},
Expand Down