Skip to content
Snippets Groups Projects
Commit 6e22488b authored by Karpenko, Oleksandr's avatar Karpenko, Oleksandr
Browse files

Merge remote-tracking branch 'origin/MAGETWO-59322' into pr-develop

parents 1af98b50 8b47980a
Branches
No related merge requests found
......@@ -23,6 +23,9 @@
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
<item name="update_url" xsi:type="url" path="mui/index/render"/>
<item name="storageConfig" xsi:type="array">
<item name="dataScope" xsi:type="string">filters.store_id</item>
</item>
</item>
</argument>
</argument>
......
......@@ -20,6 +20,7 @@ define([
method: 'GET',
dataType: 'json'
},
dataScope: '',
data: {}
},
......@@ -29,8 +30,16 @@ define([
* @returns {DataStorage} Chainable.
*/
initConfig: function () {
var scope;
this._super();
scope = this.dataScope;
if (typeof scope === 'string') {
this.dataScope = scope ? [scope] : [];
}
this._requests = [];
return this;
......@@ -77,10 +86,12 @@ define([
* @returns {jQueryPromise}
*/
getData: function (params, options) {
var cachedRequest = this.getRequest(params);
var cachedRequest;
if (params && params.filters && params.filters['store_id']) {
cachedRequest = false;
if (this.hasScopeChanged(params)) {
this.clearRequests();
} else {
cachedRequest = this.getRequest(params);
}
options = options || {};
......@@ -90,6 +101,30 @@ define([
this.requestData(params);
},
/**
* Tells whether one of the parameters defined in the "dataScope" has
* changed since the last request.
*
* @param {Object} params - Request parameters.
* @returns {Boolean}
*/
hasScopeChanged: function (params) {
var lastRequest = _.last(this._requests),
keys,
diff;
if (!lastRequest) {
return false;
}
diff = utils.compare(lastRequest.params, params);
keys = _.pluck(diff.changes, 'path');
keys = keys.concat(Object.keys(diff.containers));
return _.intersection(this.dataScope, keys).length > 0;
},
/**
* Extends records of current data object
* with the provided records collection.
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment