Skip to content

Commit d7c55ad

Browse files
committed
Apply filters after fetching collection
1 parent ba275eb commit d7c55ad

File tree

1 file changed

+15
-0
lines changed
  • contentcuration/contentcuration/frontend/shared/data

1 file changed

+15
-0
lines changed

contentcuration/contentcuration/frontend/shared/data/resources.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,20 @@ class Resource extends mix(APIResource, IndexedDBResource) {
700700
this._requests = {};
701701
}
702702

703+
/**
704+
* Apply filters after fetching data from the server
705+
* and update it with the local changes
706+
* @param {Object[]} collection
707+
* @param {Object} params
708+
* @return {Object[]}
709+
*/
710+
_applyFilters(data, params) {
711+
if (params.parent) {
712+
return data.filter(obj => obj.parent === params.parent);
713+
}
714+
return data;
715+
}
716+
703717
fetchCollection(params) {
704718
const now = Date.now();
705719
const queryString = paramsSerializer(params);
@@ -725,6 +739,7 @@ class Resource extends mix(APIResource, IndexedDBResource) {
725739
itemData = [];
726740
}
727741
return this.setData(itemData).then(data => {
742+
data = this._applyFilters(data, params);
728743
// setData also applies any outstanding local change events to the data
729744
// so we return the data returned from setData to make sure the most up to date
730745
// representation is returned from the fetch.

0 commit comments

Comments
 (0)