@eeacms/volto-cca-policy 0.2.46 → 0.2.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ ### [0.2.48](https://github.com/eea/volto-cca-policy/compare/0.2.47...0.2.48) - 2 July 2024
8
+
9
+ #### :hammer_and_wrench: Others
10
+
11
+ - Update version for hero block [Tiberiu Ichim - [`24131f1`](https://github.com/eea/volto-cca-policy/commit/24131f1626e2e27169e737ac0ac0b369b4804064)]
12
+ ### [0.2.47](https://github.com/eea/volto-cca-policy/compare/0.2.46...0.2.47) - 2 July 2024
13
+
14
+ #### :hammer_and_wrench: Others
15
+
16
+ - Tests [Tiberiu Ichim - [`d2cb56d`](https://github.com/eea/volto-cca-policy/commit/d2cb56d7b939c79fc025890110adb281cc68f570)]
17
+ - Tests [Tiberiu Ichim - [`73a4c47`](https://github.com/eea/volto-cca-policy/commit/73a4c47d243e866305c951b37c70ea75873b93db)]
18
+ - Tests [Tiberiu Ichim - [`afc6684`](https://github.com/eea/volto-cca-policy/commit/afc66846fc40bedeefb18e4a2f7fc8c0ec5c59f1)]
19
+ - Tests [Tiberiu Ichim - [`72e29dd`](https://github.com/eea/volto-cca-policy/commit/72e29dd6bfed94b67c92c5f6e02fcfc3bad299bb)]
20
+ - Show subtitle in the cca event title block [Tiberiu Ichim - [`e3fee69`](https://github.com/eea/volto-cca-policy/commit/e3fee690b3562138d67d01c8fa00453285631614)]
7
21
  ### [0.2.46](https://github.com/eea/volto-cca-policy/compare/0.2.45...0.2.46) - 1 July 2024
8
22
 
9
23
  ### [0.2.45](https://github.com/eea/volto-cca-policy/compare/0.2.44...0.2.45) - 24 June 2024
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-cca-policy",
3
- "version": "0.2.46",
3
+ "version": "0.2.48",
4
4
  "description": "@eeacms/volto-cca-policy: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -38,6 +38,7 @@
38
38
  "@elastic/search-ui": "1.21.2",
39
39
  "@eeacms/volto-slate-label": "^0.6.0",
40
40
  "@eeacms/volto-tabs-block": "^7.5.1",
41
+ "@eeacms/volto-hero-block": "^7.1.0",
41
42
  "d3-array": "^2.12.1",
42
43
  "jotai": "^1.6.0",
43
44
  "query-string": "7.1.0",
@@ -1,93 +1,59 @@
1
1
  import React, { useState } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { Input } from 'semantic-ui-react';
4
+ import config from '@plone/volto/registry';
4
5
 
5
6
  import { injectIntl } from 'react-intl';
6
7
  import { FormFieldWrapper } from '@plone/volto/components';
8
+ import MapContainer from '@eeacms/volto-cca-policy/components/theme/Widgets/GeolocationWidgetMapContainer';
7
9
 
8
- import {
9
- Controls,
10
- Interactions,
11
- Layer,
12
- Map,
13
- Layers,
14
- } from '@eeacms/volto-openlayers-map/api';
15
- import { openlayers as ol } from '@eeacms/volto-openlayers-map';
16
-
17
- const MapContainer = (props) => {
18
- const { longitude, latitude, source } = props;
19
- return (
20
- <Map
21
- view={{
22
- center: ol.proj.fromLonLat([longitude, latitude]),
23
- showFullExtent: true,
24
- zoom: 15,
25
- }}
26
- pixelRatio={1}
27
- controls={ol.control.defaults({ attribution: false })}
28
- >
29
- <Layers>
30
- <Controls attribution={false} zoom={false} />
31
- <Interactions
32
- doubleClickZoom={true}
33
- dragAndDrop={false}
34
- dragPan={true}
35
- keyboardPan={true}
36
- keyboardZoom={true}
37
- mouseWheelZoom={true}
38
- pointer={true}
39
- select={false}
40
- />
41
- <Layer.Tile source={source} zIndex={0} />
42
- </Layers>
43
- </Map>
44
- );
10
+ const defaultValue = {
11
+ latitude: 55.6761,
12
+ longitude: 12.5683,
45
13
  };
46
14
 
47
15
  const GeolocationWidget = (props) => {
48
16
  const { id, value, onChange } = props;
49
17
 
50
- const [tileWMSSources, setTileWMSSources] = useState([]);
51
18
  const [address, setAddress] = useState('');
52
19
 
53
20
  const handleAddressChange = (event) => {
54
21
  setAddress(event.target.value);
55
22
  };
56
23
 
57
- const defaultValue = {
58
- latitude: 55.6761,
59
- longitude: 12.5683,
60
- };
61
-
62
- const handleSearch = (e) => {
24
+ const handleSearch = async (e) => {
63
25
  e.preventDefault();
64
26
 
65
- fetch(`https://nominatim.openstreetmap.org/search?q=${address}&format=json`)
66
- .then((response) => {
67
- const { lat, lon } = response.data[0];
68
- onChange(id, { latitude: lat, longitude: lon });
69
- })
70
- .catch((error) => {
71
- // console.error(error);
72
- });
73
- };
27
+ const url = `https://nominatim.openstreetmap.org/search?q=${address}&format=json`;
74
28
 
75
- React.useEffect(() => {
76
- setTileWMSSources([
77
- new ol.source.TileWMS({
78
- url: 'https://gisco-services.ec.europa.eu/maps/service',
79
- params: {
80
- LAYERS: 'OSMBlossomComposite',
81
- TILED: true,
82
- },
83
- serverType: 'geoserver',
84
- transition: 0,
85
- }),
86
- ]);
87
- }, []); // ol.source.TileWMS, ol.source.Vector
29
+ const { corsProxyPath = '/cors-proxy', host, port } = config.settings;
30
+ const base = __SERVER__
31
+ ? `http://${host}:${port}`
32
+ : `${window.location.protocol}//${window.location.host}`;
33
+
34
+ const path = `${base}${corsProxyPath}/${url}`;
35
+
36
+ let locations;
37
+ try {
38
+ const response = await fetch(path);
39
+ locations = await response.json();
40
+ } catch (e) {
41
+ // eslint-disable-next-line no-console
42
+ console.log('error in fetching location', e);
43
+ }
44
+
45
+ if (locations?.length) {
46
+ const { lat, lon } = locations[0];
47
+ onChange(id, { latitude: lat, longitude: lon });
48
+ }
49
+ };
88
50
 
89
51
  if (__SERVER__) return '';
90
52
 
53
+ const lat = value?.latitude ?? defaultValue.latitude;
54
+ const long = value?.longitude ?? defaultValue.longitude;
55
+ const mapKey = `${lat}_${long}`;
56
+
91
57
  return (
92
58
  <FormFieldWrapper {...props} className="geolocation-field">
93
59
  <div className="ui form">
@@ -101,12 +67,9 @@ const GeolocationWidget = (props) => {
101
67
  </div>
102
68
  </div>
103
69
  <MapContainer
104
- key={`${value?.latitude || defaultValue.latitude}_${
105
- value?.longitude || defaultValue.longitude
106
- }`}
70
+ key={mapKey}
107
71
  longitude={value?.longitude || defaultValue.longitude}
108
72
  latitude={value?.latitude || defaultValue.latitude}
109
- source={tileWMSSources[0]}
110
73
  />
111
74
  <div className="ui form">
112
75
  <div className="inline fields">
@@ -115,6 +78,9 @@ const GeolocationWidget = (props) => {
115
78
  type="number"
116
79
  placeholder="latitude"
117
80
  value={value?.latitude || defaultValue.latitude}
81
+ onChange={(e) =>
82
+ onChange(id, { ...value, latitude: e.target.value })
83
+ }
118
84
  />
119
85
  </div>
120
86
  <div className="field">
@@ -122,6 +88,9 @@ const GeolocationWidget = (props) => {
122
88
  type="number"
123
89
  placeholder="longitude"
124
90
  value={value?.longitude || defaultValue.longitude}
91
+ onChange={(e) =>
92
+ onChange(id, { ...value, longitude: e.target.value })
93
+ }
125
94
  />
126
95
  </div>
127
96
  </div>
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import { MemoryRouter } from 'react-router-dom';
3
+ import configureStore from 'redux-mock-store';
4
+ import { render } from '@testing-library/react';
5
+ import '@testing-library/jest-dom/extend-expect';
6
+ import { Provider } from 'react-intl-redux';
7
+
8
+ import GeolocationWidget from './GeolocationWidget';
9
+
10
+ global.__SERVER__ = false;
11
+
12
+ jest.mock(
13
+ '@eeacms/volto-cca-policy/components/theme/Widgets/GeolocationWidgetMapContainer',
14
+ );
15
+ const mockStore = configureStore();
16
+
17
+ describe('GeolocationWidget', () => {
18
+ it('should render the component', () => {
19
+ const data = {
20
+ id: 'location',
21
+ title: 'Location',
22
+ value: {
23
+ latitude: 10,
24
+ longitude: 50,
25
+ },
26
+ };
27
+
28
+ const store = mockStore({
29
+ userSession: { token: '1234' },
30
+ intl: {
31
+ locale: 'en',
32
+ messages: {},
33
+ },
34
+ });
35
+
36
+ const { container } = render(
37
+ <Provider store={store}>
38
+ <MemoryRouter>
39
+ <GeolocationWidget {...data} />
40
+ </MemoryRouter>
41
+ </Provider>,
42
+ );
43
+ expect(container).toBeTruthy();
44
+ });
45
+ });
@@ -0,0 +1,63 @@
1
+ import React, { useState } from 'react';
2
+ import {
3
+ Controls,
4
+ Interactions,
5
+ Layer,
6
+ Map,
7
+ Layers,
8
+ } from '@eeacms/volto-openlayers-map/api';
9
+ import { openlayers as ol } from '@eeacms/volto-openlayers-map';
10
+
11
+ const TileSetLoader = (props) => {
12
+ const [tileWMSSources, setTileWMSSources] = useState([]);
13
+
14
+ React.useEffect(() => {
15
+ setTileWMSSources([
16
+ new ol.source.TileWMS({
17
+ url: 'https://gisco-services.ec.europa.eu/maps/service',
18
+ params: {
19
+ LAYERS: 'OSMBlossomComposite',
20
+ TILED: true,
21
+ },
22
+ serverType: 'geoserver',
23
+ transition: 0,
24
+ }),
25
+ ]);
26
+ }, []);
27
+
28
+ return tileWMSSources ? (
29
+ <MapContainer {...props} source={tileWMSSources[0]} />
30
+ ) : null;
31
+ };
32
+
33
+ const MapContainer = (props) => {
34
+ const { longitude, latitude, source } = props;
35
+ return (
36
+ <Map
37
+ view={{
38
+ center: ol.proj.fromLonLat([longitude, latitude]),
39
+ showFullExtent: true,
40
+ zoom: 15,
41
+ }}
42
+ pixelRatio={1}
43
+ controls={ol.control.defaults({ attribution: false })}
44
+ >
45
+ <Layers>
46
+ <Controls attribution={false} zoom={false} />
47
+ <Interactions
48
+ doubleClickZoom={true}
49
+ dragAndDrop={false}
50
+ dragPan={true}
51
+ keyboardPan={true}
52
+ keyboardZoom={true}
53
+ mouseWheelZoom={true}
54
+ pointer={true}
55
+ select={false}
56
+ />
57
+ <Layer.Tile source={source} zIndex={0} />
58
+ </Layers>
59
+ </Map>
60
+ );
61
+ };
62
+
63
+ export default TileSetLoader;
@@ -0,0 +1,3 @@
1
+ export default function MapContainer() {
2
+ return <div className="map-container"></div>;
3
+ }
package/src/index.js CHANGED
@@ -70,6 +70,11 @@ const applyConfig = (config) => {
70
70
  ];
71
71
  }
72
72
 
73
+ config.settings.allowed_cors_destinations = [
74
+ ...(config.settings.allowed_cors_destinations || []),
75
+ 'nominatim.openstreetmap.org',
76
+ ];
77
+
73
78
  // if (!config.settings.loadables.d3)
74
79
  // config.settings.loadables.d3 = loadable.lib(() => import('d3'));
75
80
  // if (!config.settings.loadables.d3Geo)