From ed833c492e51f78ee2523c0b2eb5fee37c91166d Mon Sep 17 00:00:00 2001 From: Magento EngCom Team Date: Wed, 24 Jan 2018 12:09:47 -0600 Subject: [PATCH] :arrow_double_up: Forwardport of magento/magento2#11846 to 2.3-develop branch Applied pull request patch https://github.com/magento/magento2/pull/11846.patch (created by @deiserh) based on commit(s): 1. 0f948ac1403ecbdacae6c58cfdd5b045698c1ea8 2. 6f70d065a415157a57716e8629b523de0ec6f291 3. 8f52242e060aefedc0bf35264d4da437870168db 4. c464951669e729d163c05a0955869cf4278a8106 --- .../js/components/dynamic-rows-tier-price.js | 4 ++ .../base/web/js/dynamic-rows/dynamic-rows.js | 6 ++- .../base/js/dynamic-rows/dynamic-rows.test.js | 38 +++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/view/adminhtml/web/js/components/dynamic-rows-tier-price.js b/app/code/Magento/Catalog/view/adminhtml/web/js/components/dynamic-rows-tier-price.js index 9201c1c8e0fb4..b5c0e7a95d401 100644 --- a/app/code/Magento/Catalog/view/adminhtml/web/js/components/dynamic-rows-tier-price.js +++ b/app/code/Magento/Catalog/view/adminhtml/web/js/components/dynamic-rows-tier-price.js @@ -9,6 +9,10 @@ define([ ], function (_, DynamicRows) { 'use strict'; + /** + * @deprecated Parent method contains labels sorting. + * @see Magento_Ui/js/dynamic-rows/dynamic-rows + */ return DynamicRows.extend({ /** diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index d4eea859b4d35..01fa03d1b4b67 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -533,7 +533,8 @@ define([ * Init header elements */ initHeader: function () { - var data; + var labels = [], + data; if (!this.labels().length) { _.each(this.childTemplate.children, function (cell) { @@ -547,8 +548,9 @@ define([ sortOrder: cell.config.sortOrder }); - this.labels.push(data); + labels.push(data); }, this); + this.labels(_.sortBy(labels, 'sortOrder')); } }, diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/dynamic-rows/dynamic-rows.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/dynamic-rows/dynamic-rows.test.js index 2eacea247d051..2e238eb993029 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/dynamic-rows/dynamic-rows.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/dynamic-rows/dynamic-rows.test.js @@ -131,5 +131,43 @@ define([ model.deleteRecord(1, 1); expect(model.recordData()).toEqual([]); }); + + it('"initHeader" sortOrder', function () { + var labels = [{ + name: 'Name 1', + config: { + label: 'Label 1', + validation: false, + columnsHeaderClasses: '', + sortOrder: 10 + } + }, { + name: 'Name 2', + config: { + label: 'Label 2', + validation: false, + columnsHeaderClasses: '', + sortOrder: 5 + } + }], + result = [{ + label: 'Label 2', + name: 'Name 2', + required: false, + columnsHeaderClasses: '', + sortOrder: 5 + }, { + label: 'Label 1', + name: 'Name 1', + required: false, + columnsHeaderClasses: '', + sortOrder: 10 + }]; + + model.childTemplate = { + children: labels + }; + expect(JSON.stringify(model.labels())).toEqual(JSON.stringify(result)); + }); }); });