ordering-ui-admin-external 1.45.41 → 1.45.43
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/_bundles/{ordering-ui-admin.afbc173eb532cc68dc11.js → ordering-ui-admin.fc0ab64d7a207636ee4c.js} +2 -2
- package/_modules/components/Orders/DriversLocation/index.js +39 -10
- package/package.json +2 -2
- package/src/components/Orders/DriversLocation/index.js +29 -5
- /package/_bundles/{ordering-ui-admin.afbc173eb532cc68dc11.js.LICENSE.txt → ordering-ui-admin.fc0ab64d7a207636ee4c.js.LICENSE.txt} +0 -0
|
@@ -57,23 +57,33 @@ var DriversLocation = exports.DriversLocation = function DriversLocation(props)
|
|
|
57
57
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
58
58
|
mapFitted = _useState8[0],
|
|
59
59
|
setMapFitted = _useState8[1];
|
|
60
|
-
var
|
|
61
|
-
var _useState9 = (0, _react.useState)([]),
|
|
60
|
+
var _useState9 = (0, _react.useState)(false),
|
|
62
61
|
_useState10 = _slicedToArray(_useState9, 2),
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
hasManualView = _useState10[0],
|
|
63
|
+
setHasManualView = _useState10[1];
|
|
64
|
+
var mapRef = (0, _react.useRef)(null);
|
|
65
|
+
var isProgrammaticChangeRef = (0, _react.useRef)(false);
|
|
66
|
+
var _useState11 = (0, _react.useState)([]),
|
|
67
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
68
|
+
showDrivers = _useState12[0],
|
|
69
|
+
setShowDrivers = _useState12[1];
|
|
65
70
|
var mapFit = function mapFit() {
|
|
66
|
-
var _assignedOrders$order2;
|
|
71
|
+
var _assignedOrders$order2, _bounds$getNorthEast, _bounds$getNorthEast$, _bounds$getNorthEast2, _bounds$getNorthEast3, _bounds$getSouthWest, _bounds$getSouthWest$, _bounds$getSouthWest2, _bounds$getSouthWest3;
|
|
67
72
|
var bounds = new window.google.maps.LatLngBounds();
|
|
68
73
|
if (!selectedOrder) {
|
|
69
74
|
var _assignedOrders$order;
|
|
70
75
|
if (showDrivers.length === 1 && !selectedOrder && !(assignedOrders !== null && assignedOrders !== void 0 && (_assignedOrders$order = assignedOrders.orders) !== null && _assignedOrders$order !== void 0 && _assignedOrders$order.length)) {
|
|
71
76
|
var _showDrivers$0$locati, _showDrivers$0$locati2, _showDrivers$, _showDrivers$2;
|
|
77
|
+
isProgrammaticChangeRef.current = true;
|
|
72
78
|
setMapCenter(showDrivers[0].location !== null && _typeof(showDrivers[0].location) === 'object' && (_showDrivers$0$locati = showDrivers[0].location) !== null && _showDrivers$0$locati !== void 0 && _showDrivers$0$locati.lat && (_showDrivers$0$locati2 = showDrivers[0].location) !== null && _showDrivers$0$locati2 !== void 0 && _showDrivers$0$locati2.lng ? showDrivers[0].location : typeof showDrivers[0].location === 'string' ? {
|
|
73
79
|
lat: parseFloat((_showDrivers$ = showDrivers[0]) === null || _showDrivers$ === void 0 || (_showDrivers$ = _showDrivers$.location) === null || _showDrivers$ === void 0 ? void 0 : _showDrivers$.split(',')[0].replace(/[^-.0-9]/g, '')),
|
|
74
80
|
lng: parseFloat((_showDrivers$2 = showDrivers[0]) === null || _showDrivers$2 === void 0 || (_showDrivers$2 = _showDrivers$2.location) === null || _showDrivers$2 === void 0 ? void 0 : _showDrivers$2.split(',')[1].replace(/[^-.0-9]/g, ''))
|
|
75
81
|
} : defaultCenter);
|
|
76
82
|
setMapZoom(mapZoom);
|
|
83
|
+
setMapFitted(true);
|
|
84
|
+
setTimeout(function () {
|
|
85
|
+
isProgrammaticChangeRef.current = false;
|
|
86
|
+
}, 0);
|
|
77
87
|
return;
|
|
78
88
|
}
|
|
79
89
|
var _iterator = _createForOfIteratorHelper(showDrivers),
|
|
@@ -124,12 +134,12 @@ var DriversLocation = exports.DriversLocation = function DriversLocation(props)
|
|
|
124
134
|
}
|
|
125
135
|
var newBounds = {
|
|
126
136
|
ne: {
|
|
127
|
-
lat: bounds.getNorthEast().lat(),
|
|
128
|
-
lng: bounds.getNorthEast().lng()
|
|
137
|
+
lat: (_bounds$getNorthEast = bounds.getNorthEast()) === null || _bounds$getNorthEast === void 0 || (_bounds$getNorthEast$ = _bounds$getNorthEast.lat) === null || _bounds$getNorthEast$ === void 0 ? void 0 : _bounds$getNorthEast$.call(_bounds$getNorthEast),
|
|
138
|
+
lng: (_bounds$getNorthEast2 = bounds.getNorthEast()) === null || _bounds$getNorthEast2 === void 0 || (_bounds$getNorthEast3 = _bounds$getNorthEast2.lng) === null || _bounds$getNorthEast3 === void 0 ? void 0 : _bounds$getNorthEast3.call(_bounds$getNorthEast2)
|
|
129
139
|
},
|
|
130
140
|
sw: {
|
|
131
|
-
lat: bounds.getSouthWest().lat(),
|
|
132
|
-
lng: bounds.getSouthWest().lng()
|
|
141
|
+
lat: (_bounds$getSouthWest = bounds.getSouthWest()) === null || _bounds$getSouthWest === void 0 || (_bounds$getSouthWest$ = _bounds$getSouthWest.lat) === null || _bounds$getSouthWest$ === void 0 ? void 0 : _bounds$getSouthWest$.call(_bounds$getSouthWest),
|
|
142
|
+
lng: (_bounds$getSouthWest2 = bounds.getSouthWest()) === null || _bounds$getSouthWest2 === void 0 || (_bounds$getSouthWest3 = _bounds$getSouthWest2.lng) === null || _bounds$getSouthWest3 === void 0 ? void 0 : _bounds$getSouthWest3.call(_bounds$getSouthWest2)
|
|
133
143
|
}
|
|
134
144
|
};
|
|
135
145
|
var mapSize = {
|
|
@@ -139,9 +149,13 @@ var DriversLocation = exports.DriversLocation = function DriversLocation(props)
|
|
|
139
149
|
var _fitBounds = (0, _googleMapReact.fitBounds)(newBounds, mapSize),
|
|
140
150
|
center = _fitBounds.center,
|
|
141
151
|
zoom = _fitBounds.zoom;
|
|
152
|
+
isProgrammaticChangeRef.current = true;
|
|
142
153
|
setMapZoom(zoom);
|
|
143
154
|
setMapCenter(center);
|
|
144
155
|
setMapFitted(true);
|
|
156
|
+
setTimeout(function () {
|
|
157
|
+
isProgrammaticChangeRef.current = false;
|
|
158
|
+
}, 0);
|
|
145
159
|
};
|
|
146
160
|
|
|
147
161
|
// Fit bounds on mount, and when the markers change
|
|
@@ -152,8 +166,10 @@ var DriversLocation = exports.DriversLocation = function DriversLocation(props)
|
|
|
152
166
|
setMapZoom(defaultZoom);
|
|
153
167
|
setMapCenter(defaultCenter);
|
|
154
168
|
setMapFitted(false);
|
|
169
|
+
setHasManualView(false);
|
|
155
170
|
return;
|
|
156
171
|
}
|
|
172
|
+
if (hasManualView) return;
|
|
157
173
|
if (selectedOrder && selectedDriver || selectedDriver && assignedOrders !== null && assignedOrders !== void 0 && (_assignedOrders$order3 = assignedOrders.orders) !== null && _assignedOrders$order3 !== void 0 && _assignedOrders$order3.length || !selectedOrder && !selectedDriver) {
|
|
158
174
|
mapFit();
|
|
159
175
|
return;
|
|
@@ -161,7 +177,7 @@ var DriversLocation = exports.DriversLocation = function DriversLocation(props)
|
|
|
161
177
|
if (!mapFitted) {
|
|
162
178
|
mapFit();
|
|
163
179
|
}
|
|
164
|
-
}, [JSON.stringify(showDrivers), mapLoaded, mapFitted, selectedOrder, assignedOrders === null || assignedOrders === void 0 ? void 0 : assignedOrders.orders]);
|
|
180
|
+
}, [JSON.stringify(showDrivers), mapLoaded, mapFitted, selectedOrder, assignedOrders === null || assignedOrders === void 0 ? void 0 : assignedOrders.orders, hasManualView]);
|
|
165
181
|
(0, _react.useEffect)(function () {
|
|
166
182
|
if (selectedDriver) {
|
|
167
183
|
setShowDrivers([selectedDriver]);
|
|
@@ -174,11 +190,24 @@ var DriversLocation = exports.DriversLocation = function DriversLocation(props)
|
|
|
174
190
|
}
|
|
175
191
|
}, [onlineDrivers, offlineDrivers, driversIsOnline, selectedDriver]);
|
|
176
192
|
var handleMapChange = function handleMapChange(data) {
|
|
193
|
+
var _data$center, _data$center2;
|
|
194
|
+
if (isProgrammaticChangeRef.current) return;
|
|
195
|
+
setHasManualView(true);
|
|
177
196
|
setMapZoom(data === null || data === void 0 ? void 0 : data.zoom);
|
|
197
|
+
if (data !== null && data !== void 0 && (_data$center = data.center) !== null && _data$center !== void 0 && _data$center.lat && data !== null && data !== void 0 && (_data$center2 = data.center) !== null && _data$center2 !== void 0 && _data$center2.lng) {
|
|
198
|
+
setMapCenter({
|
|
199
|
+
lat: data.center.lat,
|
|
200
|
+
lng: data.center.lng
|
|
201
|
+
});
|
|
202
|
+
}
|
|
178
203
|
};
|
|
179
204
|
(0, _react.useEffect)(function () {
|
|
180
205
|
setMapFitted(false);
|
|
181
206
|
}, [selectedOrder]);
|
|
207
|
+
(0, _react.useEffect)(function () {
|
|
208
|
+
setHasManualView(false);
|
|
209
|
+
setMapFitted(false);
|
|
210
|
+
}, [selectedOrder, selectedDriver, driversIsOnline]);
|
|
182
211
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, selectedDriver && (assignedOrders === null || assignedOrders === void 0 ? void 0 : assignedOrders.loading) && /*#__PURE__*/_react.default.createElement(_Shared.SpinnerLoader, {
|
|
183
212
|
primary: true
|
|
184
213
|
}), /*#__PURE__*/_react.default.createElement(_styles.WrapperMap, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ordering-ui-admin-external",
|
|
3
|
-
"version": "1.45.
|
|
3
|
+
"version": "1.45.43",
|
|
4
4
|
"description": "Ordering UI Admin Components",
|
|
5
5
|
"main": "./_modules/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"lodash": "^4.17.20",
|
|
84
84
|
"moment": "^2.29.1",
|
|
85
85
|
"moment-range": "^4.0.2",
|
|
86
|
-
"ordering-components-admin-external": "^1.43.
|
|
86
|
+
"ordering-components-admin-external": "^1.43.83",
|
|
87
87
|
"polished": "^3.6.7",
|
|
88
88
|
"prop-types": "^15.7.2",
|
|
89
89
|
"react-big-calendar": "^1.4.2",
|
|
@@ -35,8 +35,10 @@ export const DriversLocation = (props) => {
|
|
|
35
35
|
const [mapZoom, setMapZoom] = useState(defaultZoom)
|
|
36
36
|
const [mapLoaded, setMapLoaded] = useState(true)
|
|
37
37
|
const [mapFitted, setMapFitted] = useState(false)
|
|
38
|
+
const [hasManualView, setHasManualView] = useState(false)
|
|
38
39
|
|
|
39
40
|
const mapRef = useRef(null)
|
|
41
|
+
const isProgrammaticChangeRef = useRef(false)
|
|
40
42
|
|
|
41
43
|
const [showDrivers, setShowDrivers] = useState([])
|
|
42
44
|
|
|
@@ -45,6 +47,7 @@ export const DriversLocation = (props) => {
|
|
|
45
47
|
|
|
46
48
|
if (!selectedOrder) {
|
|
47
49
|
if (showDrivers.length === 1 && !selectedOrder && !assignedOrders?.orders?.length) {
|
|
50
|
+
isProgrammaticChangeRef.current = true
|
|
48
51
|
setMapCenter(
|
|
49
52
|
(showDrivers[0].location !== null && typeof showDrivers[0].location === 'object' && showDrivers[0].location?.lat && showDrivers[0].location?.lng)
|
|
50
53
|
? showDrivers[0].location
|
|
@@ -56,6 +59,10 @@ export const DriversLocation = (props) => {
|
|
|
56
59
|
: defaultCenter
|
|
57
60
|
)
|
|
58
61
|
setMapZoom(mapZoom)
|
|
62
|
+
setMapFitted(true)
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
isProgrammaticChangeRef.current = false
|
|
65
|
+
}, 0)
|
|
59
66
|
return
|
|
60
67
|
}
|
|
61
68
|
|
|
@@ -104,22 +111,27 @@ export const DriversLocation = (props) => {
|
|
|
104
111
|
|
|
105
112
|
const newBounds = {
|
|
106
113
|
ne: {
|
|
107
|
-
lat: bounds.getNorthEast()
|
|
108
|
-
lng: bounds.getNorthEast()
|
|
114
|
+
lat: bounds.getNorthEast()?.lat?.(),
|
|
115
|
+
lng: bounds.getNorthEast()?.lng?.()
|
|
109
116
|
},
|
|
110
117
|
sw: {
|
|
111
|
-
lat: bounds.getSouthWest()
|
|
112
|
-
lng: bounds.getSouthWest()
|
|
118
|
+
lat: bounds.getSouthWest()?.lat?.(),
|
|
119
|
+
lng: bounds.getSouthWest()?.lng?.()
|
|
113
120
|
}
|
|
114
121
|
}
|
|
122
|
+
|
|
115
123
|
const mapSize = {
|
|
116
124
|
width: mapRef.current.clientWidth,
|
|
117
125
|
height: mapRef.current.clientHeight
|
|
118
126
|
}
|
|
119
127
|
const { center, zoom } = fitBounds(newBounds, mapSize)
|
|
128
|
+
isProgrammaticChangeRef.current = true
|
|
120
129
|
setMapZoom(zoom)
|
|
121
130
|
setMapCenter(center)
|
|
122
131
|
setMapFitted(true)
|
|
132
|
+
setTimeout(() => {
|
|
133
|
+
isProgrammaticChangeRef.current = false
|
|
134
|
+
}, 0)
|
|
123
135
|
}
|
|
124
136
|
|
|
125
137
|
// Fit bounds on mount, and when the markers change
|
|
@@ -129,8 +141,10 @@ export const DriversLocation = (props) => {
|
|
|
129
141
|
setMapZoom(defaultZoom)
|
|
130
142
|
setMapCenter(defaultCenter)
|
|
131
143
|
setMapFitted(false)
|
|
144
|
+
setHasManualView(false)
|
|
132
145
|
return
|
|
133
146
|
}
|
|
147
|
+
if (hasManualView) return
|
|
134
148
|
if ((selectedOrder && selectedDriver) || (selectedDriver && assignedOrders?.orders?.length) || (!selectedOrder && !selectedDriver)) {
|
|
135
149
|
mapFit()
|
|
136
150
|
return
|
|
@@ -138,7 +152,7 @@ export const DriversLocation = (props) => {
|
|
|
138
152
|
if (!mapFitted) {
|
|
139
153
|
mapFit()
|
|
140
154
|
}
|
|
141
|
-
}, [JSON.stringify(showDrivers), mapLoaded, mapFitted, selectedOrder, assignedOrders?.orders])
|
|
155
|
+
}, [JSON.stringify(showDrivers), mapLoaded, mapFitted, selectedOrder, assignedOrders?.orders, hasManualView])
|
|
142
156
|
|
|
143
157
|
useEffect(() => {
|
|
144
158
|
if (selectedDriver) {
|
|
@@ -153,13 +167,23 @@ export const DriversLocation = (props) => {
|
|
|
153
167
|
}, [onlineDrivers, offlineDrivers, driversIsOnline, selectedDriver])
|
|
154
168
|
|
|
155
169
|
const handleMapChange = (data) => {
|
|
170
|
+
if (isProgrammaticChangeRef.current) return
|
|
171
|
+
setHasManualView(true)
|
|
156
172
|
setMapZoom(data?.zoom)
|
|
173
|
+
if (data?.center?.lat && data?.center?.lng) {
|
|
174
|
+
setMapCenter({ lat: data.center.lat, lng: data.center.lng })
|
|
175
|
+
}
|
|
157
176
|
}
|
|
158
177
|
|
|
159
178
|
useEffect(() => {
|
|
160
179
|
setMapFitted(false)
|
|
161
180
|
}, [selectedOrder])
|
|
162
181
|
|
|
182
|
+
useEffect(() => {
|
|
183
|
+
setHasManualView(false)
|
|
184
|
+
setMapFitted(false)
|
|
185
|
+
}, [selectedOrder, selectedDriver, driversIsOnline])
|
|
186
|
+
|
|
163
187
|
return (
|
|
164
188
|
<>
|
|
165
189
|
{selectedDriver && assignedOrders?.loading && (
|