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..caca8151ec884a67d73872722ce6da1fb457d491 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="dataNamespace" 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..3d0828b3b1c26058277210803296dcbc708fb6b2 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' }, + dataNamespace: '', data: {} }, @@ -29,8 +30,16 @@ define([ * @returns {DataStorage} Chainable. */ initConfig: function () { + var namespace; + this._super(); + namespace = this.dataNamespace; + + if (typeof namespace === 'string') { + this.dataNamespace = namespace ? [namespace] : []; + } + 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.hasNamespaceChanged(params)) { + this.clearRequests(); + } else { + cachedRequest = this.getRequest(params); } options = options || {}; @@ -90,6 +101,28 @@ define([ this.requestData(params); }, + /** + * Tells whether one of the parameters defined in the "dataNamespace" has + * changed since the last request. + * + * @param {Object} params - Request parameters. + * @returns {Boolean} + */ + hasNamespaceChanged: function (params) { + var lastRequest = _.last(this._requests), + paths, + diff; + + if (!lastRequest) { + return false; + } + + diff = utils.compare(lastRequest.params, params); + paths = _.pluck(diff.changes, 'path').concat(_.keys(diff.containers)); + + return _.intersection(this.dataNamespace, paths).length > 0; + }, + /** * Extends records of current data object * with the provided records collection.