@widergy/energy-ui 3.66.0 → 3.66.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [3.66.2](https://github.com/widergy/energy-ui/compare/v3.66.1...v3.66.2) (2025-03-19)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * [UGC-1228] workflow add class ([#593](https://github.com/widergy/energy-ui/issues/593)) ([3f3e8df](https://github.com/widergy/energy-ui/commit/3f3e8df0785a8919f285cca8e961ea5b60fa3679))
7
+
8
+ ## [3.66.1](https://github.com/widergy/energy-ui/compare/v3.66.0...v3.66.1) (2025-03-18)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * [UGENSA-1485] map options markers ([#587](https://github.com/widergy/energy-ui/issues/587)) ([7559241](https://github.com/widergy/energy-ui/commit/7559241323ffa7744d86137f538191a04c4d6389))
14
+
1
15
  # [3.66.0](https://github.com/widergy/energy-ui/compare/v3.65.0...v3.66.0) (2025-03-06)
2
16
 
3
17
 
@@ -21,25 +21,29 @@ class GoogleMaps extends _react.PureComponent {
21
21
  constructor() {
22
22
  super(...arguments);
23
23
  _defineProperty(this, "handleMarkerRightClick", marker => this.props.onMarkerRightClick(marker));
24
+ _defineProperty(this, "handleMarkerClick", (marker, optionData) => this.props.onMarkerClick(marker, optionData));
24
25
  }
25
26
  render() {
26
27
  const {
27
- onMapMounted,
28
- onMapClick,
29
28
  center,
30
- zoom,
31
- usePolygon,
32
- polygonPath,
33
- onSearchBoxMounted,
29
+ colorBorderPolygon,
30
+ colorPolygon,
31
+ disabled,
32
+ markers,
33
+ MultipleMarkersIcon,
34
+ onMapClick,
35
+ onMapMounted,
34
36
  onPlacesChanged,
37
+ onSearchBoxMounted,
38
+ onSearchChange,
35
39
  placeholder,
40
+ polygonPath,
41
+ searchEnabled,
36
42
  searchValue,
37
- onSearchChange,
38
- disabled,
39
- markers,
40
- showOnlyMap,
41
- colorPolygon,
42
- colorBorderPolygon
43
+ selectedPosition,
44
+ singleMarker,
45
+ usePolygon,
46
+ zoom
43
47
  } = this.props;
44
48
  const polygonOptions = (0, _constants.polygonDefaultOptions)(colorPolygon, colorBorderPolygon);
45
49
  const handleStopPropagation = e => {
@@ -58,7 +62,7 @@ class GoogleMaps extends _react.PureComponent {
58
62
  defaultOptions: polygonOptions,
59
63
  onClick: onMapClick,
60
64
  path: polygonPath
61
- }), !showOnlyMap && /*#__PURE__*/_react.default.createElement(_SearchBox.default, {
65
+ }), searchEnabled && /*#__PURE__*/_react.default.createElement(_SearchBox.default, {
62
66
  ref: onSearchBoxMounted,
63
67
  controlPosition: window.google.maps.ControlPosition.TOP_LEFT,
64
68
  onPlacesChanged: onPlacesChanged
@@ -70,10 +74,18 @@ class GoogleMaps extends _react.PureComponent {
70
74
  onChange: onSearchChange,
71
75
  disabled: disabled,
72
76
  onKeyDown: handleStopPropagation
73
- })), markers.map(marker => /*#__PURE__*/_react.default.createElement(_reactGoogleMaps.Marker, _extends({}, marker, {
74
- key: marker.key,
75
- onRightClick: this.handleMarkerRightClick
76
- }))));
77
+ })), markers.map(marker => {
78
+ const label = marker.label || '';
79
+ const selected = marker.key === selectedPosition;
80
+ return /*#__PURE__*/_react.default.createElement(_reactGoogleMaps.Marker, _extends({}, marker, {
81
+ key: marker.key,
82
+ onRightClick: this.handleMarkerRightClick,
83
+ onClick: markerData => this.handleMarkerClick(markerData, marker)
84
+ }, MultipleMarkersIcon && !singleMarker && {
85
+ icon: MultipleMarkersIcon(label, selected),
86
+ label: undefined
87
+ }));
88
+ }));
77
89
  }
