@eeacms/volto-bise-policy 1.2.32 → 1.2.34

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/package.json +3 -1
  3. package/src/components/Widgets/GeolocationWidget.jsx +143 -0
  4. package/src/components/Widgets/GeolocationWidgetMapContainer.jsx +131 -0
  5. package/src/components/Widgets/NRRWidgets.jsx +95 -0
  6. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyExplorerEdit.jsx +5 -0
  7. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyExplorerView.jsx +107 -0
  8. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyExplorerView.test.jsx +89 -0
  9. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyFilters.jsx +339 -0
  10. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyFilters.test.jsx +111 -0
  11. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyListing.jsx +330 -0
  12. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyListing.test.jsx +166 -0
  13. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyMap.jsx +237 -0
  14. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyMap.test.jsx +176 -0
  15. package/src/components/manage/Blocks/CaseStudyExplorer/FeatureDisplay.jsx +41 -0
  16. package/src/components/manage/Blocks/CaseStudyExplorer/FeatureDisplay.test.jsx +32 -0
  17. package/src/components/manage/Blocks/CaseStudyExplorer/FeatureInteraction.jsx +98 -0
  18. package/src/components/manage/Blocks/CaseStudyExplorer/FeatureInteraction.test.jsx +160 -0
  19. package/src/components/manage/Blocks/CaseStudyExplorer/InfoOverlay.jsx +82 -0
  20. package/src/components/manage/Blocks/CaseStudyExplorer/InfoOverlay.test.jsx +153 -0
  21. package/src/components/manage/Blocks/CaseStudyExplorer/hooks.js +20 -0
  22. package/src/components/manage/Blocks/CaseStudyExplorer/images/icon-depth.png +0 -0
  23. package/src/components/manage/Blocks/CaseStudyExplorer/images/icon-light.png +0 -0
  24. package/src/components/manage/Blocks/CaseStudyExplorer/images/search.svg +3 -0
  25. package/src/components/manage/Blocks/CaseStudyExplorer/index.js +16 -0
  26. package/src/components/manage/Blocks/CaseStudyExplorer/mockJsdom.js +8 -0
  27. package/src/components/manage/Blocks/CaseStudyExplorer/styles.less +359 -0
  28. package/src/components/manage/Blocks/CaseStudyExplorer/styles.less_old +201 -0
  29. package/src/components/manage/Blocks/CaseStudyExplorer/utils.js +144 -0
  30. package/src/components/manage/Blocks/CaseStudyExplorer/utils.test.js +88 -0
  31. package/src/components/manage/Blocks/index.js +2 -0
  32. package/src/express-middleware.js +37 -0
  33. package/src/index.js +29 -0
  34. package/theme/globals/site.overrides +12 -4
