@reltio/components 1.4.2006 → 1.4.2007
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/MapChart/components/Legend/styles.d.ts +1 -1
- package/ProfileResizablePanes/styles.d.ts +1 -1
- package/ReltioMap/ReltioMap.d.ts +15 -11
- package/ReltioMap/ReltioMap.js +49 -39
- package/ReltioMap/ReltioMap.spec.js +232 -116
- package/ReltioMap/components/ClusteredMarkers/ClusteredMarkers.d.ts +11 -0
- package/ReltioMap/components/ClusteredMarkers/ClusteredMarkers.js +58 -0
- package/ReltioMap/components/ClusteredMarkers/CustomClusterRenderer.d.ts +8 -0
- package/ReltioMap/components/ClusteredMarkers/CustomClusterRenderer.js +18 -0
- package/ReltioMap/components/ClusteredMarkers/index.d.ts +1 -0
- package/ReltioMap/components/ClusteredMarkers/index.js +1 -0
- package/ReltioMap/components/DrawingManager/DrawingManager.d.ts +2 -0
- package/ReltioMap/components/DrawingManager/DrawingManager.js +5 -0
- package/ReltioMap/components/DrawingManager/index.d.ts +1 -0
- package/ReltioMap/components/DrawingManager/index.js +1 -0
- package/ReltioMap/components/DrawingManager/useDrawingManager.d.ts +7 -0
- package/ReltioMap/components/DrawingManager/useDrawingManager.js +36 -0
- package/ReltioMap/components/EntityMarker/EntityMarker.d.ts +8 -7
- package/ReltioMap/components/EntityMarker/EntityMarker.js +23 -23
- package/ReltioMap/components/EntityMarker/EntityMarker.spec.js +151 -66
- package/ReltioMap/components/Polygon/Polygon.d.ts +7 -0
- package/ReltioMap/components/Polygon/Polygon.js +8 -0
- package/ReltioMap/components/Polygon/index.d.ts +1 -0
- package/ReltioMap/components/Polygon/index.js +1 -0
- package/ReltioMap/components/Polygon/usePolygon.d.ts +10 -0
- package/ReltioMap/components/Polygon/usePolygon.js +35 -0
- package/ReltioMap/components/TopCenterMapControls/TopCenterMapControls.d.ts +2 -1
- package/ReltioMap/components/TopCenterMapControls/TopCenterMapControls.js +6 -5
- package/ReltioMap/components/TopRightMapControls/TopRightMapControls.d.ts +2 -1
- package/ReltioMap/components/TopRightMapControls/TopRightMapControls.js +3 -2
- package/ReltioMap/components/TopRightMapControls/styles.js +1 -1
- package/ReltioMap/helpers.d.ts +3 -2
- package/ReltioMap/types.d.ts +6 -3
- package/cjs/MapChart/components/Legend/styles.d.ts +1 -1
- package/cjs/ProfileResizablePanes/styles.d.ts +1 -1
- package/cjs/ReltioMap/ReltioMap.d.ts +15 -11
- package/cjs/ReltioMap/ReltioMap.js +48 -38
- package/cjs/ReltioMap/ReltioMap.spec.js +230 -114
- package/cjs/ReltioMap/components/ClusteredMarkers/ClusteredMarkers.d.ts +11 -0
- package/cjs/ReltioMap/components/ClusteredMarkers/ClusteredMarkers.js +84 -0
- package/cjs/ReltioMap/components/ClusteredMarkers/CustomClusterRenderer.d.ts +8 -0
- package/cjs/ReltioMap/components/ClusteredMarkers/CustomClusterRenderer.js +21 -0
- package/cjs/ReltioMap/components/ClusteredMarkers/index.d.ts +1 -0
- package/cjs/ReltioMap/components/ClusteredMarkers/index.js +5 -0
- package/cjs/ReltioMap/components/DrawingManager/DrawingManager.d.ts +2 -0
- package/cjs/ReltioMap/components/DrawingManager/DrawingManager.js +9 -0
- package/cjs/ReltioMap/components/DrawingManager/index.d.ts +1 -0
- package/cjs/ReltioMap/components/DrawingManager/index.js +5 -0
- package/cjs/ReltioMap/components/DrawingManager/useDrawingManager.d.ts +7 -0
- package/cjs/ReltioMap/components/DrawingManager/useDrawingManager.js +40 -0
- package/cjs/ReltioMap/components/EntityMarker/EntityMarker.d.ts +8 -7
- package/cjs/ReltioMap/components/EntityMarker/EntityMarker.js +22 -22
- package/cjs/ReltioMap/components/EntityMarker/EntityMarker.spec.js +151 -66
- package/cjs/ReltioMap/components/Polygon/Polygon.d.ts +7 -0
- package/cjs/ReltioMap/components/Polygon/Polygon.js +11 -0
- package/cjs/ReltioMap/components/Polygon/index.d.ts +1 -0
- package/cjs/ReltioMap/components/Polygon/index.js +5 -0
- package/cjs/ReltioMap/components/Polygon/usePolygon.d.ts +10 -0
- package/cjs/ReltioMap/components/Polygon/usePolygon.js +39 -0
- package/cjs/ReltioMap/components/TopCenterMapControls/TopCenterMapControls.d.ts +2 -1
- package/cjs/ReltioMap/components/TopCenterMapControls/TopCenterMapControls.js +6 -5
- package/cjs/ReltioMap/components/TopRightMapControls/TopRightMapControls.d.ts +2 -1
- package/cjs/ReltioMap/components/TopRightMapControls/TopRightMapControls.js +3 -2
- package/cjs/ReltioMap/components/TopRightMapControls/styles.js +1 -1
- package/cjs/ReltioMap/helpers.d.ts +3 -2
- package/cjs/ReltioMap/types.d.ts +6 -3
- package/cjs/hooks/useMarkers/referenceHelpers.js +25 -2
- package/cjs/hooks/useMarkers/referenceHelpers.test.js +10 -1
- package/hooks/useMarkers/referenceHelpers.js +25 -2
- package/hooks/useMarkers/referenceHelpers.test.js +10 -1
- package/package.json +3 -2
|
@@ -45,27 +45,34 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
45
45
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
49
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
50
|
+
if (ar || !(i in from)) {
|
|
51
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
52
|
+
ar[i] = from[i];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
56
|
+
};
|
|
48
57
|
import React from 'react';
|
|
49
|
-
import { act, render, screen } from '@testing-library/react';
|
|
58
|
+
import { act, render, screen, waitFor } from '@testing-library/react';
|
|
50
59
|
import userEvent from '@testing-library/user-event';
|
|
51
60
|
import { findLast, last } from 'ramda';
|
|
52
|
-
import { OverlayView, initialize, mockInstances,
|
|
53
|
-
import { useJsApiLoader } from '@react-google-maps/api';
|
|
61
|
+
import { OverlayView, initialize, mockInstances, AdvancedMarkerElement, Map, Polygon } from '@googlemaps/jest-mocks';
|
|
54
62
|
import { MAP_DRAWING_MODES } from '../constants';
|
|
55
63
|
import * as helpers from './helpers';
|
|
56
64
|
import { ReltioMap } from './ReltioMap';
|
|
57
|
-
jest.mock('@react-google-maps
|
|
58
|
-
jest.mock('./components/MapControlContainer', function () { return ({
|
|
59
|
-
MapControlContainer: function (_a) {
|
|
65
|
+
jest.mock('@vis.gl/react-google-maps', function () { return (__assign(__assign({}, jest.requireActual('@vis.gl/react-google-maps')), { MapControl: function (_a) {
|
|
60
66
|
var children = _a.children;
|
|
61
67
|
return React.createElement(React.Fragment, null, children);
|
|
62
|
-
}
|
|
63
|
-
}); });
|
|
68
|
+
} })); });
|
|
64
69
|
describe('ReltioMap tests', function () {
|
|
65
70
|
var defaultProps = {
|
|
66
71
|
onOverlayUpdated: jest.fn(),
|
|
67
72
|
onMarkerClicked: jest.fn(),
|
|
68
73
|
isSearchEnabled: true,
|
|
74
|
+
defaultZoom: 10,
|
|
75
|
+
defaultCenter: { lat: 1, lng: 1 },
|
|
69
76
|
mapKey: 'mapKey',
|
|
70
77
|
loadingElement: React.createElement("div", null, "loading element")
|
|
71
78
|
};
|
|
@@ -75,15 +82,30 @@ describe('ReltioMap tests', function () {
|
|
|
75
82
|
return __assign(__assign({}, render(React.createElement(ReltioMap, __assign({}, props)))), { user: user });
|
|
76
83
|
};
|
|
77
84
|
var drawingManagerInstance;
|
|
85
|
+
var drawingManagerConstructorSpy = jest.fn();
|
|
78
86
|
beforeAll(function () {
|
|
79
87
|
initialize();
|
|
88
|
+
var OriginalMap = google.maps.Map;
|
|
89
|
+
jest.spyOn(google.maps, 'Map').mockImplementation(function () {
|
|
90
|
+
var args = [];
|
|
91
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
92
|
+
args[_i] = arguments[_i];
|
|
93
|
+
}
|
|
94
|
+
return new (OriginalMap.bind.apply(OriginalMap, __spreadArray([void 0], args, false)))();
|
|
95
|
+
});
|
|
80
96
|
global.google.maps.drawing.DrawingManager = /** @class */ (function () {
|
|
81
97
|
function DrawingManager() {
|
|
98
|
+
var args = [];
|
|
99
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
100
|
+
args[_i] = arguments[_i];
|
|
101
|
+
}
|
|
102
|
+
this.addListener = jest.fn();
|
|
82
103
|
this.getDrawingMode = jest.fn();
|
|
83
104
|
this.getMap = jest.fn();
|
|
84
105
|
this.setDrawingMode = jest.fn();
|
|
85
106
|
this.setMap = jest.fn();
|
|
86
107
|
this.setOptions = jest.fn();
|
|
108
|
+
drawingManagerConstructorSpy.apply(void 0, args);
|
|
87
109
|
drawingManagerInstance = this;
|
|
88
110
|
}
|
|
89
111
|
return DrawingManager;
|
|
@@ -104,71 +126,101 @@ describe('ReltioMap tests', function () {
|
|
|
104
126
|
});
|
|
105
127
|
beforeEach(function () {
|
|
106
128
|
drawingManagerInstance = null;
|
|
107
|
-
useJsApiLoader.mockReturnValue({ isLoaded: true, loadError: null });
|
|
108
129
|
});
|
|
109
130
|
afterEach(function () {
|
|
110
131
|
jest.clearAllMocks();
|
|
111
132
|
mockInstances.clearAll();
|
|
112
133
|
});
|
|
113
134
|
var getEventHandler = function (target, event) {
|
|
114
|
-
|
|
135
|
+
var _a, _b;
|
|
136
|
+
return ((_a = findLast(function (_a) {
|
|
115
137
|
var instance = _a[0], googleEventName = _a[1];
|
|
116
138
|
return instance === target && googleEventName === event;
|
|
117
|
-
}, global.google.maps.event.addListener.mock.calls)[2]
|
|
139
|
+
}, global.google.maps.event.addListener.mock.calls)) === null || _a === void 0 ? void 0 : _a[2]) || ((_b = findLast(function (_a) {
|
|
140
|
+
var name = _a[0];
|
|
141
|
+
return name === event;
|
|
142
|
+
}, target.addListener.mock.calls)) === null || _b === void 0 ? void 0 : _b[1]);
|
|
118
143
|
};
|
|
119
144
|
var getLastInstance = function (instance) { return last(mockInstances.get(instance)); };
|
|
120
145
|
describe('general behaviour', function () {
|
|
121
146
|
it('should render map controls', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
147
|
+
var _a;
|
|
148
|
+
return __generator(this, function (_b) {
|
|
149
|
+
switch (_b.label) {
|
|
150
|
+
case 0:
|
|
151
|
+
setUpRTL(__assign(__assign({}, defaultProps), { drawingModes: [MAP_DRAWING_MODES.POLYGON] }));
|
|
152
|
+
_a = expect;
|
|
153
|
+
return [4 /*yield*/, screen.findByLabelText('Draw area')];
|
|
154
|
+
case 1:
|
|
155
|
+
_a.apply(void 0, [_b.sent()]).toBeInTheDocument();
|
|
156
|
+
expect(screen.getByText('Search as I move the map')).toBeInTheDocument();
|
|
157
|
+
return [2 /*return*/];
|
|
158
|
+
}
|
|
127
159
|
});
|
|
128
160
|
}); });
|
|
129
161
|
it('should combine mapOptions', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
130
|
-
var mapOptions
|
|
162
|
+
var mapOptions;
|
|
131
163
|
return __generator(this, function (_a) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
164
|
+
switch (_a.label) {
|
|
165
|
+
case 0:
|
|
166
|
+
mapOptions = { mapTypeControl: true };
|
|
167
|
+
setUpRTL(__assign(__assign({}, defaultProps), { drawingModes: [MAP_DRAWING_MODES.POLYGON], mapOptions: mapOptions }));
|
|
168
|
+
return [4 /*yield*/, waitFor(function () {
|
|
169
|
+
expect(google.maps.Map).toHaveBeenCalledWith(expect.any(HTMLElement), expect.objectContaining({
|
|
170
|
+
fullscreenControl: false,
|
|
171
|
+
mapTypeControl: true,
|
|
172
|
+
streetViewControl: false
|
|
173
|
+
}));
|
|
174
|
+
})];
|
|
175
|
+
case 1:
|
|
176
|
+
_a.sent();
|
|
177
|
+
return [2 /*return*/];
|
|
178
|
+
}
|
|
141
179
|
});
|
|
142
180
|
}); });
|
|
143
|
-
it('should not render map controls', function () {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
label: 'testMarker'
|
|
181
|
+
it('should not render map controls', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
182
|
+
return __generator(this, function (_a) {
|
|
183
|
+
switch (_a.label) {
|
|
184
|
+
case 0:
|
|
185
|
+
setUpRTL(__assign(__assign({}, defaultProps), { drawingModes: [MAP_DRAWING_MODES.POLYGON], isSearchEnabled: false }));
|
|
186
|
+
return [4 /*yield*/, waitFor(function () {
|
|
187
|
+
expect(screen.queryByLabelText('Draw area')).not.toBeInTheDocument();
|
|
188
|
+
})];
|
|
189
|
+
case 1:
|
|
190
|
+
_a.sent();
|
|
191
|
+
expect(screen.queryByText('Search as I move the map')).not.toBeInTheDocument();
|
|
192
|
+
return [2 /*return*/];
|
|
156
193
|
}
|
|
157
|
-
];
|
|
158
|
-
var onMarkerClick = jest.fn();
|
|
159
|
-
setUpRTL(__assign(__assign({}, defaultProps), { drawingModes: [MAP_DRAWING_MODES.POLYGON], onMarkerClicked: onMarkerClick, markers: markers }));
|
|
160
|
-
var markerMock = getLastInstance(Marker);
|
|
161
|
-
getEventHandler(markerMock, 'click')();
|
|
162
|
-
expect(markerMock.setIcon).toHaveBeenCalled();
|
|
163
|
-
expect(onMarkerClick).toHaveBeenCalled();
|
|
164
|
-
});
|
|
165
|
-
it('should call useJsApiLoader with right params', function () {
|
|
166
|
-
setUpRTL(__assign({}, defaultProps));
|
|
167
|
-
expect(useJsApiLoader).toHaveBeenCalledWith({
|
|
168
|
-
googleMapsApiKey: 'mapKey',
|
|
169
|
-
libraries: ['drawing']
|
|
170
194
|
});
|
|
171
|
-
});
|
|
195
|
+
}); });
|
|
196
|
+
it('should render markers correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
197
|
+
var markers, onMarkerClick, markerMock;
|
|
198
|
+
return __generator(this, function (_a) {
|
|
199
|
+
switch (_a.label) {
|
|
200
|
+
case 0:
|
|
201
|
+
markers = [
|
|
202
|
+
{
|
|
203
|
+
point: { lat: 1, lng: 1 },
|
|
204
|
+
visible: true,
|
|
205
|
+
id: '123',
|
|
206
|
+
entity: { uri: 'testUri', type: 'testType' },
|
|
207
|
+
label: 'testMarker'
|
|
208
|
+
}
|
|
209
|
+
];
|
|
210
|
+
onMarkerClick = jest.fn();
|
|
211
|
+
setUpRTL(__assign(__assign({}, defaultProps), { drawingModes: [MAP_DRAWING_MODES.POLYGON], onMarkerClicked: onMarkerClick, markers: markers }));
|
|
212
|
+
return [4 /*yield*/, waitFor(function () {
|
|
213
|
+
markerMock = getLastInstance(AdvancedMarkerElement);
|
|
214
|
+
expect(markerMock).toBeDefined();
|
|
215
|
+
})];
|
|
216
|
+
case 1:
|
|
217
|
+
_a.sent();
|
|
218
|
+
getEventHandler(markerMock, 'click')();
|
|
219
|
+
expect(onMarkerClick).toHaveBeenCalled();
|
|
220
|
+
return [2 /*return*/];
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}); });
|
|
172
224
|
});
|
|
173
225
|
describe('fitting bounds behavior', function () {
|
|
174
226
|
it('should fit map bounds correctly if markers loaded later than map', function () {
|
|
@@ -337,7 +389,7 @@ describe('ReltioMap tests', function () {
|
|
|
337
389
|
};
|
|
338
390
|
_a = setUpRTL(__assign(__assign({}, defaultProps), { drawingModes: [MAP_DRAWING_MODES.POLYGON], activeOverlay: activeOverlay })), user = _a.user, rerender = _a.rerender;
|
|
339
391
|
polygon = getLastInstance(Polygon);
|
|
340
|
-
expect(polygon.
|
|
392
|
+
expect(polygon.setOptions).toHaveBeenCalledWith(expect.objectContaining({ paths: activeOverlay.path }));
|
|
341
393
|
newProps = __assign(__assign({}, defaultProps), { drawingModes: [MAP_DRAWING_MODES.POLYGON], activeOverlay: null });
|
|
342
394
|
rerender(React.createElement(ReltioMap, __assign({}, newProps)));
|
|
343
395
|
return [4 /*yield*/, user.click(screen.getByLabelText('Draw area'))];
|
|
@@ -348,56 +400,100 @@ describe('ReltioMap tests', function () {
|
|
|
348
400
|
}
|
|
349
401
|
});
|
|
350
402
|
}); });
|
|
351
|
-
it('should not render Polygon if "activeOverlay" prop is circle', function () {
|
|
352
|
-
var activeOverlay
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
setUpRTL(__assign(__assign({}, defaultProps), { drawingModes: [MAP_DRAWING_MODES.POLYGON], activeOverlay: activeOverlay, onOverlayUpdated: onOverlayUpdated }));
|
|
369
|
-
var polygon = getLastInstance(Polygon);
|
|
370
|
-
getEventHandler(polygon, 'mouseup')();
|
|
371
|
-
expect(onOverlayUpdated).toHaveBeenCalledWith({
|
|
372
|
-
type: MAP_DRAWING_MODES.POLYGON,
|
|
373
|
-
data: []
|
|
403
|
+
it('should not render Polygon if "activeOverlay" prop is circle', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
404
|
+
var activeOverlay;
|
|
405
|
+
return __generator(this, function (_a) {
|
|
406
|
+
switch (_a.label) {
|
|
407
|
+
case 0:
|
|
408
|
+
activeOverlay = {
|
|
409
|
+
type: MAP_DRAWING_MODES.CIRCLE,
|
|
410
|
+
path: [{ lat: 1, lng: 1 }]
|
|
411
|
+
};
|
|
412
|
+
setUpRTL(__assign(__assign({}, defaultProps), { drawingModes: [MAP_DRAWING_MODES.POLYGON], activeOverlay: activeOverlay }));
|
|
413
|
+
return [4 /*yield*/, waitFor(function () {
|
|
414
|
+
expect(mockInstances.get(Polygon)).toHaveLength(0);
|
|
415
|
+
})];
|
|
416
|
+
case 1:
|
|
417
|
+
_a.sent();
|
|
418
|
+
return [2 /*return*/];
|
|
419
|
+
}
|
|
374
420
|
});
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
421
|
+
}); });
|
|
422
|
+
it('should call props.onOverlayUpdated on polygon mouse up', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
423
|
+
var activeOverlay, onOverlayUpdated, polygon;
|
|
424
|
+
return __generator(this, function (_a) {
|
|
425
|
+
switch (_a.label) {
|
|
426
|
+
case 0:
|
|
427
|
+
activeOverlay = {
|
|
428
|
+
type: MAP_DRAWING_MODES.POLYGON,
|
|
429
|
+
path: [
|
|
430
|
+
{ lat: 1, lng: 1 },
|
|
431
|
+
{ lat: 2, lng: 2 }
|
|
432
|
+
]
|
|
433
|
+
};
|
|
434
|
+
onOverlayUpdated = jest.fn();
|
|
435
|
+
setUpRTL(__assign(__assign({}, defaultProps), { drawingModes: [MAP_DRAWING_MODES.POLYGON], activeOverlay: activeOverlay, onOverlayUpdated: onOverlayUpdated }));
|
|
436
|
+
polygon = getLastInstance(Polygon);
|
|
437
|
+
getEventHandler(polygon, 'mouseup')();
|
|
438
|
+
return [4 /*yield*/, waitFor(function () {
|
|
439
|
+
expect(onOverlayUpdated).toHaveBeenCalledWith({
|
|
440
|
+
type: MAP_DRAWING_MODES.POLYGON,
|
|
441
|
+
data: []
|
|
442
|
+
});
|
|
443
|
+
})];
|
|
444
|
+
case 1:
|
|
445
|
+
_a.sent();
|
|
446
|
+
expect(polygon.setOptions).toHaveBeenCalledWith(expect.objectContaining({ paths: activeOverlay.path }));
|
|
447
|
+
return [2 /*return*/];
|
|
448
|
+
}
|
|
392
449
|
});
|
|
393
|
-
|
|
394
|
-
|
|
450
|
+
}); });
|
|
451
|
+
it('should call props.onOverlayUpdated on polygon drag end', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
452
|
+
var activeOverlay, onOverlayUpdated, polygon;
|
|
453
|
+
return __generator(this, function (_a) {
|
|
454
|
+
switch (_a.label) {
|
|
455
|
+
case 0:
|
|
456
|
+
activeOverlay = {
|
|
457
|
+
type: MAP_DRAWING_MODES.POLYGON,
|
|
458
|
+
path: [
|
|
459
|
+
{ lat: 1, lng: 1 },
|
|
460
|
+
{ lat: 2, lng: 2 }
|
|
461
|
+
]
|
|
462
|
+
};
|
|
463
|
+
onOverlayUpdated = jest.fn();
|
|
464
|
+
setUpRTL(__assign(__assign({}, defaultProps), { drawingModes: [MAP_DRAWING_MODES.POLYGON], activeOverlay: activeOverlay, onOverlayUpdated: onOverlayUpdated }));
|
|
465
|
+
polygon = getLastInstance(Polygon);
|
|
466
|
+
getEventHandler(polygon, 'dragend')();
|
|
467
|
+
return [4 /*yield*/, waitFor(function () {
|
|
468
|
+
expect(onOverlayUpdated).toHaveBeenCalledWith({
|
|
469
|
+
type: MAP_DRAWING_MODES.POLYGON,
|
|
470
|
+
data: []
|
|
471
|
+
});
|
|
472
|
+
})];
|
|
473
|
+
case 1:
|
|
474
|
+
_a.sent();
|
|
475
|
+
expect(polygon.setOptions).toHaveBeenCalledWith(expect.objectContaining({ paths: activeOverlay.path }));
|
|
476
|
+
return [2 /*return*/];
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
}); });
|
|
395
480
|
});
|
|
396
481
|
describe('drawing behavior', function () {
|
|
397
|
-
it("shouldn't be in drawing mode by default", function () {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
482
|
+
it("shouldn't be in drawing mode by default", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
483
|
+
return __generator(this, function (_a) {
|
|
484
|
+
switch (_a.label) {
|
|
485
|
+
case 0:
|
|
486
|
+
setUpRTL(__assign(__assign({}, defaultProps), { drawingModes: [MAP_DRAWING_MODES.CIRCLE] }));
|
|
487
|
+
return [4 /*yield*/, waitFor(function () {
|
|
488
|
+
expect(drawingManagerInstance).not.toBe(null);
|
|
489
|
+
})];
|
|
490
|
+
case 1:
|
|
491
|
+
_a.sent();
|
|
492
|
+
expect(drawingManagerInstance.setDrawingMode).not.toHaveBeenCalledWith(MAP_DRAWING_MODES.CIRCLE);
|
|
493
|
+
return [2 /*return*/];
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
}); });
|
|
401
497
|
it('should change drawing mode on map control action', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
402
498
|
var user;
|
|
403
499
|
return __generator(this, function (_a) {
|
|
@@ -407,20 +503,40 @@ describe('ReltioMap tests', function () {
|
|
|
407
503
|
return [4 /*yield*/, user.click(screen.getByLabelText('Draw area'))];
|
|
408
504
|
case 1:
|
|
409
505
|
_a.sent();
|
|
410
|
-
expect(
|
|
506
|
+
expect(drawingManagerConstructorSpy).toHaveBeenCalledWith(expect.objectContaining({ drawingMode: MAP_DRAWING_MODES.CIRCLE }));
|
|
507
|
+
return [2 /*return*/];
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
}); });
|
|
511
|
+
it("shouldn't render DrawingManager without drawingModes prop", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
512
|
+
return __generator(this, function (_a) {
|
|
513
|
+
switch (_a.label) {
|
|
514
|
+
case 0:
|
|
515
|
+
setUpRTL(__assign({}, defaultProps));
|
|
516
|
+
return [4 /*yield*/, waitFor(function () {
|
|
517
|
+
expect(drawingManagerInstance).toBe(null);
|
|
518
|
+
})];
|
|
519
|
+
case 1:
|
|
520
|
+
_a.sent();
|
|
521
|
+
return [2 /*return*/];
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
}); });
|
|
525
|
+
it("shouldn't render TopRightMapControls without drawingModes prop", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
526
|
+
return __generator(this, function (_a) {
|
|
527
|
+
switch (_a.label) {
|
|
528
|
+
case 0:
|
|
529
|
+
setUpRTL(__assign({}, defaultProps));
|
|
530
|
+
return [4 /*yield*/, waitFor(function () {
|
|
531
|
+
expect(screen.queryByLabelText('Draw area')).not.toBeInTheDocument();
|
|
532
|
+
})];
|
|
533
|
+
case 1:
|
|
534
|
+
_a.sent();
|
|
535
|
+
expect(screen.queryByLabelText('Clear area')).not.toBeInTheDocument();
|
|
411
536
|
return [2 /*return*/];
|
|
412
537
|
}
|
|
413
538
|
});
|
|
414
539
|
}); });
|
|
415
|
-
it("shouldn't render DrawingManager without drawingModes prop", function () {
|
|
416
|
-
setUpRTL(__assign({}, defaultProps));
|
|
417
|
-
expect(drawingManagerInstance).toBe(null);
|
|
418
|
-
});
|
|
419
|
-
it("shouldn't render TopRightMapControls without drawingModes prop", function () {
|
|
420
|
-
setUpRTL(__assign({}, defaultProps));
|
|
421
|
-
expect(screen.queryByLabelText('Draw area')).not.toBeInTheDocument();
|
|
422
|
-
expect(screen.queryByLabelText('Clear area')).not.toBeInTheDocument();
|
|
423
|
-
});
|
|
424
540
|
it('should call props.onOverlayUpdated after polygon completing', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
425
541
|
var onOverlayUpdated, user, overlay;
|
|
426
542
|
return __generator(this, function (_a) {
|
|
@@ -431,7 +547,7 @@ describe('ReltioMap tests', function () {
|
|
|
431
547
|
return [4 /*yield*/, user.click(screen.getByLabelText('Draw area'))];
|
|
432
548
|
case 1:
|
|
433
549
|
_a.sent();
|
|
434
|
-
expect(
|
|
550
|
+
expect(drawingManagerConstructorSpy).toHaveBeenCalledWith(expect.objectContaining({ drawingMode: MAP_DRAWING_MODES.POLYGON }));
|
|
435
551
|
overlay = {
|
|
436
552
|
setMap: jest.fn(),
|
|
437
553
|
getPath: function () { return ({
|
|
@@ -452,7 +568,7 @@ describe('ReltioMap tests', function () {
|
|
|
452
568
|
]
|
|
453
569
|
});
|
|
454
570
|
expect(overlay.setMap).toHaveBeenCalledWith(null);
|
|
455
|
-
expect(
|
|
571
|
+
expect(drawingManagerConstructorSpy).toHaveBeenCalledWith(expect.objectContaining({ drawingMode: null }));
|
|
456
572
|
return [2 /*return*/];
|
|
457
573
|
}
|
|
458
574
|
});
|
|
@@ -474,11 +590,11 @@ describe('ReltioMap tests', function () {
|
|
|
474
590
|
return [4 /*yield*/, user.click(screen.getByLabelText('Draw area'))];
|
|
475
591
|
case 1:
|
|
476
592
|
_a.sent();
|
|
477
|
-
expect(
|
|
593
|
+
expect(drawingManagerConstructorSpy).toHaveBeenCalledWith(expect.objectContaining({ drawingMode: MAP_DRAWING_MODES.POLYGON }));
|
|
478
594
|
return [4 /*yield*/, user.click(screen.getByText('Search as I move the map'))];
|
|
479
595
|
case 2:
|
|
480
596
|
_a.sent();
|
|
481
|
-
expect(
|
|
597
|
+
expect(drawingManagerConstructorSpy).toHaveBeenCalledWith(expect.objectContaining({ drawingMode: null }));
|
|
482
598
|
expect(onMapBoundsChanged).toHaveBeenCalledWith(mapBoundsPolygon);
|
|
483
599
|
return [2 /*return*/];
|
|
484
600
|
}
|
|
@@ -494,14 +610,14 @@ describe('ReltioMap tests', function () {
|
|
|
494
610
|
return [4 /*yield*/, user.click(screen.getByLabelText('Draw area'))];
|
|
495
611
|
case 1:
|
|
496
612
|
_a.sent();
|
|
497
|
-
expect(
|
|
613
|
+
expect(drawingManagerConstructorSpy).toHaveBeenCalledWith(expect.objectContaining({ drawingMode: MAP_DRAWING_MODES.POLYGON }));
|
|
498
614
|
return [4 /*yield*/, user.click(screen.getByText('Search as I move the map'))];
|
|
499
615
|
case 2:
|
|
500
616
|
_a.sent();
|
|
501
617
|
return [4 /*yield*/, user.click(screen.getByText('Search as I move the map'))];
|
|
502
618
|
case 3:
|
|
503
619
|
_a.sent();
|
|
504
|
-
expect(
|
|
620
|
+
expect(drawingManagerConstructorSpy).toHaveBeenCalledWith(expect.objectContaining({ drawingMode: null }));
|
|
505
621
|
expect(onMapBoundsChanged).toHaveBeenCalledWith(null);
|
|
506
622
|
return [2 /*return*/];
|
|
507
623
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { GeoPoint } from '@reltio/mdm-sdk';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ClusteredMarkersOptions } from '../../types';
|
|
4
|
+
type Props = {
|
|
5
|
+
entityMarkers: GeoPoint[];
|
|
6
|
+
enabledClustering: boolean;
|
|
7
|
+
options?: ClusteredMarkersOptions;
|
|
8
|
+
onMarkerClick?: (marker: GeoPoint) => void;
|
|
9
|
+
};
|
|
10
|
+
export declare const ClusteredMarkers: React.MemoExoticComponent<({ entityMarkers, options, enabledClustering, onMarkerClick }: Props) => React.JSX.Element>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { MarkerClusterer } from '@googlemaps/markerclusterer';
|
|
13
|
+
import { useMap } from '@vis.gl/react-google-maps';
|
|
14
|
+
import { omit, prop } from 'ramda';
|
|
15
|
+
import React, { memo, useCallback, useEffect, useMemo, useState } from 'react';
|
|
16
|
+
import { EntityMarker } from '../EntityMarker';
|
|
17
|
+
import { CustomClusterRenderer } from './CustomClusterRenderer';
|
|
18
|
+
export var ClusteredMarkers = memo(function (_a) {
|
|
19
|
+
var entityMarkers = _a.entityMarkers, options = _a.options, enabledClustering = _a.enabledClustering, onMarkerClick = _a.onMarkerClick;
|
|
20
|
+
var _b = useState({}), markers = _b[0], setMarkers = _b[1];
|
|
21
|
+
var map = useMap();
|
|
22
|
+
var clusterer = useMemo(function () {
|
|
23
|
+
if (!enabledClustering || !map)
|
|
24
|
+
return null;
|
|
25
|
+
return new MarkerClusterer({
|
|
26
|
+
map: map,
|
|
27
|
+
renderer: new CustomClusterRenderer(options),
|
|
28
|
+
algorithmOptions: { maxZoom: options === null || options === void 0 ? void 0 : options.maxZoom }
|
|
29
|
+
});
|
|
30
|
+
}, [map, options, enabledClustering]);
|
|
31
|
+
useEffect(function () {
|
|
32
|
+
return function () {
|
|
33
|
+
clusterer === null || clusterer === void 0 ? void 0 : clusterer.onRemove();
|
|
34
|
+
};
|
|
35
|
+
}, [entityMarkers]);
|
|
36
|
+
useEffect(function () {
|
|
37
|
+
if (!clusterer)
|
|
38
|
+
return;
|
|
39
|
+
clusterer.clearMarkers();
|
|
40
|
+
clusterer.addMarkers(Object.values(markers));
|
|
41
|
+
}, [clusterer, markers]);
|
|
42
|
+
var setMarkerRef = useCallback(function (marker, key) {
|
|
43
|
+
setMarkers(function (markers) {
|
|
44
|
+
var _a;
|
|
45
|
+
if (marker && !markers[key]) {
|
|
46
|
+
return __assign(__assign({}, markers), (_a = {}, _a[key] = marker, _a));
|
|
47
|
+
}
|
|
48
|
+
else if (!marker && markers[key]) {
|
|
49
|
+
return omit([key], markers);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return markers;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}, []);
|
|
56
|
+
return (React.createElement(React.Fragment, null, entityMarkers.filter(prop('point')).map(function (marker) { return (React.createElement(EntityMarker, { key: marker.id, marker: marker, clusterer: enabledClustering ? setMarkerRef : undefined, onClick: onMarkerClick })); })));
|
|
57
|
+
});
|
|
58
|
+
ClusteredMarkers.displayName = 'ClusteredMarkers';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Marker, Renderer, Cluster, ClusterStats } from '@googlemaps/markerclusterer';
|
|
2
|
+
import { ClusteredMarkersOptions } from '../../types';
|
|
3
|
+
export declare class CustomClusterRenderer implements Renderer {
|
|
4
|
+
private options;
|
|
5
|
+
private defaultRenderer;
|
|
6
|
+
constructor(options: ClusteredMarkersOptions);
|
|
7
|
+
render(cluster: Cluster, stats: ClusterStats, map: google.maps.Map): Marker;
|
|
8
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DefaultRenderer } from '@googlemaps/markerclusterer';
|
|
2
|
+
var CustomClusterRenderer = /** @class */ (function () {
|
|
3
|
+
function CustomClusterRenderer(options) {
|
|
4
|
+
this.options = options;
|
|
5
|
+
this.defaultRenderer = new DefaultRenderer();
|
|
6
|
+
}
|
|
7
|
+
CustomClusterRenderer.prototype.render = function (cluster, stats, map) {
|
|
8
|
+
var _a;
|
|
9
|
+
var element = this.defaultRenderer.render(cluster, stats, map);
|
|
10
|
+
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.calculator) && element instanceof google.maps.marker.AdvancedMarkerElement) {
|
|
11
|
+
var title = this.options.calculator(cluster.markers).title;
|
|
12
|
+
element.title = title;
|
|
13
|
+
}
|
|
14
|
+
return element;
|
|
15
|
+
};
|
|
16
|
+
return CustomClusterRenderer;
|
|
17
|
+
}());
|
|
18
|
+
export { CustomClusterRenderer };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ClusteredMarkers } from './ClusteredMarkers';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ClusteredMarkers } from './ClusteredMarkers';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DrawingManager } from './DrawingManager';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DrawingManager } from './DrawingManager';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type DrawingManagerProps = {
|
|
2
|
+
drawingMode: google.maps.drawing.OverlayType;
|
|
3
|
+
onPolygonComplete?: (polygon: google.maps.Polygon) => void;
|
|
4
|
+
onCircleComplete?: (circle: google.maps.Circle) => void;
|
|
5
|
+
options: google.maps.drawing.DrawingManagerOptions;
|
|
6
|
+
};
|
|
7
|
+
export declare const useDrawingManager: ({ drawingMode, onPolygonComplete, onCircleComplete, options }: DrawingManagerProps) => google.maps.drawing.DrawingManager;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { useMap, useMapsLibrary } from '@vis.gl/react-google-maps';
|
|
13
|
+
import { useEffect, useState } from 'react';
|
|
14
|
+
export var useDrawingManager = function (_a) {
|
|
15
|
+
var drawingMode = _a.drawingMode, onPolygonComplete = _a.onPolygonComplete, onCircleComplete = _a.onCircleComplete, options = _a.options;
|
|
16
|
+
var map = useMap();
|
|
17
|
+
var drawing = useMapsLibrary('drawing');
|
|
18
|
+
var _b = useState(null), drawingManager = _b[0], setDrawingManager = _b[1];
|
|
19
|
+
useEffect(function () {
|
|
20
|
+
if (!map || !drawing)
|
|
21
|
+
return;
|
|
22
|
+
var newDrawingManager = new drawing.DrawingManager(__assign({ map: map, drawingMode: drawingMode }, options));
|
|
23
|
+
if (onPolygonComplete) {
|
|
24
|
+
newDrawingManager.addListener('polygoncomplete', onPolygonComplete);
|
|
25
|
+
}
|
|
26
|
+
if (onCircleComplete) {
|
|
27
|
+
newDrawingManager.addListener('circlecomplete', onCircleComplete);
|
|
28
|
+
}
|
|
29
|
+
setDrawingManager(newDrawingManager);
|
|
30
|
+
return function () {
|
|
31
|
+
google.maps.event.clearInstanceListeners(newDrawingManager);
|
|
32
|
+
newDrawingManager.setMap(null);
|
|
33
|
+
};
|
|
34
|
+
}, [drawing, map, options, drawingMode, onPolygonComplete, onCircleComplete]);
|
|
35
|
+
return drawingManager;
|
|
36
|
+
};
|