-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #951 from magento-nord/NORD-EXT-PR-31
MAGETWO-63502: A lot of catalog related entities shown in admin product grid column
- Loading branch information
Showing
7 changed files
with
282 additions
and
4 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
app/code/Magento/Ui/view/base/web/js/grid/columns/expandable.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
define([ | ||
'./column' | ||
], function (Column) { | ||
'use strict'; | ||
|
||
return Column.extend({ | ||
defaults: { | ||
bodyTmpl: 'ui/grid/cells/expandable', | ||
tooltipTmpl: 'ui/grid/cells/expandable/content', | ||
visibeItemsLimit: 5, | ||
tooltipTitle: '' | ||
}, | ||
|
||
/** | ||
* Gets label from full options array. | ||
* | ||
* @param {Object} record - Record object. | ||
* @returns {String} | ||
*/ | ||
getFullLabel: function (record) { | ||
return this.getLabelsArray(record).join(', '); | ||
}, | ||
|
||
/** | ||
* Gets label from options array limited by 'visibeItemsLimit'. | ||
* | ||
* @param {Object} record - Record object. | ||
* @returns {String} | ||
*/ | ||
getShortLabel: function (record) { | ||
return this.getLabelsArray(record).slice(0, this.visibeItemsLimit).join(', '); | ||
}, | ||
|
||
/** | ||
* Extracts array of labels associated with provided values and sort it alphabetically. | ||
* | ||
* @param {Object} record - Record object. | ||
* @returns {Array} | ||
*/ | ||
getLabelsArray: function (record) { | ||
var values = this.getLabel(record), | ||
options = this.options || [], | ||
labels = []; | ||
|
||
if (_.isString(values)) { | ||
values = values.split(','); | ||
} | ||
|
||
if (!Array.isArray(values)) { | ||
values = [values]; | ||
} | ||
|
||
values = values.map(function (value) { | ||
return value + ''; | ||
}); | ||
|
||
options = this.flatOptions(options); | ||
|
||
options.forEach(function (item) { | ||
if (_.contains(values, item.value + '')) { | ||
labels.push(item.label); | ||
} | ||
}); | ||
|
||
return labels.sort(); | ||
}, | ||
|
||
/** | ||
* Transformation tree options structure to liner array. | ||
* | ||
* @param {Array} options | ||
* @returns {Array} | ||
*/ | ||
flatOptions: function (options) { | ||
var self = this; | ||
|
||
return options.reduce(function (options, option) { | ||
if (_.isArray(option.value)) { | ||
options = options.concat(self.flatOptions(option.value)); | ||
} else { | ||
options.push(option); | ||
} | ||
|
||
return options; | ||
}, []); | ||
}, | ||
|
||
/** | ||
* Checks if amount of options is more than limit value. | ||
* | ||
* @param {Object} record - Data to be preprocessed. | ||
* @returns {Boolean} | ||
*/ | ||
isExpandable: function (record) { | ||
return this.getLabel(record).length > this.visibeItemsLimit; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/code/Magento/Ui/view/base/web/templates/grid/cells/expandable.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!-- | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<div class="data-grid-cell-content"> | ||
<span text="$col.getFullLabel($row())" ifnot="$col.isExpandable($row())"/> | ||
|
||
<div if="$col.isExpandable($row())"> | ||
<div text="$col.getShortLabel($row())" class="admin__control-short-label" /> | ||
<a attr="'data-tooltip-trigger': ++ko.uid" translate="'Show more'"/> | ||
<div | ||
tooltip=" | ||
tooltipClasses: 'data-grid-column-tooltip', | ||
trigger: '[data-tooltip-trigger=' + ko.uid + ']', | ||
action: 'click', | ||
delay: 0, | ||
center: true, | ||
position: 'top', | ||
closeButton: true, | ||
closeOnScroll: false | ||
"> | ||
<div render="$data.tooltipTmpl"/> | ||
</div> | ||
</div> | ||
</div> |
14 changes: 14 additions & 0 deletions
14
app/code/Magento/Ui/view/base/web/templates/grid/cells/expandable/content.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!-- | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<div class="admin__tooltip-title" if="$data.tooltipTitle.length"> | ||
<span translate="$data.tooltipTitle"/> | ||
</div> | ||
<ul class="items"> | ||
<li class="item" repeat="foreach: $col.getLabelsArray($row()), item: '$item'"> | ||
<span text="$item()"/> | ||
</li> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid/columns/expandable.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
define([ | ||
'Magento_Ui/js/grid/columns/expandable' | ||
], function (Expandable) { | ||
'use strict'; | ||
|
||
describe('Ui/js/grid/columns/expandable', function () { | ||
var expandable, record; | ||
|
||
beforeEach(function () { | ||
expandable = new Expandable({ | ||
index: 'shared_catalog', | ||
visibeItemsLimit: 1, | ||
options: [] | ||
}); | ||
record = { | ||
'entity_id': '3', | ||
'row_id': '3', | ||
'shared_catalog': [] | ||
}; | ||
}); | ||
|
||
describe('getFullLabel method', function () { | ||
it('get label while options are empty', function () { | ||
expect(expandable.getFullLabel(record)).toBe(''); | ||
}); | ||
|
||
it('get label after options are set', function () { | ||
record['shared_catalog'].push(1); | ||
expandable.options.push({ | ||
label: 'Default', | ||
value: '1' | ||
}); | ||
expect(expandable.getFullLabel(record)).toBe('Default'); | ||
}); | ||
|
||
it('check if getLabelsArray have been called', function () { | ||
spyOn(expandable, 'getLabelsArray').and.returnValues(['Default', 'Custom']); | ||
expandable.getFullLabel(record); | ||
expect(expandable.getLabelsArray).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('getShortLabel method', function () { | ||
it('get label while options are empty', function () { | ||
expect(expandable.getShortLabel(record)).toBe(''); | ||
}); | ||
}); | ||
|
||
describe('isExpandable method', function () { | ||
it('check if label is not expandable', function () { | ||
expect(expandable.isExpandable(record)).toBe(false); | ||
}); | ||
|
||
it('check if label is expandable', function () { | ||
record['shared_catalog'].push(1); | ||
record['shared_catalog'].push(2); | ||
expect(expandable.isExpandable(record)).toBe(true); | ||
}); | ||
|
||
it('check if getLabel have been called', function () { | ||
spyOn(expandable, 'getLabel').and.returnValues('1', '2'); | ||
expandable.isExpandable(record); | ||
expect(expandable.getLabel).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
}); |