78
90
  }
79
91
  GoogleMaps.propTypes = _types.GoogleMapsPropTypes;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.ZOOM_INITIAL = exports.ZOOM_ADDRESS_VALID = exports.TEXTS = exports.LOCATION_TYPES = exports.GMAP_PARAMS = exports.ADDRESS_TYPES = void 0;
6
+ exports.ZOOM_INITIAL = exports.ZOOM_ADDRESS_VALID = exports.TEXTS = exports.MAP_PADDING = exports.LOCATION_TYPES = exports.GMAP_PARAMS = exports.ADDRESS_TYPES = void 0;
7
7
  const GMAP_PARAMS = exports.GMAP_PARAMS = {
8
8
  latitude: 'latitude',
9
9
  longitude: 'longitude',
@@ -25,4 +25,5 @@ const ADDRESS_TYPES = exports.ADDRESS_TYPES = {
25
25
  route: 'route'
26
26
  };
27
27
  const ZOOM_INITIAL = exports.ZOOM_INITIAL = 10;
28
- const ZOOM_ADDRESS_VALID = exports.ZOOM_ADDRESS_VALID = 15;
28
+ const ZOOM_ADDRESS_VALID = exports.ZOOM_ADDRESS_VALID = 15;
29
+ const MAP_PADDING = exports.MAP_PADDING = 60;
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
- var _array = require("@widergy/web-utils/lib/array");
9
8
  var _form = require("@widergy/web-utils/lib/form");
9
+ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
10
10
  var _UTLabel = _interopRequireDefault(require("../UTLabel"));
11
11
  var _googleMapsTypes = require("../../types/googleMapsTypes");
12
12
  var _WithGoogleMaps = _interopRequireDefault(require("../WithGoogleMaps"));
@@ -22,7 +22,9 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
22
22
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
23
  class UTMap extends _react.PureComponent {
24
24
  constructor(props) {
25
+ var _this;
25
26
  super(props);
27
+ _this = this;
26
28
  _defineProperty(this, "handleSearchChange", event => this.setState({
27
29
  searchValue: event.target.value
28
30
  }));
@@ -40,12 +42,13 @@ class UTMap extends _react.PureComponent {
40
42
  }, () => {
41
43
  const {
42
44
  field,
43
- onChange
45
+ onChange,
46
+ singleMarker
44
47
  } = this.props;
45
48
  const addressComponents = field.configuration.address_components;
46
49
  const addressValue = {};
47
50
  Object.keys(addressComponents).map(key => addressValue[addressComponents[key]] = (0, _utils.getValue)(address, latLng, key));
48
- if (changeValue) onChange(addressValue);
51
+ if (changeValue && singleMarker) onChange(addressValue);
49
52
  });
50
53
  });
51
54
  });
@@ -56,23 +59,39 @@ class UTMap extends _react.PureComponent {
56
59
  defaultAnimation: 2,
57
60
  key: Date.now()
58
61
  };
59
- const markers = [...(this.props.singleMarker ? [] : [...this.state.markers]), newMarker];
62
+ const markers = this.props.singleMarker ? [newMarker] : [...this.state.markers];
60
63
  this.setState({
61
64
  markers
62
65
  });
63
66
  });