@@ -0,0 +1,160 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import FeatureInteraction from './FeatureInteraction';
4
+ import { scrollToElement, zoomMapToFeatures } from './utils';
5
+
6
+ jest.mock('@eeacms/volto-openlayers-map', () => ({
7
+ withOpenLayers: (Comp) => Comp,
8
+ }));
9
+
10
+ const addInteraction = jest.fn();
11
+ const removeInteraction = jest.fn();
12
+ const onMap = jest.fn();
13
+ const getEventPixel = jest.fn(() => [10, 20]);
14
+ const hasFeatureAtPixel = jest.fn(() => true);
15
+ const getViewport = jest.fn(() => ({ style: {} }));
16
+
17
+ jest.mock('@eeacms/volto-openlayers-map/api', () => ({
18
+ useMapContext: () => ({
19
+ map: mockMap,
20
+ }),
21
+ }));
22
+
23
+ jest.mock('./utils', () => ({
24
+ scrollToElement: jest.fn(),
25
+ zoomMapToFeatures: jest.fn(),
26
+ }));
27
+
28
+ const mockOl = {
29
+ style: {
30
+ Style: jest.fn(() => ({
31
+ image_: { getFill: () => ({ setColor: jest.fn() }) },
32
+ })),
33
+ Circle: jest.fn(() => ({})),
34
+ Fill: jest.fn(() => ({})),
35
+ Stroke: jest.fn(() => ({})),
36
+ },
37
+ interaction: {
38
+ Select: jest.fn(() => ({
39
+ on: jest.fn((evt, cb) => {
40
+ if (evt === 'select') {
41
+ mockSelectCb = cb;
42
+ }
43
+ }),
44
+ })),
45
+ },
46
+ condition: {
47
+ click: jest.fn(),
48
+ },
49
+ };
50
+
51
+ let mockSelectCb;
52
+ const mockMap = {
53
+ addInteraction,
54
+ removeInteraction,
55
+ on: onMap,
56
+ getEventPixel,
57
+ hasFeatureAtPixel,
58
+ getViewport,
59
+ };
60
+
61
+ function triggerSelectEvent(subfeatures) {
62
+ const feature = { values_: { features: subfeatures } };
63
+ const mockE = {
64
+ target: {
65
+ getFeatures: () => ({
66
+ getArray: () => [feature],
67
+ }),
68
+ },
69
+ };
70
+ mockSelectCb(mockE);
71
+ }
72
+
73
+ describe('FeatureInteraction', () => {
74
+ beforeEach(() => {
75
+ jest.clearAllMocks();
76
+ mockSelectCb = null;
77
+ });
78
+
79
+ it('selects a single feature and calls onFeatureSelect + scrollToElement (hideFilters=false)', () => {
80
+ const onFeatureSelect = jest.fn();
81
+ const singleFeature = {
82
+ values_: { path: '/path1', geometry: {}, foo: 'bar' },
83
+ };
84
+
85
+ render(
86
+ <FeatureInteraction
87
+ onFeatureSelect={onFeatureSelect}
88
+ hideFilters={false}
89
+ selectedCase={null}
90
+ ol={mockOl}
91
+ />,
92
+ );
93
+
94
+ triggerSelectEvent([singleFeature]);
95
+
96
+ expect(onFeatureSelect).toHaveBeenCalledWith(singleFeature.values_);
97
+ expect(scrollToElement).toHaveBeenCalledWith('ol-map-container');
98
+ });
99
+
100
+ it('selects a single feature and changes window.location when hideFilters=true', () => {
101
+ const onFeatureSelect = jest.fn();
102
+ const singleFeature = { values_: { path: '/go-here', geometry: {} } };
103
+ delete window.location;
104
+ window.location = { href: '' };
105
+
106
+ render(
107
+ <FeatureInteraction
108
+ onFeatureSelect={onFeatureSelect}
109
+ hideFilters={true}
110
+ selectedCase={null}
111
+ ol={mockOl}
112
+ />,
113
+ );
114
+
115
+ triggerSelectEvent([singleFeature]);
116
+
117
+ expect(window.location.href).toContain('/go-here');
118
+ });
119
+
120
+ it('selects multiple features and calls zoomMapToFeatures', () => {
121
+ const onFeatureSelect = jest.fn();
122
+ const subfeatures = [
123
+ { values_: { path: '/f1' } },
124
+ { values_: { path: '/f2' } },
125
+ ];
126
+
127
+ render(
128
+ <FeatureInteraction
129
+ onFeatureSelect={onFeatureSelect}
130
+ hideFilters={false}
131
+ selectedCase={null}
132
+ ol={mockOl}
133
+ />,
134
+ );
135
+
136
+ triggerSelectEvent(subfeatures);
137
+
138
+ expect(onFeatureSelect).toHaveBeenCalledWith(null);
139
+ expect(zoomMapToFeatures).toHaveBeenCalledWith({
140
+ map: mockMap,
141
+ features: subfeatures,
142
+ ol: mockOl,
143
+ });
144
+ });
145
+
146
+ it('adds and removes interaction on mount/unmount', () => {
147
+ const { unmount } = render(
148
+ <FeatureInteraction
149
+ onFeatureSelect={jest.fn()}
150
+ hideFilters={false}
151
+ selectedCase={null}
152
+ ol={mockOl}
153
+ />,
154
+ );
155
+
156
+ expect(addInteraction).toHaveBeenCalled();
157
+ unmount();
158
+ expect(removeInteraction).toHaveBeenCalled();
159
+ });
160
+ });
@@ -0,0 +1,82 @@
1
+ import React from 'react';
2
+ import { useMapContext } from '@eeacms/volto-openlayers-map/api';
3
+ import { withOpenLayers } from '@eeacms/volto-openlayers-map';
4
+ import FeatureDisplay from './FeatureDisplay';
5
+ import { usePrevious } from '@plone/volto/helpers/Utils/usePrevious';
6
+
7
+ function InfoOverlay({
8
+ selectedFeature,
9
+ onFeatureSelect,
10
+ layerId,
11
+ hideFilters,
12
+ ol,
13
+ }) {
14
+ const { map } = useMapContext();
15
+ const [tooltip, setTooltipRef] = React.useState();
16
+ const [showTooltip, setShowTooltip] = React.useState();
17
+
18
+ const prevLayerId = usePrevious(layerId);
19
+
20
+ React.useEffect(() => {
21
+ if (prevLayerId && layerId !== prevLayerId) {
22
+ setShowTooltip(false);
23
+ }
24
+ }, [layerId, prevLayerId]);
25
+
26
+ React.useEffect(() => {
27
+ if (!(map && tooltip)) return;
28
+
29
+ const overlay = new ol.Overlay({
30
+ element: document.getElementById('popup-overlay'),
31
+ positioning: 'bottom-center',
32
+ offset: [0, -10],
33
+ stopEvent: false,
34
+ });
35
+ map.addOverlay(overlay);
36
+
37
+ function handler(evt) {
38
+ const { pixel, target } = evt;
39
+ const features = target.getFeaturesAtPixel(pixel);
40
+ const popupOverlay = overlay.element; // document.getElementById('popup-overlay');
41
+
42
+ if (
43
+ features.length &&
44
+ !hideFilters // && !isCluster(features)
45
+ ) {
46
+ setShowTooltip(true);
47
+ } else {
48
+ // handle a click in an overlay popup
49
+ if (evt.originalEvent.target.tagName === 'A') return;
50
+ setShowTooltip(false);
51
+ popupOverlay.style.display = 'none';
52
+ onFeatureSelect(null);
53
+ }
54
+ }
55
+
56
+ map.on('click', handler);
57
+
58
+ return () => {
59
+ map.un('click', handler);
60
+ map.removeOverlay(overlay);
61
+ };
62
+ }, [map, tooltip, onFeatureSelect, hideFilters, ol]); //
63
+
64
+ const [isClient, setIsClient] = React.useState(false);
65
+ React.useEffect(() => setIsClient(true), []);
66
+
67
+ return isClient ? (
68
+ <div
69
+ id="popup-overlay"
70
+ style={{
71
+ position: 'absolute',
72
+ zIndex: 1,
73
+ visibility: showTooltip ? 'visible' : 'hidden',
74
+ }}
75
+ ref={setTooltipRef}
76
+ >
77
+ {selectedFeature ? <FeatureDisplay feature={selectedFeature} /> : null}
78
+ </div>
79
+ ) : null;
80
+ }
81
+
82
+ export default withOpenLayers(InfoOverlay);
@@ -0,0 +1,153 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import InfoOverlay from './InfoOverlay';
4
+ import '@testing-library/jest-dom';
5
+
6
+ jest.mock('@eeacms/volto-openlayers-map', () => ({
7
+ withOpenLayers: (Comp) => Comp,
8
+ }));
9
+
10
+ const onMap = jest.fn();
11
+ const unMap = jest.fn();
12
+ const addOverlay = jest.fn();
13
+ const removeOverlay = jest.fn();
14
+ jest.mock('@eeacms/volto-openlayers-map/api', () => ({
15
+ useMapContext: () => ({
16
+ map: mockMap,
17
+ }),
18
+ }));
19
+
20
+ jest.mock('./FeatureDisplay', () => () => (
21
+ <div data-testid="feature-display" />
22
+ ));
23
+
24
+ const mockAddOverlayInstance = {};
25
+ jest.mock('ol/Overlay', () => {
26
+ return jest.fn().mockImplementation((config) => {
27
+ return { ...mockAddOverlayInstance, element: config.element };
28
+ });
29
+ });
30
+
31
+ const mockOl = {
32
+ Overlay: jest.fn((config) => ({
33
+ element: config.element,
34
+ })),
35
+ };
36
+
37
+ const mockMap = {
38
+ on: onMap,
39
+ un: unMap,
40
+ addOverlay,
41
+ removeOverlay,
42
+ };
43
+
44
+ jest.mock('@plone/volto/helpers/Utils/usePrevious', () => ({
45
+ usePrevious: (val) => undefined,
46
+ }));
47
+
48
+ describe('InfoOverlay', () => {
49
+ let overlayElement;
50
+ beforeEach(() => {
51
+ jest.clearAllMocks();
52
+ overlayElement = document.createElement('div');
53
+ overlayElement.id = 'popup-overlay';
54
+ document.body.appendChild(overlayElement);
55
+ });
56
+
57
+ afterEach(() => {
58
+ document.body.innerHTML = '';
59
+ });
60
+
61
+ it('renders FeatureDisplay when selectedFeature is provided', () => {
62
+ const { getByTestId } = render(
63
+ <InfoOverlay
64
+ selectedFeature={{ id: 1 }}
65
+ onFeatureSelect={jest.fn()}
66
+ layerId="layer1"
67
+ hideFilters={false}
68
+ ol={mockOl}
69
+ />,
70
+ );
71
+ expect(getByTestId('feature-display')).toBeInTheDocument();
72
+ });
73
+
74
+ it('does not render FeatureDisplay when selectedFeature is null', () => {
75
+ const { queryByTestId } = render(
76
+ <InfoOverlay
77
+ selectedFeature={null}
78
+ onFeatureSelect={jest.fn()}
79
+ layerId="layer1"
80
+ hideFilters={false}
81
+ ol={mockOl}
82
+ />,
83
+ );
84
+ expect(queryByTestId('feature-display')).toBeNull();
85
+ });
86
+
87
+ it('attaches and detaches click handler on map', () => {
88
+ const { unmount } = render(
89
+ <InfoOverlay
90
+ selectedFeature={null}
91
+ onFeatureSelect={jest.fn()}
92
+ layerId="layer1"
93
+ hideFilters={false}
94
+ ol={mockOl}
95
+ />,
96
+ );
97
+ expect(addOverlay).toHaveBeenCalled();
98
+ expect(onMap).toHaveBeenCalledWith('click', expect.any(Function));
99
+
100
+ unmount();
101
+ expect(unMap).toHaveBeenCalledWith('click', expect.any(Function));
102
+ expect(removeOverlay).toHaveBeenCalled();
103
+ });
104
+
105
+ it('click handler hides tooltip when no features found', () => {
106
+ const onFeatureSelect = jest.fn();
107
+ render(
108
+ <InfoOverlay
109
+ selectedFeature={{}}
110
+ onFeatureSelect={onFeatureSelect}
111
+ layerId="layer1"
112
+ hideFilters={false}
113
+ ol={mockOl}
114
+ />,
115
+ );
116
+
117
+ const handler = onMap.mock.calls.find(([event]) => event === 'click')[1];
118
+
119
+ const evt = {
120
+ pixel: [0, 0],
121
+ target: { getFeaturesAtPixel: () => [] },
122
+ originalEvent: { target: { tagName: 'DIV' } },
123
+ };
124
+ handler(evt);
125
+
126
+ expect(onFeatureSelect).toHaveBeenCalledWith(null);
127
+ expect(document.getElementById('popup-overlay').style.display).toBe('none');
128
+ });
129
+
130
+ it('ignores click when target is a link (A tag)', () => {
131
+ const onFeatureSelect = jest.fn();
132
+ render(
133
+ <InfoOverlay
134
+ selectedFeature={{}}
135
+ onFeatureSelect={onFeatureSelect}
136
+ layerId="layer1"
137
+ hideFilters={false}
138
+ ol={mockOl}
139
+ />,
140
+ );
141
+
142
+ const handler = onMap.mock.calls.find(([event]) => event === 'click')[1];
143
+
144
+ const evt = {
145
+ pixel: [0, 0],
146
+ target: { getFeaturesAtPixel: () => [] },
147
+ originalEvent: { target: { tagName: 'A' } },
148
+ };
149
+ handler(evt);
150
+
151
+ expect(onFeatureSelect).not.toHaveBeenCalled();
152
+ });
153
+ });
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import superagent from 'superagent';
3
+
4
+ // const cases_url = '@@case-studies-map.arcgis.json';
5
+
6
+ export function useCases(url) {
7
+ const [cases, setCases] = React.useState([]);
8
+
9
+ React.useEffect(() => {
10
+ superagent
11
+ .get(url)
12
+ .set('accept', 'json')
13
+ .then((resp) => {
14
+ const res = JSON.parse(resp.text);
15
+ setCases(res.features);
16
+ });
17
+ }, [url]);
18
+
19
+ return cases;
20
+ }
@@ -0,0 +1,3 @@
1
+ <svg width="38" height="38" viewBox="0 0 38 38" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M37.3757 34.3789L30.2003 27.2246C32.5154 24.2751 33.7716 20.633 33.7669 16.8835C33.7669 13.5442 32.7767 10.28 30.9215 7.50351C29.0663 4.72705 26.4295 2.56305 23.3445 1.28518C20.2594 0.00731515 16.8647 -0.327033 13.5897 0.324418C10.3146 0.97587 7.30625 2.58386 4.94506 4.94506C2.58386 7.30625 0.97587 10.3146 0.324418 13.5897C-0.327033 16.8647 0.00731528 20.2594 1.28518 23.3445C2.56305 26.4295 4.72705 29.0664 7.50351 30.9215C10.28 32.7767 13.5442 33.7669 16.8835 33.7669C20.633 33.7716 24.2751 32.5154 27.2246 30.2003L34.3789 37.3757C34.5751 37.5735 34.8085 37.7306 35.0657 37.8377C35.3229 37.9448 35.5987 38 35.8773 38C36.1559 38 36.4318 37.9448 36.689 37.8377C36.9461 37.7306 37.1795 37.5735 37.3757 37.3757C37.5735 37.1795 37.7305 36.9461 37.8377 36.689C37.9448 36.4318 38 36.1559 38 35.8773C38 35.5987 37.9448 35.3229 37.8377 35.0657C37.7305 34.8085 37.5735 34.5751 37.3757 34.3789ZM4.22087 16.8835C4.22087 14.379 4.96352 11.9309 6.3549 9.8485C7.74628 7.76615 9.72391 6.14315 12.0377 5.18475C14.3515 4.22635 16.8975 3.97559 19.3538 4.46418C21.8101 4.95277 24.0664 6.15876 25.8373 7.92966C27.6081 9.70055 28.8141 11.9568 29.3027 14.4131C29.7913 16.8694 29.5406 19.4154 28.5822 21.7292C27.6238 24.043 26.0008 26.0206 23.9184 27.412C21.8361 28.8034 19.3879 29.546 16.8835 29.546C13.5251 29.546 10.3043 28.2119 7.92966 25.8373C5.55496 23.4626 4.22087 20.2418 4.22087 16.8835Z"/>
3
+ </svg>
@@ -0,0 +1,16 @@
1
+ import worldSVG from '@plone/volto/icons/world.svg';
2
+ import CaseStudyExplorerEdit from './CaseStudyExplorerEdit';
3
+ import CaseStudyExplorerView from './CaseStudyExplorerView';
4
+
5
+ export default function installCaseStudyExplorerBlock(config) {
6
+ config.blocks.blocksConfig.caseStudyExplorer = {
7
+ id: 'caseStudyExplorer',
8
+ title: 'NRR Case Study Explorer',
9
+ icon: worldSVG,
10
+ group: 'custom_blocks',
11
+ edit: CaseStudyExplorerEdit,
12
+ view: CaseStudyExplorerView,
13
+ };
14
+
15
+ return config;
16
+ }
@@ -0,0 +1,8 @@
1
+ Object.defineProperty(URL, 'createObjectURL', {
2
+ writable: true,
3
+ value: jest.fn(),
4
+ });
5
+ Object.defineProperty(HTMLCanvasElement, 'getContext', {
6
+ writable: true,
7
+ value: jest.fn(),
8
+ });