@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
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import React, { ComponentProps } from 'react';
|
|
2
|
+
import { AdvancedMarker } from '@vis.gl/react-google-maps';
|
|
3
|
+
import { GeoPoint } from '@reltio/mdm-sdk';
|
|
4
4
|
type Props = {
|
|
5
|
-
marker:
|
|
6
|
-
onClick: (marker:
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
marker: GeoPoint;
|
|
6
|
+
onClick: (marker: GeoPoint) => void;
|
|
7
|
+
clusterer?: (advancedMarker: google.maps.marker.AdvancedMarkerElement | null, id: string) => void;
|
|
8
|
+
} & Omit<ComponentProps<typeof AdvancedMarker>, 'onClick' | 'position' | 'onMouseEnter' | 'onMouseLeave'>;
|
|
9
|
+
declare const _default: React.MemoExoticComponent<({ marker, onClick, clusterer, ...otherProps }: Props) => React.JSX.Element>;
|
|
9
10
|
export default _default;
|
|
@@ -20,9 +20,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
}
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
|
-
import React, { memo, useCallback, useContext, useRef,
|
|
23
|
+
import React, { memo, useCallback, useContext, useState, useRef, useMemo } from 'react';
|
|
24
24
|
import { pathEq } from 'ramda';
|
|
25
|
-
import {
|
|
25
|
+
import { AdvancedMarker } from '@vis.gl/react-google-maps';
|
|
26
26
|
import { ProfileCard } from '../../../ProfileCard';
|
|
27
27
|
import { Popper } from '../../../Popper';
|
|
28
28
|
import { debounce, svg2Url } from '@reltio/mdm-sdk';
|
|
@@ -31,39 +31,39 @@ import { MARKER } from './icons/marker.inline.svg';
|
|
|
31
31
|
import { HOVERED_MARKER } from './icons/marker-hover.inline.svg';
|
|
32
32
|
import { useStyles } from './styles';
|
|
33
33
|
var HIDE_DEBOUNCE_INTERVAL = 50;
|
|
34
|
-
var MARKER_WIDTH = 22;
|
|
35
34
|
var MARKER_HEIGHT = 32;
|
|
36
35
|
var MARKER_CARD_MARGIN = 8;
|
|
37
36
|
var hoveredMarkerIcon = svg2Url(HOVERED_MARKER);
|
|
38
37
|
var markerIcon = svg2Url(MARKER);
|
|
39
38
|
var EntityMarker = function (_a) {
|
|
40
|
-
var
|
|
39
|
+
var _b;
|
|
40
|
+
var marker = _a.marker, onClick = _a.onClick, clusterer = _a.clusterer, otherProps = __rest(_a, ["marker", "onClick", "clusterer"]);
|
|
41
41
|
var styles = useStyles();
|
|
42
|
-
var
|
|
43
|
-
var _b = useState(false), hovered = _b[0], setHovered = _b[1];
|
|
42
|
+
var _c = useState(false), hovered = _c[0], setHovered = _c[1];
|
|
44
43
|
var activeEntityUri = useContext(EntityMarkerContext).activeEntityUri;
|
|
45
44
|
var isActive = pathEq(['entity', 'uri'], activeEntityUri, marker);
|
|
46
|
-
var position = { lat: marker.point.lat, lng: marker.point.lng };
|
|
45
|
+
var position = useMemo(function () { return ({ lat: marker.point.lat, lng: marker.point.lng }); }, [marker.point]);
|
|
47
46
|
var setHoveredDebounced = useCallback(debounce(setHovered, HIDE_DEBOUNCE_INTERVAL), []);
|
|
48
47
|
var onMouseOver = useCallback(function () { return setHoveredDebounced(true); }, [setHoveredDebounced]);
|
|
49
48
|
var onMouseOut = useCallback(function () { return setHoveredDebounced(false); }, [setHoveredDebounced]);
|
|
50
49
|
var handleClick = useCallback(function () { return onClick(marker); }, [onClick, marker]);
|
|
50
|
+
var advancedMarkerRef = useRef(null);
|
|
51
|
+
var ref = useCallback(function (advancedMarker) {
|
|
52
|
+
clusterer === null || clusterer === void 0 ? void 0 : clusterer(advancedMarker, marker.id);
|
|
53
|
+
advancedMarkerRef.current = advancedMarker;
|
|
54
|
+
}, [clusterer, marker.id]);
|
|
55
|
+
var anchorEl = (_b = advancedMarkerRef.current) === null || _b === void 0 ? void 0 : _b.element;
|
|
51
56
|
return (React.createElement(React.Fragment, null,
|
|
52
|
-
React.createElement(Popper, { anchorEl:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
closeBoxURL: '',
|
|
64
|
-
enableEventPropagation: true,
|
|
65
|
-
disableAutoPan: true
|
|
66
|
-
}, position: position },
|
|
67
|
-
React.createElement("span", { ref: popperAnchor }))));
|
|
57
|
+
anchorEl && (React.createElement(Popper, { anchorEl: anchorEl, open: hovered, className: styles.popper, modal: false, placement: "top", modifiers: [
|
|
58
|
+
{
|
|
59
|
+
name: 'offset',
|
|
60
|
+
options: {
|
|
61
|
+
offset: [0, MARKER_HEIGHT + MARKER_CARD_MARGIN]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
] },
|
|
65
|
+
React.createElement(ProfileCard, { entity: marker.entity, onMouseOver: onMouseOver, onMouseOut: onMouseOut }))),
|
|
66
|
+
React.createElement(AdvancedMarker, __assign({ ref: ref, position: position, onClick: handleClick, onMouseEnter: onMouseOver, onMouseLeave: onMouseOut }, otherProps),
|
|
67
|
+
React.createElement("img", { "data-reltio-id": "marker-icon", src: hovered || isActive ? hoveredMarkerIcon : markerIcon }))));
|
|
68
68
|
};
|
|
69
69
|
export default memo(EntityMarker);
|
|
@@ -9,78 +9,163 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
12
48
|
import React from 'react';
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
16
|
-
import { Popper } from '../../../Popper';
|
|
49
|
+
import { render, screen } from '@testing-library/react';
|
|
50
|
+
import userEvent from '@testing-library/user-event';
|
|
51
|
+
import { svg2Url } from '@reltio/mdm-sdk';
|
|
17
52
|
import EntityMarker from './EntityMarker';
|
|
18
|
-
import { MARKER } from './icons/marker.inline.svg';
|
|
19
|
-
import { HOVERED_MARKER } from './icons/marker-hover.inline.svg';
|
|
20
|
-
import { setupGoogleMock } from '../../googleMock.test-data';
|
|
21
53
|
import { EntityMarkerContext } from '../../../contexts/EntityMarkerContext';
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
jest.mock('@
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
54
|
+
import { HOVERED_MARKER } from './icons/marker-hover.inline.svg';
|
|
55
|
+
import { MARKER } from './icons/marker.inline.svg';
|
|
56
|
+
import { MdmModuleProvider } from '../../../contexts/MdmModuleContext';
|
|
57
|
+
jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { debounce: jest.fn(function (fn, _delay) { return jest.requireActual('@reltio/mdm-sdk').debounce(fn, 0); }) })); });
|
|
58
|
+
jest.mock('@vis.gl/react-google-maps', function () {
|
|
59
|
+
// The only reason why all the mock stuff inlcuding 'requre' inside the jest.mock is that
|
|
60
|
+
// mocks with forwardRef doesn't work outside (in beforeEach/beforeAll)
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
62
|
+
var React = require('react');
|
|
63
|
+
var forwardRef = React.forwardRef, useRef = React.useRef, useImperativeHandle = React.useImperativeHandle;
|
|
64
|
+
// eslint-disable-next-line react/prop-types
|
|
65
|
+
var AdvancedMarker = forwardRef(function (_a, ref) {
|
|
66
|
+
var children = _a.children, onClick = _a.onClick, onMouseEnter = _a.onMouseEnter, onMouseLeave = _a.onMouseLeave;
|
|
67
|
+
var divRef = useRef(null);
|
|
68
|
+
useImperativeHandle(ref, function () { return ({
|
|
69
|
+
element: divRef.current
|
|
70
|
+
}); });
|
|
71
|
+
return (React.createElement("div", { ref: divRef, onClick: onClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave }, children));
|
|
72
|
+
});
|
|
73
|
+
AdvancedMarker.displayName = 'AdvancedMarker';
|
|
74
|
+
return __assign(__assign({}, jest.requireActual('@vis.gl/react-google-maps')), { AdvancedMarker: AdvancedMarker });
|
|
75
|
+
});
|
|
76
|
+
var hoveredMarkerIcon = svg2Url(HOVERED_MARKER);
|
|
77
|
+
var markerIcon = svg2Url(MARKER);
|
|
78
|
+
describe('EntityMarker', function () {
|
|
79
|
+
var mockMarker = {
|
|
80
|
+
id: 'someId',
|
|
81
|
+
label: 'Entity 123',
|
|
82
|
+
point: { lat: 10, lng: 20 },
|
|
83
|
+
entity: { uri: 'entities/123', label: 'Entity label 123', type: 'hcp' }
|
|
33
84
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
expect(infoBox.length).toBe(1);
|
|
50
|
-
expect(infoBox.prop('options').disableAutoPan).toBe(true);
|
|
51
|
-
expect(infoBox.prop('position')).toEqual(markerProp.point);
|
|
85
|
+
var mockOnClick = jest.fn();
|
|
86
|
+
var metadata = { entityTypes: [], relationTypes: [] };
|
|
87
|
+
var defaultProps = { marker: mockMarker, onClick: mockOnClick };
|
|
88
|
+
var setUp = function (props, contextValue) {
|
|
89
|
+
if (props === void 0) { props = defaultProps; }
|
|
90
|
+
if (contextValue === void 0) { contextValue = {}; }
|
|
91
|
+
var Providers = function (_a) {
|
|
92
|
+
var children = _a.children;
|
|
93
|
+
return (React.createElement(MdmModuleProvider, { values: { metadata: metadata } }, children));
|
|
94
|
+
};
|
|
95
|
+
return render(React.createElement(EntityMarkerContext.Provider, { value: contextValue },
|
|
96
|
+
React.createElement(EntityMarker, __assign({}, props))), { wrapper: Providers });
|
|
97
|
+
};
|
|
98
|
+
afterEach(function () {
|
|
99
|
+
jest.clearAllMocks();
|
|
52
100
|
});
|
|
53
|
-
it('should
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
rerenderWrapper(component);
|
|
59
|
-
expect(component.find(Popper).prop('open')).toBe(true);
|
|
60
|
-
expect(component.find(Marker).prop('icon')).toMatchObject({
|
|
61
|
-
url: hoveredMarkerUrl
|
|
101
|
+
it('should render correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
102
|
+
return __generator(this, function (_a) {
|
|
103
|
+
setUp();
|
|
104
|
+
expect(screen.getByTestId('marker-icon')).toHaveAttribute('src', markerIcon);
|
|
105
|
+
return [2 /*return*/];
|
|
62
106
|
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
107
|
+
}); });
|
|
108
|
+
it('should call onClick when marker is clicked', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
109
|
+
return __generator(this, function (_a) {
|
|
110
|
+
switch (_a.label) {
|
|
111
|
+
case 0:
|
|
112
|
+
setUp();
|
|
113
|
+
return [4 /*yield*/, userEvent.click(screen.getByTestId('marker-icon'))];
|
|
114
|
+
case 1:
|
|
115
|
+
_a.sent();
|
|
116
|
+
expect(mockOnClick).toHaveBeenCalledWith(mockMarker);
|
|
117
|
+
return [2 /*return*/];
|
|
118
|
+
}
|
|
68
119
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
120
|
+
}); });
|
|
121
|
+
it('should show ProfileCard on mouse enter and hide on mouse leave', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
122
|
+
var _a;
|
|
123
|
+
return __generator(this, function (_b) {
|
|
124
|
+
switch (_b.label) {
|
|
125
|
+
case 0:
|
|
126
|
+
setUp();
|
|
127
|
+
return [4 /*yield*/, userEvent.hover(screen.getByTestId('marker-icon'))];
|
|
128
|
+
case 1:
|
|
129
|
+
_b.sent();
|
|
130
|
+
_a = expect;
|
|
131
|
+
return [4 /*yield*/, screen.findByText(mockMarker.entity.label)];
|
|
132
|
+
case 2:
|
|
133
|
+
_a.apply(void 0, [_b.sent()]).toBeInTheDocument();
|
|
134
|
+
return [4 /*yield*/, userEvent.unhover(screen.getByTestId('marker-icon'))];
|
|
135
|
+
case 3:
|
|
136
|
+
_b.sent();
|
|
137
|
+
expect(screen.queryByText(mockMarker.entity.label)).not.toBeInTheDocument();
|
|
138
|
+
return [2 /*return*/];
|
|
139
|
+
}
|
|
84
140
|
});
|
|
85
|
-
});
|
|
141
|
+
}); });
|
|
142
|
+
it('should use hovered marker icon when hovered', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
143
|
+
return __generator(this, function (_a) {
|
|
144
|
+
switch (_a.label) {
|
|
145
|
+
case 0:
|
|
146
|
+
setUp();
|
|
147
|
+
return [4 /*yield*/, userEvent.hover(screen.getByTestId('marker-icon'))];
|
|
148
|
+
case 1:
|
|
149
|
+
_a.sent();
|
|
150
|
+
expect(screen.getByTestId('marker-icon')).toHaveAttribute('src', hoveredMarkerIcon);
|
|
151
|
+
return [2 /*return*/];
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}); });
|
|
155
|
+
it('should use active marker icon when marker is active', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
156
|
+
return __generator(this, function (_a) {
|
|
157
|
+
setUp(undefined, { activeEntityUri: mockMarker.entity.uri });
|
|
158
|
+
expect(screen.getByTestId('marker-icon')).toHaveAttribute('src', hoveredMarkerIcon);
|
|
159
|
+
return [2 /*return*/];
|
|
160
|
+
});
|
|
161
|
+
}); });
|
|
162
|
+
it('should call clusterer with advancedMarker and marker id', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
163
|
+
var clusterer;
|
|
164
|
+
return __generator(this, function (_a) {
|
|
165
|
+
clusterer = jest.fn();
|
|
166
|
+
setUp(__assign(__assign({}, defaultProps), { clusterer: clusterer }));
|
|
167
|
+
expect(clusterer).toHaveBeenCalledWith(expect.objectContaining({ element: expect.any(HTMLElement) }), mockMarker.id);
|
|
168
|
+
return [2 /*return*/];
|
|
169
|
+
});
|
|
170
|
+
}); });
|
|
86
171
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const Polygon: import("react").ForwardRefExoticComponent<{
|
|
2
|
+
options: google.maps.PolygonOptions;
|
|
3
|
+
} & {
|
|
4
|
+
onInit?: (polygon: google.maps.Polygon) => void;
|
|
5
|
+
onDragEnd?: (e: google.maps.MapMouseEvent) => void;
|
|
6
|
+
onMouseUp?: (e: google.maps.MapMouseEvent) => void;
|
|
7
|
+
} & import("react").RefAttributes<google.maps.Polygon>>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { forwardRef, useImperativeHandle } from 'react';
|
|
2
|
+
import { usePolygon } from './usePolygon';
|
|
3
|
+
export var Polygon = forwardRef(function (props, ref) {
|
|
4
|
+
var polygon = usePolygon(props);
|
|
5
|
+
useImperativeHandle(ref, function () { return polygon; }, []);
|
|
6
|
+
return null;
|
|
7
|
+
});
|
|
8
|
+
Polygon.displayName = 'Polygon';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Polygon } from './Polygon';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Polygon } from './Polygon';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type PolygonEventProps = {
|
|
2
|
+
onInit?: (polygon: google.maps.Polygon) => void;
|
|
3
|
+
onDragEnd?: (e: google.maps.MapMouseEvent) => void;
|
|
4
|
+
onMouseUp?: (e: google.maps.MapMouseEvent) => void;
|
|
5
|
+
};
|
|
6
|
+
export type PolygonProps = {
|
|
7
|
+
options: google.maps.PolygonOptions;
|
|
8
|
+
} & PolygonEventProps;
|
|
9
|
+
export declare const usePolygon: (props: PolygonProps) => google.maps.Polygon;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useEffect, useMemo } from 'react';
|
|
2
|
+
import { useMap } from '@vis.gl/react-google-maps';
|
|
3
|
+
export var usePolygon = function (props) {
|
|
4
|
+
var onInit = props.onInit, onDragEnd = props.onDragEnd, onMouseUp = props.onMouseUp, options = props.options;
|
|
5
|
+
var polygon = useMemo(function () { return new google.maps.Polygon(); }, []);
|
|
6
|
+
useEffect(function () {
|
|
7
|
+
polygon.setOptions(options);
|
|
8
|
+
}, [polygon, options]);
|
|
9
|
+
var map = useMap();
|
|
10
|
+
useEffect(function () {
|
|
11
|
+
if (!map)
|
|
12
|
+
return;
|
|
13
|
+
polygon.setMap(map);
|
|
14
|
+
if (onInit) {
|
|
15
|
+
onInit(polygon);
|
|
16
|
+
}
|
|
17
|
+
return function () {
|
|
18
|
+
polygon.setMap(null);
|
|
19
|
+
};
|
|
20
|
+
}, [map]);
|
|
21
|
+
useEffect(function () {
|
|
22
|
+
if (!polygon)
|
|
23
|
+
return;
|
|
24
|
+
if (onDragEnd) {
|
|
25
|
+
google.maps.event.addListener(polygon, 'dragend', onDragEnd);
|
|
26
|
+
}
|
|
27
|
+
if (onMouseUp) {
|
|
28
|
+
google.maps.event.addListener(polygon, 'mouseup', onMouseUp);
|
|
29
|
+
}
|
|
30
|
+
return function () {
|
|
31
|
+
google.maps.event.clearInstanceListeners(polygon);
|
|
32
|
+
};
|
|
33
|
+
}, [polygon, onDragEnd, onMouseUp]);
|
|
34
|
+
return polygon;
|
|
35
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
type Props = {
|
|
3
|
+
className?: string;
|
|
3
4
|
isSearchOnMapMove: boolean;
|
|
4
5
|
onChangeIsSearchOnMapMove: (value: boolean) => void;
|
|
5
6
|
};
|
|
6
|
-
export declare const TopCenterMapControls: ({ isSearchOnMapMove, onChangeIsSearchOnMapMove }: Props) => React.JSX.Element;
|
|
7
|
+
export declare const TopCenterMapControls: ({ className, isSearchOnMapMove, onChangeIsSearchOnMapMove }: Props) => React.JSX.Element;
|
|
7
8
|
export {};
|
|
@@ -4,13 +4,14 @@ import FormControlLabel from '@mui/material/FormControlLabel';
|
|
|
4
4
|
import Checkbox from '@mui/material/Checkbox';
|
|
5
5
|
import { useStyles } from './styles';
|
|
6
6
|
export var TopCenterMapControls = function (_a) {
|
|
7
|
-
var isSearchOnMapMove = _a.isSearchOnMapMove, onChangeIsSearchOnMapMove = _a.onChangeIsSearchOnMapMove;
|
|
7
|
+
var className = _a.className, isSearchOnMapMove = _a.isSearchOnMapMove, onChangeIsSearchOnMapMove = _a.onChangeIsSearchOnMapMove;
|
|
8
8
|
var styles = useStyles();
|
|
9
9
|
var onChange = function (event) {
|
|
10
10
|
onChangeIsSearchOnMapMove(event.target.checked);
|
|
11
11
|
};
|
|
12
|
-
return (React.createElement(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
return (React.createElement("div", { className: className },
|
|
13
|
+
React.createElement(FormControlLabel, { classes: {
|
|
14
|
+
root: styles.container,
|
|
15
|
+
label: styles.label
|
|
16
|
+
}, control: React.createElement(Checkbox, { checked: isSearchOnMapMove, onChange: onChange, className: styles.checkbox }), label: i18n.text('Search as I move the map') })));
|
|
16
17
|
};
|
|
@@ -38,11 +38,12 @@ export declare const ButtonWithTooltip: React.ForwardRefExoticComponent<Omit<{
|
|
|
38
38
|
ref?: React.Ref<HTMLButtonElement>;
|
|
39
39
|
}, "color" | "size" | "disabled" | "tabIndex" | "children" | "sx" | "action" | keyof import("@mui/material/OverridableComponent").CommonProps | "centerRipple" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "onFocusVisible" | "TouchRippleProps" | "touchRippleRef" | "disableFocusRipple" | "href" | "startIcon" | "disableElevation" | "endIcon" | "fullWidth" | "variant">, "ref"> & React.RefAttributes<HTMLElement>>;
|
|
40
40
|
type Props = {
|
|
41
|
+
className?: string;
|
|
41
42
|
onDrawingModeChanged: (value: DrawingMode | null) => void;
|
|
42
43
|
drawingMode: DrawingMode | null;
|
|
43
44
|
drawingModes: DrawingModes;
|
|
44
45
|
hasActiveOverlay: boolean;
|
|
45
46
|
onClearOverlay: () => void;
|
|
46
47
|
};
|
|
47
|
-
export declare const TopRightMapControls: ({ drawingMode, drawingModes, hasActiveOverlay, onDrawingModeChanged, onClearOverlay }: Props) => React.JSX.Element;
|
|
48
|
+
export declare const TopRightMapControls: ({ className, drawingMode, drawingModes, hasActiveOverlay, onDrawingModeChanged, onClearOverlay }: Props) => React.JSX.Element;
|
|
48
49
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import classnames from 'classnames';
|
|
2
3
|
import i18n from 'ui-i18n';
|
|
3
4
|
import Button from '@mui/material/Button';
|
|
4
5
|
import { withTooltip } from '../../../HOCs/withTooltip';
|
|
@@ -19,12 +20,12 @@ var getIcon = function (mode) {
|
|
|
19
20
|
}
|
|
20
21
|
};
|
|
21
22
|
export var TopRightMapControls = function (_a) {
|
|
22
|
-
var drawingMode = _a.drawingMode, _b = _a.drawingModes, drawingModes = _b === void 0 ? [] : _b, hasActiveOverlay = _a.hasActiveOverlay, onDrawingModeChanged = _a.onDrawingModeChanged, onClearOverlay = _a.onClearOverlay;
|
|
23
|
+
var className = _a.className, drawingMode = _a.drawingMode, _b = _a.drawingModes, drawingModes = _b === void 0 ? [] : _b, hasActiveOverlay = _a.hasActiveOverlay, onDrawingModeChanged = _a.onDrawingModeChanged, onClearOverlay = _a.onClearOverlay;
|
|
23
24
|
var styles = useStyles();
|
|
24
25
|
var changeDrawingModeTo = function (drawingMode) { return function () {
|
|
25
26
|
onDrawingModeChanged(drawingMode);
|
|
26
27
|
}; };
|
|
27
|
-
return (React.createElement("div", { className: styles.container }, drawingMode || hasActiveOverlay ? (React.createElement(ButtonWithTooltip, { tooltipTitle: i18n.text('Clear area'), className: styles.button, onClick: hasActiveOverlay ? onClearOverlay : changeDrawingModeTo(null) },
|
|
28
|
+
return (React.createElement("div", { className: classnames(styles.container, className) }, drawingMode || hasActiveOverlay ? (React.createElement(ButtonWithTooltip, { tooltipTitle: i18n.text('Clear area'), className: styles.button, onClick: hasActiveOverlay ? onClearOverlay : changeDrawingModeTo(null) },
|
|
28
29
|
React.createElement(HighlightOffIcon, { className: styles.icon }))) : (drawingModes.map(function (mode) {
|
|
29
30
|
var Icon = getIcon(mode);
|
|
30
31
|
return (React.createElement(ButtonWithTooltip, { tooltipTitle: i18n.text('Draw area'), key: mode, className: styles.button, onClick: changeDrawingModeTo(mode) },
|
package/ReltioMap/helpers.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GeoPoint } from '@reltio/mdm-sdk';
|
|
2
|
+
import { DrawingMode, Overlay, MapInstance } from './types';
|
|
2
3
|
export declare const getMapBoundsPolygon: (map: MapInstance) => any[];
|
|
3
4
|
export declare const getDrawingMode: (drawingMode: DrawingMode) => google.maps.drawing.OverlayType.CIRCLE | google.maps.drawing.OverlayType.POLYGON;
|
|
4
|
-
export declare const fitMapBoundsForMarkers: (markers:
|
|
5
|
+
export declare const fitMapBoundsForMarkers: (markers: GeoPoint[], map: MapInstance, overlay: Overlay) => void;
|
|
5
6
|
export declare const fitMapBoundsForOverlay: (map: MapInstance, overlay: Overlay, existingBounds?: any) => void;
|
package/ReltioMap/types.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Marker } from '@googlemaps/markerclusterer';
|
|
2
2
|
export type DrawingMode = 'circle' | 'polygon';
|
|
3
3
|
export type DrawingModes = DrawingMode[];
|
|
4
|
-
export type
|
|
5
|
-
|
|
4
|
+
export type ClusteredMarkersOptions = {
|
|
5
|
+
maxZoom?: number;
|
|
6
|
+
calculator?: (markers: Marker[]) => {
|
|
7
|
+
title: string;
|
|
8
|
+
};
|
|
6
9
|
};
|
|
7
10
|
export type OverlayPath = Array<{
|
|
8
11
|
lat: number;
|
|
@@ -2,5 +2,5 @@ type StylesProps = {
|
|
|
2
2
|
colors: string[];
|
|
3
3
|
width: number;
|
|
4
4
|
};
|
|
5
|
-
export declare const useStyles: (props: StylesProps) => import("@mui/styles").ClassNameMap<"
|
|
5
|
+
export declare const useStyles: (props: StylesProps) => import("@mui/styles").ClassNameMap<"legendContainer" | "alignTop" | "alignBottom" | "legendBar" | "legendLabel">;
|
|
6
6
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useStyles: (props?: any) => import("@mui/styles").ClassNameMap<"
|
|
1
|
+
export declare const useStyles: (props?: any) => import("@mui/styles").ClassNameMap<"resizablePanesWrapper" | "pane">;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { DrawingModes,
|
|
4
|
-
type MarkerClustererOptions = MarkerClustererProps['options'];
|
|
2
|
+
import { GeoPoint } from '@reltio/mdm-sdk';
|
|
3
|
+
import { DrawingModes, MapBounds, Overlay, ClusteredMarkersOptions, DrawingMode } from './types';
|
|
5
4
|
type Props = {
|
|
6
|
-
markers?:
|
|
5
|
+
markers?: GeoPoint[];
|
|
7
6
|
mapKey: string;
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/** A map ID is required to use Advanced Markers. https://developers.google.com/maps/documentation/javascript/advanced-markers/overview */
|
|
8
|
+
mapId?: string;
|
|
9
|
+
defaultZoom?: number;
|
|
10
|
+
defaultCenter?: google.maps.LatLngLiteral;
|
|
10
11
|
loadingElement: React.ReactElement;
|
|
11
12
|
isSearchOnMapMove?: boolean;
|
|
12
13
|
isSearchEnabled?: boolean;
|
|
@@ -14,15 +15,18 @@ type Props = {
|
|
|
14
15
|
overlayOptions?: google.maps.PolygonOptions | google.maps.CircleOptions;
|
|
15
16
|
drawingModes?: DrawingModes;
|
|
16
17
|
markerClusterer?: boolean;
|
|
17
|
-
markerClustererOptions?:
|
|
18
|
+
markerClustererOptions?: ClusteredMarkersOptions;
|
|
18
19
|
mapOptions?: google.maps.MapOptions;
|
|
19
20
|
mapContainerClassName?: string;
|
|
20
21
|
onMapBoundsChanged?: (value: MapBounds | null) => void;
|
|
21
22
|
onOverlayUpdated?: (value: {
|
|
22
|
-
data:
|
|
23
|
-
|
|
23
|
+
data: number[][] | {
|
|
24
|
+
radius: number;
|
|
25
|
+
center: google.maps.LatLng;
|
|
26
|
+
};
|
|
27
|
+
type: DrawingMode;
|
|
24
28
|
}) => void;
|
|
25
|
-
onMarkerClicked?: (value:
|
|
29
|
+
onMarkerClicked?: (value: GeoPoint) => void;
|
|
26
30
|
};
|
|
27
|
-
export declare const ReltioMap: ({
|
|
31
|
+
export declare const ReltioMap: ({ mapKey, ...restProps }: Props) => React.JSX.Element;
|
|
28
32
|
export {};
|