Skip to content

Commit 58a7c5d

Browse files
author
Michael Yu
committed
MAGETWO-92335: Architecture Review
- Resolved name conflict for location form and map form
1 parent ec32d7c commit 58a7c5d

File tree

6 files changed

+74
-26
lines changed

6 files changed

+74
-26
lines changed

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

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,12 @@
159159
<item name="componentType" xsi:type="string">container</item>
160160
</item>
161161
</argument>
162-
<field name="name" component="Magento_Ui/js/form/element/text" formElement="input" >
162+
<field name="location_name" component="Magento_Ui/js/form/element/text" formElement="input" >
163+
<argument name="data" xsi:type="array">
164+
<item name="config" xsi:type="array">
165+
<item name="sortBy" xsi:type="string">name</item>
166+
</item>
167+
</argument>
163168
<settings>
164169
<dataType>text</dataType>
165170
<label translate="true">Location Name</label>
@@ -168,7 +173,12 @@
168173
<elementTmpl>ui/dynamic-rows/cells/text</elementTmpl>
169174
</settings>
170175
</field>
171-
<field name="phone" component="Magento_Ui/js/form/element/text" formElement="input">
176+
<field name="location_phone" component="Magento_Ui/js/form/element/text" formElement="input">
177+
<argument name="data" xsi:type="array">
178+
<item name="config" xsi:type="array">
179+
<item name="sortBy" xsi:type="string">phone</item>
180+
</item>
181+
</argument>
172182
<settings>
173183
<dataType>text</dataType>
174184
<label translate="true">Phone Number</label>
@@ -177,7 +187,12 @@
177187
<elementTmpl>ui/dynamic-rows/cells/text</elementTmpl>
178188
</settings>
179189
</field>
180-
<field name="address" component="Magento_Ui/js/form/element/text" formElement="input">
190+
<field name="location_address" component="Magento_Ui/js/form/element/text" formElement="input">
191+
<argument name="data" xsi:type="array">
192+
<item name="config" xsi:type="array">
193+
<item name="sortBy" xsi:type="string">address</item>
194+
</item>
195+
</argument>
181196
<settings>
182197
<dataType>text</dataType>
183198
<label translate="true">Street Address</label>
@@ -186,7 +201,12 @@
186201
<elementTmpl>ui/dynamic-rows/cells/text</elementTmpl>
187202
</settings>
188203
</field>
189-
<field name="city" component="Magento_Ui/js/form/element/text" formElement="input">
204+
<field name="location_city" component="Magento_Ui/js/form/element/text" formElement="input">
205+
<argument name="data" xsi:type="array">
206+
<item name="config" xsi:type="array">
207+
<item name="sortBy" xsi:type="string">city</item>
208+
</item>
209+
</argument>
190210
<settings>
191211
<dataType>text</dataType>
192212
<label translate="true">City</label>
@@ -195,7 +215,12 @@
195215
<elementTmpl>ui/dynamic-rows/cells/text</elementTmpl>
196216
</settings>
197217
</field>
198-
<field name="state" component="Magento_Ui/js/form/element/text" formElement="input">
218+
<field name="location_state" component="Magento_Ui/js/form/element/text" formElement="input">
219+
<argument name="data" xsi:type="array">
220+
<item name="config" xsi:type="array">
221+
<item name="sortBy" xsi:type="string">state</item>
222+
</item>
223+
</argument>
199224
<settings>
200225
<dataType>text</dataType>
201226
<label translate="true">Region/State</label>
@@ -204,7 +229,12 @@
204229
<elementTmpl>ui/dynamic-rows/cells/text</elementTmpl>
205230
</settings>
206231
</field>
207-
<field name="zipcode" component="Magento_Ui/js/form/element/text" formElement="input">
232+
<field name="location_zipcode" component="Magento_Ui/js/form/element/text" formElement="input">
233+
<argument name="data" xsi:type="array">
234+
<item name="config" xsi:type="array">
235+
<item name="sortBy" xsi:type="string">zipcode</item>
236+
</item>
237+
</argument>
208238
<settings>
209239
<dataType>text</dataType>
210240
<label translate="true">Zip/Postal Code</label>
@@ -213,7 +243,12 @@
213243
<elementTmpl>ui/dynamic-rows/cells/text</elementTmpl>
214244
</settings>
215245
</field>
216-
<field name="country" component="Magento_Ui/js/form/element/text" formElement="input">
246+
<field name="location_country" component="Magento_Ui/js/form/element/text" formElement="input">
247+
<argument name="data" xsi:type="array">
248+
<item name="config" xsi:type="array">
249+
<item name="sortBy" xsi:type="string">country</item>
250+
</item>
251+
</argument>
217252
<settings>
218253
<dataType>text</dataType>
219254
<label translate="true">Country</label>

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/map/preview.js

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/form/components/dynamic-rows.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,31 @@ define([
3030
return this;
3131
},
3232

33+
/**
34+
* Init header elements
35+
*/
36+
initHeader: function () {
37+
var labels = [],
38+
data;
39+
40+
if (!this.labels().length) {
41+
_.each(this.childTemplate.children, function (cell) {
42+
data = this.createHeaderTemplate(cell.config);
43+
cell.config.labelVisible = false;
44+
_.extend(data, {
45+
label: cell.config.label,
46+
name: cell.name,
47+
required: !!cell.config.validation,
48+
columnsHeaderClasses: cell.config.columnsHeaderClasses,
49+
sortOrder: cell.config.sortOrder,
50+
sortBy: cell.config.sortBy
51+
});
52+
labels.push(data);
53+
}, this);
54+
this.labels(_.sortBy(labels, 'sortOrder'));
55+
}
56+
},
57+
3358
/**
3459
* Open the location modal and insert form with the data from selected record
3560
*
@@ -83,7 +108,7 @@ define([
83108
allLabels,
84109
placeholder;
85110

86-
if (property().name === 'actions') {
111+
if (!property().sortBy) {
87112
return;
88113
}
89114

@@ -96,7 +121,8 @@ define([
96121
} else {
97122
allLabels = this.labels().slice();
98123
allLabels.forEach(function (label) {
99-
if (label.name === property().name) {
124+
125+
if (label.sortBy === property().sortBy) {
100126
label.columnsHeaderClasses = '_ascend';
101127
} else {
102128
label.columnsHeaderClasses = '';
@@ -110,7 +136,7 @@ define([
110136
placeholder = this.emptyContentPlaceholder;
111137

112138
this.emptyContentPlaceholder = false;
113-
this.sortRecord(property().name, ascend);
139+
this.sortRecord(property().sortBy, ascend);
114140
this.reload();
115141
this.emptyContentPlaceholder = placeholder;
116142
}

app/code/Magento/PageBuilder/view/adminhtml/web/js/form/element/map.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ define([
134134
if (typeof this.value() === 'string' && this.value() !== '') {
135135
content = JSON.parse(this.value());
136136
}
137-
138137
latitudeLongitude = new google.maps.LatLng(parseFloat(content.latitude), parseFloat(content.longitude));
139138

140139
if (!this.marker) {
141140
this.addMarker(latitudeLongitude.lat(), latitudeLongitude.lng());
142141
}
143142

144143
this.marker.setPosition(latitudeLongitude);
144+
debugger;
145145
this.map.setCenter(latitudeLongitude);
146146
},
147147

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/map/preview.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@ export default class Preview extends BasePreview {
9595
location.position.longitude = parseFloat(location.position.longitude);
9696
});
9797

98-
if (locations[0]) {
99-
options.center = {
100-
latitude: locations[0].position.latitude,
101-
longitude: locations[0].position.longitude,
102-
};
103-
}
104-
10598
return {
10699
locations,
107100
options,

app/code/Magento/PageBuilder/view/base/web/js/utils/map.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ define([
2222
};
2323

2424
return function (element, markers, options) {
25+
2526
var mapOptions = _.extend({
2627
zoom: 8,
2728
center: getGoogleLatitudeLongitude({
@@ -132,6 +133,7 @@ define([
132133
* Zoom to 8 if there is only a single location
133134
*/
134135
if (this.bounds.length === 1) {
136+
this.map.setCenter(this.bounds[0]);
135137
this.map.setZoom(8);
136138
}
137139
};

0 commit comments

Comments
 (0)