@eeacms/volto-eea-map 5.0.2 → 5.0.4

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,11 +4,40 @@ 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
- ### [5.0.2](https://github.com/eea/volto-eea-map/compare/5.0.1...5.0.2) - 16 August 2024
7
+ ### [5.0.4](https://github.com/eea/volto-eea-map/compare/5.0.3...5.0.4) - 9 September 2024
8
8
 
9
- #### :hammer_and_wrench: Others
9
+ #### :house: Internal changes
10
+
11
+ - style: Automated code fix [eea-jenkins - [`f537545`](https://github.com/eea/volto-eea-map/commit/f53754571332b1f984528aa5cf8ad9a52c2af403)]
12
+ - style: Automated code fix [eea-jenkins - [`d91f093`](https://github.com/eea/volto-eea-map/commit/d91f09374b10dd887028b12c026eb09df4948528)]
13
+
14
+ #### :hammer_and_wrench: Others
15
+
16
+ - manage the redux and actions right [dobri1408 - [`44f7177`](https://github.com/eea/volto-eea-map/commit/44f7177958ee9b03ce25d178279e44f686c053c5)]
17
+ - manage the redux and actions right [dobri1408 - [`83461ad`](https://github.com/eea/volto-eea-map/commit/83461ad0848e610349bd7be76a48ecc8b331e169)]
18
+ - manage the redux and actions right [dobri1408 - [`7c28909`](https://github.com/eea/volto-eea-map/commit/7c289090f46eeb7a49ebb3f6043c30aeb978752f)]
19
+ - Update preview_image.js [dobri1408 - [`2b1695b`](https://github.com/eea/volto-eea-map/commit/2b1695bd4da4f8850bcfba721ab96d5a878828f3)]
20
+ - Update preview_image.js [dobri1408 - [`4a93291`](https://github.com/eea/volto-eea-map/commit/4a93291fd37139d7130ed9952e3ff9bbf67873b5)]
21
+ - fix bug on maps zoom [dobri1408 - [`7d76531`](https://github.com/eea/volto-eea-map/commit/7d765312d372824b4f8a34bf761759b8db08d7f6)]
22
+ - Update preview_image.js [dobri1408 - [`e2df116`](https://github.com/eea/volto-eea-map/commit/e2df116d0eacccfbc5b320e4102aad517c488afe)]
23
+ - fix linter [dobri1408 - [`bb29959`](https://github.com/eea/volto-eea-map/commit/bb29959761865f5933739f8656af929df8b19f37)]
24
+ - fix eslint [dobri1408 - [`f19375a`](https://github.com/eea/volto-eea-map/commit/f19375a7a7f825a41d415b5ed5a29b1e4517a33c)]
25
+ - Update VisualizationWidget.jsx [dobri1408 - [`7e6cc7d`](https://github.com/eea/volto-eea-map/commit/7e6cc7da795f3b47c189aec1425d78f7c385e670)]
26
+ - Update preview_image.js [dobri1408 - [`3b37b97`](https://github.com/eea/volto-eea-map/commit/3b37b97cb965fe5c3204a6272e159dbe03d8bf0b)]
27
+ - Alert message if preview image not saved [dobri1408 - [`1213b99`](https://github.com/eea/volto-eea-map/commit/1213b99edf2623221610656301e0fa6e9cef78b7)]
28
+ - update [Miu Razvan - [`af50deb`](https://github.com/eea/volto-eea-map/commit/af50deb4e623f82d11ac11c92f9342362f289a7f)]
29
+ - fix tests [dobri1408 - [`f0a55c0`](https://github.com/eea/volto-eea-map/commit/f0a55c0f75f04cc3d66a00f6e9f32db77bb2ecd2)]
30
+ - fix tests [dobri1408 - [`27a2c86`](https://github.com/eea/volto-eea-map/commit/27a2c8654ce9350e82a77a1cea6aadb08c0035e0)]
31
+ - fix tests [dobri1408 - [`3f0a5bf`](https://github.com/eea/volto-eea-map/commit/3f0a5bfd8fa4ce578318876b4b3b77f846067bf6)]
32
+ - fix tests [dobri1408 - [`65244c7`](https://github.com/eea/volto-eea-map/commit/65244c7d16c30d6d1d37f5e294add890a3f93405)]
33
+ - fix tests [dobri1408 - [`e73568c`](https://github.com/eea/volto-eea-map/commit/e73568c32d66f22b938cbc9f8ed8a37b3061edb2)]
34
+ - preview image [dobri1408 - [`c8e1b58`](https://github.com/eea/volto-eea-map/commit/c8e1b58d1bfd5c034a56a31fbf41fa2e463d4af8)]
35
+ - add middleware [dobri1408 - [`2480fad`](https://github.com/eea/volto-eea-map/commit/2480fadb2a95a9b628a30ecb7a5c3fed49e64fb6)]
36
+ - use arcgis reactiveUtils to take screenshot when layers are drawn [Miu Razvan - [`96794da`](https://github.com/eea/volto-eea-map/commit/96794da9fba1f4824edb5b7f28d18643d6f7a84e)]
37
+ ### [5.0.3](https://github.com/eea/volto-eea-map/compare/5.0.2...5.0.3) - 22 August 2024
38
+
39
+ ### [5.0.2](https://github.com/eea/volto-eea-map/compare/5.0.1...5.0.2) - 16 August 2024
10
40
 
11
- - fix small bug [Miu Razvan - [`41499bf`](https://github.com/eea/volto-eea-map/commit/41499bfc86d7a975fac49cad865f396b7deda187)]
12
41
  ### [5.0.1](https://github.com/eea/volto-eea-map/compare/5.0.0...5.0.1) - 16 August 2024
13
42
 
14
43
  ## [5.0.0](https://github.com/eea/volto-eea-map/compare/4.1.0...5.0.0) - 26 July 2024
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-eea-map",
3
- "version": "5.0.2",
3
+ "version": "5.0.4",
4
4
  "description": "@eeacms/volto-eea-map: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -145,7 +145,7 @@ class $Layer extends EventEmitter {
145
145
  if (this.#layer?.queryExtent && this.#props.zoomToExtent) {
146
146
  this.#layer.when(async () => {
147
147
  const data = await this.#layer.queryExtent();
148
- if (!$map.view) return;
148
+ if (!$map.view?.ready) return;
149
149
  $map.view.goTo(data.extent).then(() => {
150
150
  const homeWidget = $map.view.ui.find('Home');
151
151
  if (!homeWidget) return;
@@ -56,6 +56,25 @@ const MapBuilder = forwardRef((props, ref) => {
56
56
 
57
57
  const rotationEnabled = settings.view?.constraints?.rotationEnabled ?? false;
58
58
 
59
+ const MapProperties = useMemo(
60
+ () => ({
61
+ ...(settings.map || {}),
62
+ basemap,
63
+ }),
64
+ [settings.map, basemap],
65
+ );
66
+
67
+ const ViewProperties = useMemo(
68
+ () => ({
69
+ ...(settings.view || {}),
70
+ constraints: {
71
+ ...(settings.view?.constraints || {}),
72
+ rotationEnabled,
73
+ },
74
+ }),
75
+ [settings.view, rotationEnabled],
76
+ );
77
+
59
78
  useEffect(() => {
60
79
  setRenderWidgets(false);
61
80
  }, [widgets]);
@@ -80,17 +99,8 @@ const MapBuilder = forwardRef((props, ref) => {
80
99
 
81
100
  return (
82
101
  <Map
83
- MapProperties={{
84
- ...(settings.map || {}),
85
- basemap,
86
- }}
87
- ViewProperties={{
88
- ...(settings.view || {}),
89
- constraints: {
90
- ...(settings.view?.constraints || {}),
91
- rotationEnabled,
92
- },
93
- }}
102
+ MapProperties={MapProperties}
103
+ ViewProperties={ViewProperties}
94
104
  ref={$map}
95
105
  >
96
106
  {renderWidgets &&
@@ -1,9 +1,7 @@
1
1
  import React, { useState, useRef, useEffect } from 'react';
2
2
  import { Modal, Button, Grid } from 'semantic-ui-react';
3
3
  import { toast } from 'react-toastify';
4
-
5
4
  import { FormFieldWrapper, Icon, Toast } from '@plone/volto/components';
6
-
7
5
  import MapBuilder from '@eeacms/volto-eea-map/Arcgis/Map/MapBuilder';
8
6
  import {
9
7
  initEditor,
@@ -11,11 +9,10 @@ import {
11
9
  validateEditor,
12
10
  onPasteEditor,
13
11
  } from '@eeacms/volto-eea-map/jsoneditor';
14
-
15
12
  import editSVG from '@plone/volto/icons/editing.svg';
16
-
17
13
  import '@eeacms/volto-eea-map/styles/editor.less';
18
14
  import MapEditor from '../Arcgis/Editor/Editor';
15
+ import { debounce } from '../Arcgis/helpers';
19
16
 
20
17
  function JsonEditorModal(props) {
21
18
  const { value, onClose, onChange } = props;
@@ -164,9 +161,73 @@ function MapEditorModal(props) {
164
161
  }
165
162
 
166
163
  const VisualizationWidget = (props) => {
164
+ const $map = useRef();
165
+ const controller = useRef({});
166
+ const $value = useRef(props.value);
167
167
  const { id, title, description, value } = props;
168
168
  const [showMapEditor, setShowMapEditor] = useState(false);
169
169
 
170
+ const onConnect = () => {
171
+ if (controller.current.multiple && !props.block && !$map.current) return;
172
+ props.onChange(props.id, {
173
+ ...$value.current,
174
+ preview: 'loading',
175
+ });
176
+ controller.current.agReactive = $map.current.modules.agReactiveUtils.watch(
177
+ () => $map.current?.view?.updating,
178
+ async (updating) => {
179
+ if (updating || !$map.current?.view) return;
180
+ debounce(
181
+ async () => {
182
+ if (!$map.current?.view) return;
183
+ const preview = await $map.current.view.takeScreenshot({
184
+ format: 'png',
185
+ });
186
+ props.onChange(props.id, {
187
+ ...$value.current,
188
+ preview: preview.dataUrl,
189
+ });
190
+ },
191
+ 300,
192
+ 'visualization-widget-screenshot',
193
+ );
194
+ },
195
+ );
196
+ };
197
+
198
+ const onDisconnect = () => {
199
+ if (!controller.current.agReactive) return;
200
+ controller.current.agReactive.remove();
201
+ };
202
+
203
+ useEffect(() => {
204
+ const map = $map.current;
205
+
206
+ if (!map) return;
207
+
208
+ const widgets = document.querySelectorAll(
209
+ '.field-wrapper-map_visualization_data',
210
+ );
211
+
212
+ if (widgets.length > 1) {
213
+ controller.current.multiple = true;
214
+ }
215
+
216
+ map.on('connected', onConnect);
217
+ map.on('disconnected', onDisconnect);
218
+
219
+ return () => {
220
+ if (!map) return;
221
+ map.off('connected', onConnect);
222
+ map.off('disconnected', onDisconnect);
223
+ };
224
+ // eslint-disable-next-line
225
+ }, []);
226
+
227
+ useEffect(() => {
228
+ $value.current = value;
229
+ }, [value]);
230
+
170
231
  if (__SERVER__ || !value) return null;
171
232
 
172
233
  return (
@@ -185,7 +246,7 @@ const VisualizationWidget = (props) => {
185
246
  </Button>
186
247
  </div>
187
248
  {description && <p className="help">{description}</p>}
188
- <MapBuilder data={value} />
249
+ <MapBuilder data={value} ref={$map} />
189
250
  {showMapEditor && (
190
251
  <MapEditorModal
191
252
  {...props}
package/src/index.js CHANGED
@@ -15,6 +15,7 @@ import ArcgisViewpointWidget from './Widgets/ArcgisViewpointWidget';
15
15
  import VisualizationViewWidget from './Widgets/VisualizationViewWidget';
16
16
 
17
17
  import VisualizationView from './Views/VisualizationView';
18
+ import { preview_image } from './middlewares/preview_image';
18
19
 
19
20
  const applyConfig = (config) => {
20
21
  config.settings.allowed_cors_destinations = [
@@ -63,6 +64,10 @@ const applyConfig = (config) => {
63
64
  ],
64
65
  'id',
65
66
  );
67
+ config.settings.storeExtenders = [
68
+ ...(config.settings.storeExtenders || []),
69
+ preview_image,
70
+ ];
66
71
 
67
72
  config.views.contentTypesViews.map_visualization = VisualizationView;
68
73
 
@@ -72,6 +77,7 @@ const applyConfig = (config) => {
72
77
  config.widgets.widget.arcgis_viewpoint = ArcgisViewpointWidget;
73
78
 
74
79
  config.widgets.id.map_visualization_data = VisualizationWidget;
80
+
75
81
  config.widgets.views.id.map_visualization_data = VisualizationViewWidget;
76
82
 
77
83
  return config;
@@ -0,0 +1,100 @@
1
+ import {
2
+ CREATE_CONTENT,
3
+ UPDATE_CONTENT,
4
+ } from '@plone/volto/constants/ActionTypes';
5
+
6
+ export const preview_image = (middlewares) => [
7
+ (store) => (next) => async (action) => {
8
+ if (![CREATE_CONTENT, UPDATE_CONTENT].includes(action.type)) {
9
+ return next(action);
10
+ }
11
+ const state = store.getState();
12
+ const contentData = state.content.data;
13
+ const type = action?.request?.data?.['@type'] || contentData['@type'];
14
+ const lastPreviewImage = Object.keys(action?.request?.data).includes(
15
+ 'preview_image',
16
+ )
17
+ ? action?.request?.data.preview_image
18
+ : contentData?.preview_image;
19
+ if (
20
+ !contentData ||
21
+ type !== 'map_visualization' ||
22
+ contentData.preview_image_saved ||
23
+ !action?.request?.data?.map_visualization_data?.preview
24
+ ) {
25
+ return next(action);
26
+ }
27
+
28
+ if (
29
+ lastPreviewImage &&
30
+ lastPreviewImage?.filename !== 'preview_image_generated_map_simple.png'
31
+ ) {
32
+ if (action?.request?.data?.map_visualization_data?.preview) {
33
+ const mapVisualizationData = {
34
+ ...action.request.data.map_visualization_data,
35
+ };
36
+ delete mapVisualizationData.preview;
37
+
38
+ return next({
39
+ ...action,
40
+ request: {
41
+ ...action.request,
42
+ data: {
43
+ ...action.request.data,
44
+ map_visualization_data: mapVisualizationData,
45
+ },
46
+ },
47
+ });
48
+ } else return next(action);
49
+ }
50
+ const preview = action?.request?.data?.map_visualization_data?.preview;
51
+ if (
52
+ preview === 'loading' &&
53
+ // eslint-disable-next-line no-alert
54
+ window.confirm('Do you want to save a preview image?')
55
+ ) {
56
+ // eslint-disable-next-line no-alert
57
+ window.alert('Wait for the preview image to generate!');
58
+ return;
59
+ } else if (
60
+ preview !== 'loading' &&
61
+ // eslint-disable-next-line no-alert
62
+ !window.confirm('Do you want to save a preview image?')
63
+ ) {
64
+ return next(action);
65
+ }
66
+ try {
67
+ const previewImage = {
68
+ preview_image: {
69
+ data: action.request.data.map_visualization_data.preview.split(
70
+ ',',
71
+ )[1],
72
+ encoding: 'base64',
73
+ 'content-type': 'image/png',
74
+ filename: 'preview_image_generated_map_simple.png',
75
+ },
76
+ preview_image_saved: true,
77
+ };
78
+
79
+ const mapVisualizationData = {
80
+ ...action.request.data.map_visualization_data,
81
+ };
82
+ delete mapVisualizationData.preview;
83
+
84
+ return next({
85
+ ...action,
86
+ request: {
87
+ ...action.request,
88
+ data: {
89
+ ...action.request.data,
90
+ ...previewImage,
91
+ map_visualization_data: mapVisualizationData,
92
+ },
93
+ },
94
+ });
95
+ } catch (error) {
96
+ return next(action);
97
+ }
98
+ },
99
+ ...middlewares,
100
+ ];