Skip to content

Commit 4223034

Browse files
authored
Merge pull request #132 from devgateway/task/TCDICORE-544/clear-old-filters-selection
chore (TCDICORE-544): clear old filters when source changes
2 parents 8b457b1 + a045251 commit 4223034

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

.changeset/real-moles-judge.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devgateway/dvz-wp-commons": patch
3+
---
4+
5+
Clear old filters on wordpress source change

packages/commons/src/Blocks.jsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ export class BlockEditWithFilters extends ComponentWithSettings {
179179
wordpressSourceType !== prevProps.attributes.wordpressSourceType ||
180180
wordpressSource !== prevProps.attributes.wordpressSource;
181181
if (sourceChanged) {
182+
setAttributes({
183+
type: undefined,
184+
taxonomy: 'none',
185+
categories: [],
186+
sortingTaxonomy: 'none',
187+
sortFirstBy: 'none',
188+
defaultValues: [],
189+
});
182190
this.getTypes();
183191
this.getTaxonomies();
184192
this.getTaxonomyValues();
@@ -538,7 +546,10 @@ export class BlockEditWithAPIMetadata extends ComponentWithSettings {
538546
'Accept': 'application/json',
539547
},
540548
})
541-
.then(response => response.json())
549+
.then(response => {
550+
if (!response.ok) throw new Error(`Eureka apps returned ${response.status}`);
551+
return response.json();
552+
})
542553
.then(data => {
543554
const apps = data.applications ? [...data.applications.application
544555
.filter(a => a.instance[0].metadata.type === 'data')
@@ -570,8 +581,21 @@ export class BlockEditWithAPIMetadata extends ComponentWithSettings {
570581
}
571582
});
572583
})
573-
.catch(() => {
574-
console.log("Error when loading apps");
584+
.catch((error) => {
585+
console.error("Error when loading apps, falling back to CSV", error);
586+
this.setState({
587+
react_ui_url: settingsData["react_ui_url"] + '/' + window._page_locale,
588+
react_api_url: settingsData["react_api_url"],
589+
apache_superset_url: settingsData["apache_superset_url"],
590+
site_language: settingsData["site_language"],
591+
current_language: new URLSearchParams(document.location.search).get("edit_lang"),
592+
apps: [{ label: 'CSV', value: 'csv' }]
593+
}, () => {
594+
const { app, dvzProxyDatasetId } = this.props.attributes;
595+
if (app && app != 'none') {
596+
this.loadMetadata(app, dvzProxyDatasetId);
597+
}
598+
});
575599
});
576600
});
577601
}

0 commit comments

Comments
 (0)