Skip to content

Commit 0fbf1d9

Browse files
committed
MAGETWO-90441: Allow inline editing of Heading from stage
- set default text align value to empty - extend select component to allow options with empty values
1 parent 79f3f90 commit 0fbf1d9

File tree

3 files changed

+103
-2
lines changed

3 files changed

+103
-2
lines changed

app/code/Magento/PageBuilder/etc/adminhtml/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
<argument name="optionsSize" xsi:type="string">small</argument>
108108
<argument name="optionsData" xsi:type="array">
109109
<item name="0" xsi:type="array">
110-
<item name="value" xsi:type="string">default</item>
110+
<item name="value" xsi:type="string"/>
111111
<item name="title" xsi:type="string" translate="true">Default</item>
112112
</item>
113113
<item name="1" xsi:type="array">

app/code/Magento/PageBuilder/view/adminhtml/ui_component/pagebuilder_base_form.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<label translate="true">Advanced</label>
2424
<collapsible>true</collapsible>
2525
</settings>
26-
<field name="text_align" sortOrder="10" formElement="select">
26+
<field name="text_align" sortOrder="10" formElement="select" component="Magento_PageBuilder/js/form/element/visual-select">
2727
<argument name="data" xsi:type="array">
2828
<item name="config" xsi:type="array">
2929
<item name="default" xsi:type="string"/>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'underscore',
8+
'Magento_Ui/js/form/element/select'
9+
], function (_, Select) {
10+
'use strict';
11+
12+
return Select.extend({
13+
14+
/**
15+
* Parses incoming options, considers options with undefined value property
16+
* as caption
17+
*
18+
* @param {Array} nodes
19+
* @return {Object} captionValue
20+
*/
21+
parseOptions: function (nodes, captionValue) {
22+
var caption,
23+
value;
24+
25+
nodes = _.map(nodes, function (node) {
26+
value = node.value;
27+
28+
if (value === null || value === captionValue) {
29+
if (_.isUndefined(caption)) {
30+
caption = node.label;
31+
}
32+
// Allow nodes with empty values to return
33+
return node;
34+
} else {
35+
return node;
36+
}
37+
});
38+
39+
return {
40+
options: _.compact(nodes),
41+
caption: _.isString(caption) ? caption : false
42+
};
43+
},
44+
45+
/**
46+
* Recursively set to object item like value and item.value like key.
47+
*
48+
* @param {Array} data
49+
* @param {Object} result
50+
* @returns {Object}
51+
*/
52+
indexOptions: function (data, result) {
53+
var value;
54+
55+
result = result || {};
56+
57+
data.forEach(function (item) {
58+
value = item.value;
59+
60+
if (Array.isArray(value)) {
61+
indexOptions(value, result);
62+
} else {
63+
result[value] = item;
64+
}
65+
});
66+
67+
return result;
68+
},
69+
70+
/**
71+
* Sets 'data' to 'options' observable array, if instance has
72+
* 'customEntry' property set to true, calls 'setHidden' method
73+
* passing !options.length as a parameter
74+
*
75+
* @param {Array} data
76+
* @returns {Object} Chainable
77+
*/
78+
setOptions: function (data) {
79+
var captionValue = this.captionValue || '',
80+
result = this.parseOptions(data, captionValue),
81+
isVisible;
82+
83+
this.indexedOptions = this.indexOptions(result.options);
84+
85+
this.options(result.options);
86+
87+
if (!this.caption()) {
88+
this.caption(result.caption);
89+
}
90+
91+
if (this.customEntry) {
92+
isVisible = !!result.options.length;
93+
94+
this.setVisible(isVisible);
95+
this.toggleInput(!isVisible);
96+
}
97+
98+
return this;
99+
}
100+
});
101+
});

0 commit comments

Comments
 (0)