You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by si...@apache.org on 2021/10/26 08:41:04 UTC
[superset] branch master updated: fix(native-filters): Fix update
ownState (#17181)
This is an automated email from the ASF dual-hosted git repository.
simchashats pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new cf284ba fix(native-filters): Fix update ownState (#17181)
cf284ba is described below
commit cf284ba3c72550f64ddb19aeed44de2c5cf0b677
Author: simcha90 <56...@users.noreply.github.com>
AuthorDate: Tue Oct 26 11:39:16 2021 +0300
fix(native-filters): Fix update ownState (#17181)
* fix:fix get permission function
* fix: fix own state update
* refactor: fix CR notes
---
.../src/dashboard/components/Dashboard.jsx | 81 +++++++++++++++-------
1 file changed, 57 insertions(+), 24 deletions(-)
diff --git a/superset-frontend/src/dashboard/components/Dashboard.jsx b/superset-frontend/src/dashboard/components/Dashboard.jsx
index 7e67288..1377789 100644
--- a/superset-frontend/src/dashboard/components/Dashboard.jsx
+++ b/superset-frontend/src/dashboard/components/Dashboard.jsx
@@ -220,6 +220,55 @@ 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;
@@ -235,37 +284,21 @@ class Dashboard extends React.PureComponent {
);
[...allKeys].forEach(filterKey => {
if (
- !currFilterKeys.includes(filterKey) &&
- appliedFilterKeys.includes(filterKey)
+ this.isFilterKeyRemoved(filterKey) ||
+ this.isFilterKeyNewlyAdded(filterKey)
) {
- // filterKey is removed?
- affectedChartIds.push(...appliedFilters[filterKey].scope);
- } else if (!appliedFilterKeys.includes(filterKey)) {
- // filterKey is newly added?
- affectedChartIds.push(...activeFilters[filterKey].scope);
+ // 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);
+ }
} else {
- // if filterKey changes value,
// update charts in its scope
- if (
- !areObjectsEqual(
- appliedFilters[filterKey].values,
- activeFilters[filterKey].values,
- {
- ignoreUndefined: true,
- },
- )
- ) {
+ if (this.isFilterKeyChangedValue(filterKey)) {
affectedChartIds.push(...activeFilters[filterKey].scope);
}
- // if filterKey changes scope,
// update all charts in its scope
- if (
- !areObjectsEqual(
- appliedFilters[filterKey].scope,
- activeFilters[filterKey].scope,
- )
- ) {
+ if (this.isFilterKeyChangedScope(filterKey)) {
const chartsInScope = (activeFilters[filterKey].scope || []).concat(
appliedFilters[filterKey].scope || [],
);