64
67
  _defineProperty(this, "handleMapClick", event => {
65
68
  // When user click on any place inside map
66
- if (this.props.disabled) return;
67
- if ((0, _utils.checkAddressIsValid)(event.latLng, this.state.usePolygon, this.props.polygonPath)) {
68
- this.props.onChange(null);
69
- this.updateMarker(event.latLng);
70
- this.updateAddress(event.latLng, null, true);
71
- } else if (this.props.onLocationOutOfBoundsCallback) {
69
+ const {
70
+ disabled,
71
+ singleMarker,
72
+ onChange,
73
+ polygonPath,
74
+ onLocationOutOfBoundsCallback,
75
+ zoomAddressInvalid
76
+ } = this.props;
77
+ const {
78
+ usePolygon
79
+ } = this.state;
80
+ const {
81
+ latLng
82
+ } = event;
83
+ if (disabled) return;
84
+ const isValid = (0, _utils.checkAddressIsValid)(latLng, usePolygon, polygonPath);
85
+ if (!isValid && onLocationOutOfBoundsCallback) {
72
86
  this.setState({
73
- mapZoom: this.props.zoomAddressInvalid || 10
87
+ mapZoom: zoomAddressInvalid || 10
74
88
  });
75
- this.props.onLocationOutOfBoundsCallback();
89
+ return onLocationOutOfBoundsCallback();
90
+ }
91
+ if (isValid && singleMarker) {
92
+ onChange(null);
93
+ this.updateMarker(latLng);
94
+ this.updateAddress(latLng, null, true);
76
95
  }
77
96
  });
78
97
  _defineProperty(this, "centerMap", latLng => this.setState({
@@ -85,12 +104,28 @@ class UTMap extends _react.PureComponent {
85
104
  markers: nextMarkers
86
105
  });
87
106
  });
107
+ _defineProperty(this, "handleMarkerClick", function (_) {
108
+ let optionData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
109
+ const {
110
+ key,
111
+ value
112
+ } = optionData;
113
+ const {
114
+ onChange
115
+ } = _this.props;
116
+ const selected = _this.state.selectedPosition === key;
117
+ _this.setState({
118
+ selectedPosition: selected ? null : key
119
+ });
120
+ if (onChange) onChange(selected ? null : value);
121
+ });
88
122
  _defineProperty(this, "handleMapMounted", mapRef => {
89
123
  // When map is mounted on screen
90
124
  this.map = mapRef;
91
125
  const {
92
126
  input,
93
- field
127
+ field,
128
+ singleMarker
94
129
  } = this.props;
95
130
  if (input.value) {
96
131
  const addressComponents = field.configuration.address_components;
@@ -101,27 +136,36 @@ class UTMap extends _react.PureComponent {
101
136
  if (this.props.useGeolocation) {
102
137
  // We try to recover user actual position with navigator geolocation
103
138
  (0, _utils.geolocation)(this.props.errors.retrieveLocationError).getCurrentPosition(userPosition => {
139
+ var _this$state$markers;
104
140
  // If we can retrieve user position...
141
+
142
+ const markerCoordinates = !singleMarker && ((_this$state$markers = this.state.markers) === null || _this$state$markers === void 0 || (_this$state$markers = _this$state$markers[0]) === null || _this$state$markers === void 0 ? void 0 : _this$state$markers.position);
143
+ const {
144
+ lat: optionLat,
145
+ lng: optionLng
146
+ } = markerCoordinates || {};
105
147
  const {
106
148
  latitude: userLatitude,
107
149
  longitude: userLongitude
108
150
  } = userPosition.coords;
109
- const userLatLng = new window.google.maps.LatLng(userLatitude, userLongitude);
151
+ const searchLatitude = singleMarker ? userLatitude : optionLat;
152
+ const searchLongitude = singleMarker ? userLongitude : optionLng;
153
+ const userLatLng = new window.google.maps.LatLng(searchLatitude, searchLongitude);
110
154
  if ((0, _utils.checkAddressIsValid)(userLatLng, this.state.usePolygon, this.props.polygonPath)) {
111
155
  const actualPosition = {
112
- lat: userLatitude,
113
- lng: userLongitude
156
+ lat: searchLatitude,
157
+ lng: searchLongitude
114
158
  };
115
159
  this.setState({
116
160
  center: actualPosition,
117
- markers: [{
161
+ markers: [...(this.props.singleMarker ? [{
118
162
  position: actualPosition,
119
163
  key: Date.now(),
120
164
  defaultAnimation: 2
121
- }],
165
+ }] : this.state.markers)],
122
166
  mapLoading: false
123
167
  }, () => {
124
- const latlng = new window.google.maps.LatLng(userLatitude, userLongitude);
168
+ const latlng = new window.google.maps.LatLng(searchLatitude, searchLongitude);
125
169
  this.updateAddress(latlng, null, true);
126
170
  });
127
171
  } else {
@@ -136,6 +180,13 @@ class UTMap extends _react.PureComponent {
136
180
  this.updateAddress(latlng, null, true);
137
181
  });
138
182
  }
183
+ const bounds = new window.google.maps.LatLngBounds();
184
+ this.state.markers.forEach(marker => {
185
+ bounds.extend(new window.google.maps.LatLng(marker.position.lat, marker.position.lng));
186
+ });
187
+ if (this.map && !singleMarker) {
188
+ this.map.fitBounds(bounds, _constants.MAP_PADDING);
189
+ }
139
190
  });
140
191
  _defineProperty(this, "handleBoundsChanged", () => this.setState({
141
192
  center: this.map.getCenter()
@@ -144,7 +195,7 @@ class UTMap extends _react.PureComponent {
144
195
  _defineProperty(this, "handlePlacesChanged", () => {
145
196
  if (this.props.disabled) return;
146
197
  const places = this.searchBox.getPlaces();
147
- const place = !(0, _array.isEmpty)(places) && (0, _utils.checkAddressIsValid)(places[0].geometry.location, this.state.usePolygon, this.props.polygonPath) && places[0];
198
+ const place = !(0, _isEmpty.default)(places) && (0, _utils.checkAddressIsValid)(places[0].geometry.location, this.state.usePolygon, this.props.polygonPath) && places[0];
148
199
  if (place) {
149
200
  this.props.onChange(null);
150
201
  this.updateMarker(place.geometry.location);
@@ -157,8 +208,9 @@ class UTMap extends _react.PureComponent {
157
208
  mapLoading: true,
158
209
  searchValue: '',
159
210
  mapZoom: this.props.zoomInitial || _constants.ZOOM_INITIAL,
160
- usePolygon: this.props.usePolygon && !(0, _array.isEmpty)(this.props.polygonPath),
161
- invalidConfiguration: false
211
+ usePolygon: this.props.usePolygon && !(0, _isEmpty.default)(this.props.polygonPath),
212
+ invalidConfiguration: false,
213
+ selectedPosition: null
162
214
  };
163
215
  }
164
216
  componentDidMount() {
@@ -171,7 +223,8 @@ class UTMap extends _react.PureComponent {
171
223
  const {
172
224
  input,
173
225
  startLocation,
174
- field
226
+ field = {},
227
+ options = []
175
228
  } = this.props;
176
229
  if (!(0, _utils.isValidConfiguration)(field)) {
177
230
  this.setState({
@@ -180,6 +233,15 @@ class UTMap extends _react.PureComponent {
180
233
  });
181
234
  return;
182
235
  }
236
+ const coordinates = options.map(option => ({
237
+ key: option.id.toString(),
238
+ position: {
239
+ lat: option.configuration.coordinates.latitude,
240
+ lng: option.configuration.coordinates.longitude
241
+ },
242
+ label: "".concat(option.value),
243
+ value: option.value
244
+ }));
183
245
  if (input.value) {
184
246
  startPosition.position.lat = input.value[field.configuration.address_components[_constants.GMAP_PARAMS.latitude]];
185
247
  startPosition.position.lng = input.value[field.configuration.address_components[_constants.GMAP_PARAMS.longitude]];
@@ -197,35 +259,47 @@ class UTMap extends _react.PureComponent {
197
259
  mapLoading: false
198
260
  });
199
261
  }
262
+ if (!(0, _isEmpty.default)(coordinates)) {
263
+ this.setState({
264
+ center: coordinates[0].position,
265
+ markers: coordinates,
266
+ mapLoading: false
267
+ });
268
+ }
200
269
  }
201
270
  render() {
202
271
  const {
203
- showOnlyMap
272
+ showOnlyMap = false
204
273
  } = this.props.field.configuration;
274
+ const searchEnabled = !showOnlyMap && this.props.singleMarker;
205
275
  return /*#__PURE__*/_react.default.createElement("div", null, this.state.center ? /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_GoogleMaps.default, {
276
+ center: this.state.center,
277
+ colorBorderPolygon: this.props.colorBorderPolygon,
278
+ colorPolygon: this.props.colorPolygon,
206
279
  containerElement: /*#__PURE__*/_react.default.createElement("div", {
207
280
  className: this.props.className
208
281
  }),
282
+ disabled: this.props.disabled,
209
283
  mapElement: /*#__PURE__*/_react.default.createElement("div", {
210
284
  className: this.props.className
211
285
  }),
286
+ markers: this.state.markers,
287
+ MultipleMarkersIcon: this.props.MultipleMarkersIcon,
212
288
  onMapClick: this.handleMapClick,
213
- onMarkerRightClick: this.handleMarkerRightClick,
214
289
  onMapMounted: this.handleMapMounted,
215
- onSearchBoxMounted: this.handleSearchBoxMounted,
290
+ onMarkerClick: this.handleMarkerClick,
291
+ onMarkerRightClick: this.handleMarkerRightClick,
216
292
  onPlacesChanged: this.handlePlacesChanged,
217
- markers: this.state.markers,
218
- center: this.state.center,
219
- searchValue: this.state.searchValue,
293
+ onSearchBoxMounted: this.handleSearchBoxMounted,
220
294
  onSearchChange: this.handleSearchChange,
221
- zoom: this.state.mapZoom,
295
+ placeholder: this.props.placeholder,
222
296
  polygonPath: this.props.polygonPath,
297
+ searchEnabled: searchEnabled,
298
+ searchValue: this.state.searchValue,
299
+ selectedPosition: this.state.selectedPosition,
300
+ singleMarker: this.props.singleMarker,
223
301
  usePolygon: this.state.usePolygon,
224
- placeholder: this.props.placeholder,
225
- disabled: this.props.disabled,
226
- showOnlyMap: showOnlyMap,
227
- colorPolygon: this.props.colorPolygon,
228
- colorBorderPolygon: this.props.colorBorderPolygon
302
+ zoom: this.state.mapZoom
229
303
  })) : this.state.mapLoading ? /*#__PURE__*/_react.default.createElement(_UTLabel.default, null, this.props.errors.retrievingLocation) : this.state.invalidConfiguration ? /*#__PURE__*/_react.default.createElement(_UTLabel.default, {
230
304
  colorTheme: "error",
231
305
  variant: "small"
@@ -143,7 +143,7 @@ const UTWorkflowContainer = _ref => {
143
143
  }, /*#__PURE__*/_react.default.createElement("div", {
144
144
  className: "".concat(_constants.childrenContentStyle[variant] || _stylesModule.default.childrenContent, " ").concat(classes.childrenContent)
145
145
  }, children))), /*#__PURE__*/_react.default.createElement("div", {
146
- className: _stylesModule.default.footer
146
+ className: "".concat(_stylesModule.default.footer, " ").concat(classes.footer)
147
147
  }, /*#__PURE__*/_react.default.createElement(_UTWizard.default, wizardConfig), !isNavHidden && /*#__PURE__*/_react.default.createElement("div", {
148
148
  className: "".concat(classes.bottomNav, " ").concat(_stylesModule.default.bottomNav)
149
149
  }, checkbox && isMobileOrTablet && /*#__PURE__*/_react.default.createElement("div", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widergy/energy-ui",
3
- "version": "3.66.0",
3
+ "version": "3.66.2",
4
4
  "description": "Widergy Web Components",
5
5
  "author": "widergy",
6
6
  "license": "MIT",