diff --git a/app/code/Magento/Catalog/view/adminhtml/ui_component/product_listing.xml b/app/code/Magento/Catalog/view/adminhtml/ui_component/product_listing.xml index ec88952af503359cddd6159fdc84c2826f51235f..5fab2d04f220978048d990a527cef34e647196e6 100644 --- a/app/code/Magento/Catalog/view/adminhtml/ui_component/product_listing.xml +++ b/app/code/Magento/Catalog/view/adminhtml/ui_component/product_listing.xml @@ -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> diff --git a/app/code/Magento/Ui/view/base/web/js/grid/data-storage.js b/app/code/Magento/Ui/view/base/web/js/grid/data-storage.js index dca12f832cd15e1cdc197ec909df92557c45da60..b90138a47b842f4d7428bc5bc12a98e0ee130ca5 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/data-storage.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/data-storage.js @@ -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.