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

fix: Revert "fix(native-filters): Fix update ownState" #17311

Merged
merged 1 commit into from
Nov 2, 2021
Merged
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
81 changes: 24 additions & 57 deletions superset-frontend/src/dashboard/components/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,55 +220,6 @@ class Dashboard extends React.PureComponent {
return Object.values(this.props.charts);
}

isFilterKeyRemoved(filterKey) {
const { appliedFilters } = this;
const { activeFilters } = this.props;

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

return (
!currFilterKeys.includes(filterKey) &&
appliedFilterKeys.includes(filterKey)
);
}

isFilterKeyNewlyAdded(filterKey) {
const { appliedFilters } = this;
const appliedFilterKeys = Object.keys(appliedFilters);

return !appliedFilterKeys.includes(filterKey);
}

isFilterKeyChangedValue(filterKey) {
const { appliedFilters } = this;
const { activeFilters } = this.props;

return !areObjectsEqual(
appliedFilters[filterKey].values,
activeFilters[filterKey].values,
{
ignoreUndefined: true,
},
);
}

isFilterKeyChangedScope(filterKey) {
const { appliedFilters } = this;
const { activeFilters } = this.props;

return !areObjectsEqual(
appliedFilters[filterKey].scope,
activeFilters[filterKey].scope,
);
}

hasFilterKeyValues(filterKey) {
const { appliedFilters } = this;
return Object.keys(appliedFilters[filterKey]?.values ?? []).length;
}

applyFilters() {
const { appliedFilters } = this;
const { activeFilters, ownDataCharts } = this.props;
Expand All @@ -284,21 +235,37 @@ class Dashboard extends React.PureComponent {
);
[...allKeys].forEach(filterKey => {
if (
this.isFilterKeyRemoved(filterKey) ||
this.isFilterKeyNewlyAdded(filterKey)
!currFilterKeys.includes(filterKey) &&
appliedFilterKeys.includes(filterKey)
) {
// check if there are values in filter, if no, there is was added only ownState, so no need reload other charts
if (this.hasFilterKeyValues(filterKey)) {
affectedChartIds.push(...appliedFilters[filterKey].scope);
}
// filterKey is removed?
affectedChartIds.push(...appliedFilters[filterKey].scope);
} else if (!appliedFilterKeys.includes(filterKey)) {
// filterKey is newly added?
affectedChartIds.push(...activeFilters[filterKey].scope);
} else {
// if filterKey changes value,
// update charts in its scope
if (this.isFilterKeyChangedValue(filterKey)) {
if (
!areObjectsEqual(
appliedFilters[filterKey].values,
activeFilters[filterKey].values,
{
ignoreUndefined: true,
},
)
) {
affectedChartIds.push(...activeFilters[filterKey].scope);
}

// if filterKey changes scope,
// update all charts in its scope
if (this.isFilterKeyChangedScope(filterKey)) {
if (
!areObjectsEqual(
appliedFilters[filterKey].scope,
activeFilters[filterKey].scope,
)
) {
const chartsInScope = (activeFilters[filterKey].scope || []).concat(
appliedFilters[filterKey].scope || [],
);
Expand Down