@eeacms/volto-eea-map 0.1.34 → 0.1.35

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,30 @@ 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.1.34](https://github.com/eea/volto-eea-map/compare/0.1.33...0.1.34) - 12 June 2023
7
+ ### [0.1.35](https://github.com/eea/volto-eea-map/compare/0.1.34...0.1.35) - 14 June 2023
8
+
9
+ #### :rocket: New Features
10
+
11
+ - feat: webmap update faster #254131 [Andrei Grigore - [`b1d6d25`](https://github.com/eea/volto-eea-map/commit/b1d6d25c94987b6c7f7ec548f36960f5912ebee6)]
12
+ - feat: colorpicker can set transparency #254131 [Andrei Grigore - [`aa13f63`](https://github.com/eea/volto-eea-map/commit/aa13f63c2123368d53e4ded81e2ebc7f6044c1f0)]
13
+
14
+ #### :bug: Bug Fixes
15
+
16
+ - fix: apply/remove queries more simple #254131 [Andrei Grigore - [`ec442c0`](https://github.com/eea/volto-eea-map/commit/ec442c0f6aaffada095f6722f23faebe93b0f9da)]
17
+ - fix: clearup map data on viz_url delete #254131 [Andrei Grigore - [`f14b2d0`](https://github.com/eea/volto-eea-map/commit/f14b2d038379bc6170dfaaa8c34f265c6516cb18)]
18
+ - fix: colorpicker with submit #254131 [Andrei Grigore - [`3fac753`](https://github.com/eea/volto-eea-map/commit/3fac75391758ad6b24b6e54bb5f7d19c373f9fba)]
8
19
 
9
20
  #### :house: Internal changes
10
21
 
11
- - chore: enable alpha [Andrei Grigore - [`e016e46`](https://github.com/eea/volto-eea-map/commit/e016e4631a4332f07895f6077308235c41a6702c)]
22
+ - chore: cleanup unused #254131 [Andrei Grigore - [`5245fd4`](https://github.com/eea/volto-eea-map/commit/5245fd46912214ae3cbaac29c338497f0649c919)]
23
+ - chore: cleanup, more reusable helper function #254131 [Andrei Grigore - [`1d83848`](https://github.com/eea/volto-eea-map/commit/1d83848fd965a165df57632c3b23229b411cc674)]
24
+ - chore: cleanup, creater reusable helper function #254131 [Andrei Grigore - [`8be34bf`](https://github.com/eea/volto-eea-map/commit/8be34bfbb40936c5dfccc674ef1e95e6f5b165a0)]
25
+
26
+ #### :hammer_and_wrench: Others
27
+
28
+ - wip: better queries keep #254131 [Andrei Grigore - [`88c9d48`](https://github.com/eea/volto-eea-map/commit/88c9d489d02780e1b03237c78db196f5dcabea06)]
29
+ - wip: init branch #254131 [Andrei Grigore - [`f841ecd`](https://github.com/eea/volto-eea-map/commit/f841ecdee3ef1018679c14706e1e0962ea4b3286)]
30
+ ### [0.1.34](https://github.com/eea/volto-eea-map/compare/0.1.33...0.1.34) - 12 June 2023
12
31
 
13
32
  ### [0.1.33](https://github.com/eea/volto-eea-map/compare/0.1.32...0.1.33) - 12 June 2023
14
33
 
@@ -22,7 +41,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
22
41
 
23
42
  - chore: clear unused #254131 [andreiggr - [`ccec2ea`](https://github.com/eea/volto-eea-map/commit/ccec2eaab173c905cd4ea0190a9c6cfd630250f9)]
24
43
  - chore: clear block style #254131 [andreiggr - [`af500bc`](https://github.com/eea/volto-eea-map/commit/af500bc10a5f280eff0335f45bae1596d66a7e6b)]
25
- - chore: [JENKINS] Remove alpha testing version [valentinab25 - [`76b29e5`](https://github.com/eea/volto-eea-map/commit/76b29e510f5156590723831a524bc39dfba6deba)]
26
44
 
27
45
  #### :hammer_and_wrench: Others
28
46
 
@@ -32,7 +50,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
32
50
  - * versions [andreiggr - [`6d9ff2b`](https://github.com/eea/volto-eea-map/commit/6d9ff2b26a236b6445678e3d84698d1c3c0826f4)]
33
51
  - add razzle-plugin-scss dep [andreiggr - [`d74cee5`](https://github.com/eea/volto-eea-map/commit/d74cee51d30c866afe55730e5b25e0bf11d2caea)]
34
52
  - volto-object-widget [andreiggr - [`18d0ed7`](https://github.com/eea/volto-eea-map/commit/18d0ed72c1ba7b0f7159a0eefc09ccea9acee5cb)]
35
- - Add Sonarqube tag using bise-frontend addons list [EEA Jenkins - [`5911d01`](https://github.com/eea/volto-eea-map/commit/5911d01f7f3bc79a2c834fab75a9a4ac05d2d042)]
36
53
  ### [0.1.32](https://github.com/eea/volto-eea-map/compare/0.1.31...0.1.32) - 20 February 2023
37
54
 
38
55
  #### :hammer_and_wrench: Others
@@ -40,7 +57,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
40
57
  - remove console.log [tedw87 - [`3aeb3e8`](https://github.com/eea/volto-eea-map/commit/3aeb3e8ec5474387f3cd22eb9b387c6681e17120)]
41
58
  - refactor code [tedw87 - [`6d7830e`](https://github.com/eea/volto-eea-map/commit/6d7830eb934f56c255eea5642bdefba30d892946)]
42
59
  - add Blossom basemap layer [tedw87 - [`5226ee2`](https://github.com/eea/volto-eea-map/commit/5226ee218df3401cf467afbc7a4d720dc30719e1)]
43
- - Add Sonarqube tag using cca-frontend addons list [EEA Jenkins - [`1dad5c6`](https://github.com/eea/volto-eea-map/commit/1dad5c6617096ff85223165a6dd2b1d5d7deea6a)]
44
60
  ### [0.1.31](https://github.com/eea/volto-eea-map/compare/0.1.30...0.1.31) - 11 November 2022
45
61
 
46
62
  #### :hammer_and_wrench: Others
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-eea-map",
3
- "version": "0.1.34",
3
+ "version": "0.1.35",
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",
@@ -7,15 +7,28 @@ import { compose } from 'redux';
7
7
  import { getContent } from '@plone/volto/actions';
8
8
 
9
9
  import BlockDataForm from '@plone/volto/components/manage/Form/BlockDataForm';
10
- import View from './View';
11
- import { Schema } from './Schema';
12
- import '../../../styles/map.css';
10
+ import Webmap from '@eeacms/volto-eea-map/components/Webmap';
11
+ import ExtraViews from '@eeacms/volto-eea-map/components/ExtraViews';
12
+ import '@eeacms/volto-eea-map/styles/map.css';
13
13
 
14
- import _ from 'lodash';
14
+ import { Schema } from './Schema';
15
+ import {
16
+ applyQueriesToMapLayers,
17
+ updateBlockQueryFromPageQuery,
18
+ } from '@eeacms/volto-eea-map/utils';
15
19
 
16
20
  const Edit = (props) => {
17
- const { block, data, onChangeBlock, selected, id } = props;
18
- const schema = React.useMemo(() => Schema(props), [props]);
21
+ const {
22
+ block,
23
+ data,
24
+ onChangeBlock,
25
+ selected,
26
+ id,
27
+ data_provenance = {},
28
+ } = props;
29
+ const { height = '' } = data;
30
+ const schema = Schema(props);
31
+ const [mapData, setMapData] = React.useState('');
19
32
 
20
33
  React.useEffect(() => {
21
34
  if (!Object.hasOwn(data, 'show_legend')) {
@@ -36,30 +49,68 @@ const Edit = (props) => {
36
49
  dataprotection: { enabled: true },
37
50
  });
38
51
  }
39
-
40
- // eslint-disable-next-line react-hooks/exhaustive-deps
41
- }, [data]);
52
+ // eslint-disable-next-line react-hooks/exhaustive-deps
53
+ }, [data.show_legend, data.show_sources, data.dataprotection]);
42
54
 
43
55
  React.useEffect(() => {
44
- props.getContent(data.vis_url, null, id);
45
- // eslint-disable-next-line react-hooks/exhaustive-deps
46
- }, [data.vis_url]);
56
+ props.getContent(props.data.vis_url, null, id);
57
+ // eslint-disable-next-line react-hooks/exhaustive-deps
58
+ }, [props.data.vis_url]);
47
59
 
48
60
  React.useEffect(() => {
49
- if (
50
- !data.data_query_params ||
51
- !_.isEqual(props.data_query, data.data_query_params)
52
- ) {
53
- onChangeBlock(block, {
54
- ...data,
55
- data_query_params: props.data_query,
56
- });
61
+ if (props.data_query) {
62
+ //if block data_query_params do not exist, init them
63
+ if (!props?.data?.data_query_params) {
64
+ onChangeBlock(block, {
65
+ ...props.data,
66
+ data_query_params: [...props.data_query],
67
+ });
68
+ }
69
+
70
+ //if block data_query_params exist, deep check them then change them in block data
71
+ if (props?.data_query && data?.data_query_params) {
72
+ const newDataQuery = updateBlockQueryFromPageQuery(
73
+ props?.data_query,
74
+ data?.data_query_params,
75
+ );
76
+
77
+ onChangeBlock(block, {
78
+ ...data,
79
+ data_query_params: [...newDataQuery],
80
+ });
81
+ }
57
82
  }
58
83
  // eslint-disable-next-line react-hooks/exhaustive-deps
59
- }, [props.block, props.data_query, data.data_query_params]);
84
+ }, [props.data_query]);
85
+
86
+ React.useEffect(() => {
87
+ const updatedMapData = applyQueriesToMapLayers(
88
+ props.map_visualization,
89
+ props.data.data_query_params,
90
+ props.data.enable_queries,
91
+ );
92
+ setMapData(updatedMapData);
93
+
94
+ // eslint-disable-next-line react-hooks/exhaustive-deps
95
+ }, [props.map_visualization, props.data]);
96
+
60
97
  return (
61
98
  <>
62
- <View data={data} id={id} isEdit={true} />
99
+ {mapData && (
100
+ <div>
101
+ <Webmap data={mapData} height={height} isEdit={true} />
102
+ <ExtraViews
103
+ data={{
104
+ ...data,
105
+ data_provenance,
106
+ map_data: props.map_visualization,
107
+ }}
108
+ />
109
+ </div>
110
+ )}
111
+ {!mapData && (
112
+ <p>No map view to show. Set visualization in block configuration.</p>
113
+ )}
63
114
  <SidebarPortal selected={selected}>
64
115
  <BlockDataForm
65
116
  block={block}
@@ -81,8 +132,11 @@ const Edit = (props) => {
81
132
  export default compose(
82
133
  connect(
83
134
  (state, props) => ({
84
- block_data: state.content.data,
85
135
  data_query: state.content.data.data_query,
136
+ data_provenance:
137
+ state.content.subrequests?.[props.id]?.data?.data_provenance,
138
+ map_visualization:
139
+ state.content.subrequests?.[props.id]?.data?.map_visualization_data,
86
140
  }),
87
141
  {
88
142
  getContent,
@@ -6,72 +6,31 @@ import { compose } from 'redux';
6
6
  import { PrivacyProtection } from '@eeacms/volto-embed';
7
7
 
8
8
  import { getContent } from '@plone/volto/actions';
9
- import Webmap from '../../Webmap';
10
- import ExtraViews from '../../ExtraViews';
9
+ import Webmap from '@eeacms/volto-eea-map/components/Webmap';
10
+ import ExtraViews from '@eeacms/volto-eea-map/components/ExtraViews';
11
+ import { applyQueriesToMapLayers } from '@eeacms/volto-eea-map/utils';
11
12
 
12
13
  const View = (props) => {
13
- const { data, id, isEdit, map_visualization = '', data_provenance = {} } =
14
- props || {};
15
- const { height = '', vis_url = '', enable_queries } = data;
14
+ const { data, id, data_provenance = {} } = props || {};
15
+ const { height = '' } = data;
16
16
 
17
- const [mapData, setMapData] = React.useState(map_visualization);
17
+ const [mapData, setMapData] = React.useState('');
18
18
 
19
19
  React.useEffect(() => {
20
- if (vis_url) {
21
- props.getContent(vis_url, null, id);
22
- }
20
+ props.getContent(props.data.vis_url, null, id);
23
21
  // eslint-disable-next-line react-hooks/exhaustive-deps
24
- }, [vis_url, enable_queries]);
22
+ }, [props.data.vis_url]);
25
23
 
26
24
  React.useEffect(() => {
27
- var altMapData = { ...map_visualization };
28
- const query_params = isEdit
29
- ? props.data?.data_query_params
30
- : props?.data_query;
31
- if (
32
- enable_queries &&
33
- map_visualization &&
34
- query_params &&
35
- query_params.length > 0 &&
36
- altMapData.layers &&
37
- altMapData.layers.map_layers &&
38
- altMapData.layers.map_layers.length > 0
39
- ) {
40
- let rules = [];
25
+ const updatedMapData = applyQueriesToMapLayers(
26
+ props.map_visualization,
27
+ props.data.data_query_params,
28
+ props.data.enable_queries,
29
+ );
41
30
 
42
- altMapData.layers.map_layers.forEach((l, j) => {
43
- query_params.forEach((param, i) => {
44
- const matchingFields =
45
- l.map_layer && l.map_layer.fields && l.map_layer.fields.length > 0
46
- ? l.map_layer.fields.filter(
47
- (field, k) =>
48
- field.name === param.alias || field.name === param.i,
49
- )
50
- : [];
51
-
52
- matchingFields.forEach((m, i) => {
53
- const newRules = param.v
54
- ? param.v.map((paramVal, i) => {
55
- return {
56
- field: m.name,
57
- operator: '=',
58
- value: paramVal,
59
- };
60
- })
61
- : [];
62
- rules = rules.concat(newRules);
63
- });
64
- });
65
- let autoQuery = {
66
- combinator: 'or',
67
- rules,
68
- };
69
- altMapData.layers.map_layers[j].map_layer.query = autoQuery;
70
- });
71
- }
72
- setMapData(altMapData);
31
+ setMapData(updatedMapData);
73
32
  // eslint-disable-next-line react-hooks/exhaustive-deps
74
- }, [map_visualization, props.data, props.data_query, isEdit, enable_queries]);
33
+ }, [props.map_visualization, props.data]);
75
34
 
76
35
  return (
77
36
  <PrivacyProtection data={data} height={height} {...props}>
@@ -82,7 +41,7 @@ const View = (props) => {
82
41
  data={{
83
42
  ...data,
84
43
  data_provenance,
85
- map_data: map_visualization,
44
+ map_data: props.map_visualization,
86
45
  }}
87
46
  />
88
47
  </div>
@@ -97,7 +56,6 @@ const View = (props) => {
97
56
  export default compose(
98
57
  connect(
99
58
  (state, props) => ({
100
- data_query: state.content.data.data_query,
101
59
  data_provenance:
102
60
  state.content.subrequests?.[props.id]?.data?.data_provenance,
103
61
  map_visualization:
@@ -1,11 +1,11 @@
1
1
  import React from 'react';
2
2
  import { UniversalLink, Icon } from '@plone/volto/components';
3
3
 
4
- import LegendWidget from './widgets/LegendWidget';
5
4
  import { serializeNodes } from '@plone/volto-slate/editor/render';
6
5
 
7
6
  import rightKeySVG from '@plone/volto/icons/right-key.svg';
8
7
  import downKeySVG from '@plone/volto/icons/down-key.svg';
8
+ import LegendView from '@eeacms/volto-eea-map/components/LegendView';
9
9
 
10
10
  const SourcesWidget = ({ data }) => {
11
11
  const [expand, setExpand] = React.useState(true);
@@ -56,7 +56,7 @@ const ExtraViews = ({ data }) => {
56
56
  return (
57
57
  <div className="extra-eea-map-content">
58
58
  {show_legend && map_data && (
59
- <LegendWidget data={map_data} show_viewer={show_viewer} />
59
+ <LegendView data={map_data} show_viewer={show_viewer} />
60
60
  )}
61
61
  {show_sources && (
62
62
  <>
@@ -1,14 +1,14 @@
1
1
  import React from 'react';
2
2
  import { Button, Grid } from 'semantic-ui-react';
3
- import { fetchArcGISData, setLegendColumns } from '../../utils';
3
+ import { fetchArcGISData, setLegendColumns } from '../utils';
4
4
  import { Icon } from '@plone/volto/components';
5
5
  import { serializeNodes } from '@plone/volto-slate/editor/render';
6
6
 
7
7
  import rightKeySVG from '@plone/volto/icons/right-key.svg';
8
8
  import downKeySVG from '@plone/volto/icons/down-key.svg';
9
- import { withDeviceSize } from '../../hocs';
9
+ import { withDeviceSize } from '@eeacms/volto-eea-map/hocs';
10
10
 
11
- import codeSVG from '../../static/code-line.svg';
11
+ import codeSVG from '@eeacms/volto-eea-map/static/code-line.svg';
12
12
 
13
13
  const LayerLegend = ({ data, show_viewer }) => {
14
14
  const [legendRows, setLegendRows] = React.useState([]);
@@ -92,7 +92,7 @@ const LayerLegend = ({ data, show_viewer }) => {
92
92
  );
93
93
  };
94
94
 
95
- const LegendWidget = (props) => {
95
+ const LegendView = (props) => {
96
96
  const data = React.useMemo(() => props.data, [props.data]);
97
97
  const { device = '', show_viewer = false } = props;
98
98
 
@@ -150,4 +150,4 @@ const LegendWidget = (props) => {
150
150
  );
151
151
  };
152
152
 
153
- export default withDeviceSize(React.memo(LegendWidget));
153
+ export default withDeviceSize(React.memo(LegendView));
@@ -22,16 +22,23 @@ const MODULES = [
22
22
  const Webmap = (props) => {
23
23
  const { editMode, height, id } = props;
24
24
 
25
+ const device = React.useMemo(() => props.device || {}, [props.device]);
26
+
25
27
  const data = React.useMemo(() => props.data || {}, [props.data]);
26
28
 
27
- const device = React.useMemo(() => props.device || {}, [props.device]);
28
- const {
29
- base = {},
30
- layers = {},
31
- legend = {},
32
- general = {},
33
- styles = {},
34
- } = data;
29
+ const layers = React.useMemo(() => props?.data?.layers || {}, [
30
+ props.data.layers,
31
+ ]);
32
+ const base = React.useMemo(() => props?.data?.base || {}, [props.data.base]);
33
+ const legend = React.useMemo(() => props?.data?.legend || {}, [
34
+ props.data.legend,
35
+ ]);
36
+ const general = React.useMemo(() => props?.data?.general || {}, [
37
+ props.data.general,
38
+ ]);
39
+ const styles = React.useMemo(() => props?.data?.styles || {}, [
40
+ props.data.styles,
41
+ ]);
35
42
 
36
43
  const { base_layer = '' } = base;
37
44
 
@@ -91,11 +98,26 @@ const Webmap = (props) => {
91
98
  type: 'simple', // autocasts as new SimpleRenderer()
92
99
  symbol: {
93
100
  type: 'simple-fill', // autocasts as new SimpleFillSymbol()
94
- color: styles?.symbol_color ? styles?.symbol_color : 'black',
101
+ color: styles?.symbol_color
102
+ ? styles?.symbol_color?.rgb
103
+ : {
104
+ r: 0,
105
+ g: 0,
106
+ b: 0,
107
+ a: 1,
108
+ },
109
+ //color: 'rgba(255,255,255,0.4)',
95
110
  style: 'solid',
96
111
  outline: {
97
112
  // autocasts as new SimpleLineSymbol()
98
- color: styles?.outline_color ? styles?.outline_color : 'white',
113
+ color: styles?.outline_color
114
+ ? styles?.outline_color?.rgb
115
+ : {
116
+ r: 0,
117
+ g: 0,
118
+ b: 0,
119
+ a: 1,
120
+ },
99
121
  width: styles?.outline_width ? styles?.outline_width : 1,
100
122
  },
101
123
  },
@@ -1,7 +1,6 @@
1
- export EEAMapView from './Blocks/EEAMap/View';
2
- export EEAMapEdit from './Blocks/EEAMap/Edit';
3
1
  export Webmap from './Webmap';
4
2
  export ExtraViews from './ExtraViews';
3
+ export LegendView from './LegendView';
5
4
 
6
5
  export EmbedMapView from './Blocks/EmbedEEAMap/View';
7
6
  export EmbedMapEdit from './Blocks/EmbedEEAMap/Edit';
@@ -114,7 +114,7 @@ const VisualizationEditorWidget = (props) => {
114
114
  </Modal.Actions>
115
115
  </Modal>
116
116
  )}
117
- <Webmap data={value} editMode={true} />
117
+ {!open && <Webmap data={value} editMode={true} />}
118
118
  </FormFieldWrapper>
119
119
  );
120
120
  };
@@ -78,6 +78,8 @@ const MapLayersSchema = {
78
78
  required: [],
79
79
  };
80
80
 
81
+ //style changes work only for Feature layers atm
82
+ // TODO: apply style for individual layers
81
83
  const StylesLayersSchema = ({ data = {} }) => {
82
84
  return {
83
85
  title: 'Styles Layers',
@@ -3,6 +3,7 @@ import { FormFieldWrapper, Icon } from '@plone/volto/components';
3
3
  import { Button } from 'semantic-ui-react';
4
4
  import loadable from '@loadable/component';
5
5
  import clearSVG from '@plone/volto/icons/clear.svg';
6
+ import checkSVG from '@plone/volto/icons/check.svg';
6
7
 
7
8
  const ReactColor = loadable.lib(() => import('react-color'));
8
9
 
@@ -10,17 +11,33 @@ export default (props) => {
10
11
  const { id, value, onChange, available_colors } = props;
11
12
  const [showPicker, setShowPicker] = React.useState(false);
12
13
 
14
+ const [color, setColor] = React.useState(value);
15
+
16
+ const handleChangeColor = (valColor) => {
17
+ setColor(valColor);
18
+ };
19
+
20
+ const handleConfirmColor = () => {
21
+ onChange(id, color);
22
+ setShowPicker(false);
23
+ };
24
+
25
+ const handleAbortColor = () => {
26
+ setColor(value);
27
+ setShowPicker(false);
28
+ };
29
+
13
30
  return (
14
31
  <FormFieldWrapper
15
32
  {...props}
16
33
  draggable={false}
17
34
  className="simple-color-picker-widget"
18
35
  >
19
- <div>
36
+ <div style={{ position: 'relative' }}>
20
37
  <Button.Group fluid>
21
38
  <Button
22
- color={value}
23
- style={{ backgroundColor: value }}
39
+ color={value?.hex ? value?.hex : 'black'}
40
+ style={{ backgroundColor: value?.hex ? value?.hex : 'black' }}
24
41
  onClick={() => setShowPicker(true)}
25
42
  size="small"
26
43
  fluid
@@ -35,27 +52,67 @@ export default (props) => {
35
52
  >
36
53
  <Icon name={clearSVG} size="18px" color="red" />
37
54
  </Button>
55
+ {showPicker ? (
56
+ <div
57
+ style={{
58
+ position: 'absolute',
59
+ top: '0',
60
+ zIndex: '77',
61
+ background: 'lightgrey',
62
+ display: 'flex',
63
+ flexDirection: 'column',
64
+ padding: '5px',
65
+ borderRadius: '2px',
66
+ }}
67
+ >
68
+ <ReactColor>
69
+ {({ SketchPicker }) => {
70
+ return (
71
+ <SketchPicker
72
+ width="180px"
73
+ colors={available_colors}
74
+ color={
75
+ color?.rgb
76
+ ? color.rgb
77
+ : {
78
+ r: 0,
79
+ g: 0,
80
+ b: 0,
81
+ a: 1,
82
+ }
83
+ }
84
+ onChangeComplete={(value) => {
85
+ handleChangeColor(value);
86
+ }}
87
+ ></SketchPicker>
88
+ );
89
+ }}
90
+ </ReactColor>
91
+ <Button.Group>
92
+ <Button
93
+ size="tiny"
94
+ compact
95
+ title="Reset color"
96
+ style={{ paddingLeft: '8px', paddingRight: '0px' }}
97
+ onClick={() => handleAbortColor()}
98
+ >
99
+ <Icon name={clearSVG} size="18px" />
100
+ </Button>
101
+ <Button
102
+ onClick={() => handleConfirmColor()}
103
+ color="green"
104
+ compact
105
+ size="tiny"
106
+ title="Confirm color"
107
+ >
108
+ <Icon name={checkSVG} size="18px" />
109
+ </Button>
110
+ </Button.Group>
111
+ </div>
112
+ ) : (
113
+ ''
114
+ )}
38
115
  </Button.Group>
39
-
40
- {showPicker ? (
41
- <ReactColor>
42
- {({ SketchPicker }) => {
43
- return (
44
- <SketchPicker
45
- width="180px"
46
- colors={available_colors}
47
- color={value || '#000'}
48
- onChangeComplete={(value) => {
49
- setShowPicker(false);
50
- onChange(id, value.hex);
51
- }}
52
- ></SketchPicker>
53
- );
54
- }}
55
- </ReactColor>
56
- ) : (
57
- ''
58
- )}
59
116
  </div>
60
117
  </FormFieldWrapper>
61
118
  );
package/src/index.js CHANGED
@@ -2,11 +2,13 @@ import EmbedMapView from './components/Blocks/EmbedEEAMap/View';
2
2
  import EmbedMapEdit from './components/Blocks/EmbedEEAMap/Edit';
3
3
 
4
4
  import world from '@plone/volto/icons/world.svg';
5
+
5
6
  import DataQueryWidget from './components/widgets/DataQueryWidget';
6
7
  import LayerSelectWidget from './components/widgets/LayerSelectWidget';
7
- import MapEditorWidget from './components/widgets/MapEditorWidget';
8
+
8
9
  import VisualizationEditorWidget from './components/visualization/VisualizationEditorWidget';
9
10
  import VisualizationView from './components/visualization/VisualizationView';
11
+
10
12
  import SimpleColorPickerWidget from './components/widgets/SimpleColorPickerWidget';
11
13
 
12
14
  import { data_visualizations } from './middlewares';
@@ -51,7 +53,6 @@ export default (config) => {
51
53
  ],
52
54
  };
53
55
 
54
- config.widgets.widget.map_edit_widget = MapEditorWidget;
55
56
  config.widgets.widget.map_layers_widget = LayerSelectWidget;
56
57
  config.widgets.widget.data_query_widget = DataQueryWidget;
57
58
  config.widgets.widget.simple_color_picker_widget = SimpleColorPickerWidget;
package/src/utils.js CHANGED
@@ -30,4 +30,97 @@ const fetchArcGISData = async (url) => {
30
30
  return data;
31
31
  };
32
32
 
33
- export { setLegendColumns, fetchArcGISData };
33
+ const applyQueriesToMapLayers = (
34
+ map_visualization,
35
+ block_data_query_params,
36
+ enable_queries,
37
+ ) => {
38
+ //break reference to the original map_visualization object
39
+ //so i safely manipulate data
40
+ var altMapData = map_visualization
41
+ ? JSON.parse(JSON.stringify(map_visualization))
42
+ : '';
43
+
44
+ var rules = [];
45
+ if (
46
+ enable_queries &&
47
+ block_data_query_params &&
48
+ block_data_query_params.length > 0 &&
49
+ altMapData.layers &&
50
+ altMapData.layers.map_layers &&
51
+ altMapData.layers.map_layers.length > 0
52
+ ) {
53
+ altMapData.layers.map_layers.forEach((l, j) => {
54
+ block_data_query_params.forEach((param, i) => {
55
+ const matchingFields =
56
+ l.map_layer && l.map_layer.fields && l.map_layer.fields.length > 0
57
+ ? l.map_layer.fields.filter(
58
+ (field, k) =>
59
+ field.name === param.alias || field.name === param.i,
60
+ )
61
+ : [];
62
+ matchingFields.forEach((m, i) => {
63
+ const newRules = param.v
64
+ ? param.v.map((paramVal, i) => {
65
+ return {
66
+ field: m.name,
67
+ operator: '=',
68
+ value: paramVal,
69
+ };
70
+ })
71
+ : [];
72
+ const concatRules = rules.concat(newRules);
73
+ const filteredRules = concatRules.filter(
74
+ (v, i, a) =>
75
+ a.findLastIndex(
76
+ (v2) => v2.field === v.field && v2.value === v.value,
77
+ ) === i,
78
+ );
79
+ rules = filteredRules;
80
+ });
81
+ });
82
+ let autoQuery = {
83
+ combinator: 'or',
84
+ rules,
85
+ };
86
+ altMapData.layers.map_layers[j].map_layer.query = autoQuery;
87
+ });
88
+ }
89
+ return altMapData;
90
+ };
91
+
92
+ const updateBlockQueryFromPageQuery = (data_query, data_query_params) => {
93
+ var pageDataQuery = JSON.parse(JSON.stringify(data_query));
94
+ var blockDataQuery = data_query_params
95
+ ? JSON.parse(JSON.stringify(data_query_params))
96
+ : '';
97
+ var newDataQuery = pageDataQuery.map((parameter, index) => {
98
+ //check if the parameter exists in data and has value
99
+ // then get its alias value and update it
100
+ //check if data_query param value is changed
101
+ //and change it in block data
102
+ if (
103
+ blockDataQuery &&
104
+ blockDataQuery[index] &&
105
+ parameter.i &&
106
+ blockDataQuery[index].i &&
107
+ parameter.i === blockDataQuery[index].i
108
+ ) {
109
+ return {
110
+ ...parameter,
111
+ alias: blockDataQuery[index]?.alias ? blockDataQuery[index]?.alias : '',
112
+ v: parameter?.v ? parameter?.v : '',
113
+ };
114
+ }
115
+
116
+ return parameter;
117
+ });
118
+ return newDataQuery;
119
+ };
120
+
121
+ export {
122
+ setLegendColumns,
123
+ fetchArcGISData,
124
+ applyQueriesToMapLayers,
125
+ updateBlockQueryFromPageQuery,
126
+ };
@@ -1,65 +0,0 @@
1
- import React from 'react';
2
-
3
- import { connect } from 'react-redux';
4
- import { compose } from 'redux';
5
-
6
- import { SidebarPortal } from '@plone/volto/components';
7
- import BlockDataForm from '@plone/volto/components/manage/Form/BlockDataForm';
8
-
9
- import { Schema } from './Schema';
10
- import View from './View';
11
- import { getContent } from '@plone/volto/actions';
12
-
13
- import { addPrivacyProtectionToSchema } from '@eeacms/volto-embed';
14
- import '../../../styles/map.css';
15
-
16
- const Edit = (props) => {
17
- const { block, data, onChangeBlock, selected, id } = props;
18
- const schema = React.useMemo(() => Schema(props), [props]);
19
-
20
- React.useEffect(() => {
21
- if (
22
- !data.data_query_params ||
23
- props.data_query !== data.data_query_params
24
- ) {
25
- onChangeBlock(block, {
26
- ...data,
27
- data_query_params: props.data_query,
28
- });
29
- }
30
- // eslint-disable-next-line react-hooks/exhaustive-deps
31
- }, [props.data_query, block, data]);
32
-
33
- return (
34
- <div>
35
- <View data={data} id={id} />
36
- <SidebarPortal selected={selected}>
37
- <BlockDataForm
38
- block={block}
39
- title={schema.title}
40
- schema={addPrivacyProtectionToSchema(schema)}
41
- onChangeField={(id, value) => {
42
- onChangeBlock(block, {
43
- ...data,
44
- [id]: value,
45
- });
46
- }}
47
- formData={data}
48
- />
49
- </SidebarPortal>
50
- </div>
51
- );
52
- };
53
-
54
- export default compose(
55
- connect(
56
- (state, props) => ({
57
- data_query: state.content.data.data_query,
58
- data_provenance:
59
- state.content.subrequests?.[props.id]?.data?.data_provenance,
60
- }),
61
- {
62
- getContent,
63
- },
64
- ),
65
- )(Edit);
@@ -1,55 +0,0 @@
1
- export const Schema = (props) => {
2
- return {
3
- title: 'EEA Map Block',
4
- fieldsets: [
5
- {
6
- id: 'default',
7
- title: 'Default',
8
- fields: [
9
- 'map_data',
10
- 'description',
11
- 'height',
12
- 'show_legend',
13
- 'show_download',
14
- 'show_viewer',
15
- 'show_sources',
16
- 'data_query_params',
17
- ],
18
- },
19
- ],
20
- properties: {
21
- show_sources: {
22
- title: 'Show sources',
23
- type: 'boolean',
24
- },
25
- height: {
26
- title: 'Height',
27
- type: 'number',
28
- },
29
- description: {
30
- title: 'Description',
31
- widget: 'slate',
32
- },
33
- map_data: {
34
- title: 'Edit map',
35
- description: 'Open the map customization interface',
36
- widget: 'map_edit_widget',
37
- },
38
- show_legend: {
39
- title: 'Show legend',
40
- type: 'boolean',
41
- },
42
-
43
- show_viewer: {
44
- title: 'Show web viewer',
45
- type: 'boolean',
46
- },
47
- data_query_params: {
48
- title: 'Query parameters',
49
- description: 'ddafdfas',
50
- widget: 'data_query_widget',
51
- },
52
- },
53
- required: [],
54
- };
55
- };
@@ -1,44 +0,0 @@
1
- import React from 'react';
2
-
3
- import { connect } from 'react-redux';
4
- import { compose } from 'redux';
5
-
6
- import Webmap from '../../Webmap';
7
- import ExtraViews from '../../ExtraViews';
8
-
9
- import { PrivacyProtection } from '@eeacms/volto-embed';
10
- import { getContent } from '@plone/volto/actions';
11
-
12
- const View = (props) => {
13
- const { data, id, path } = props || {};
14
- const { map_data = {}, height = '' } = data;
15
-
16
- React.useEffect(() => {
17
- if (path) {
18
- props.getContent(path, null, id);
19
- }
20
- // eslint-disable-next-line react-hooks/exhaustive-deps
21
- }, [path]);
22
-
23
- return (
24
- <div>
25
- <PrivacyProtection data={data} {...props}>
26
- <Webmap data={map_data} height={height} id={id} />
27
- <ExtraViews data={data} />
28
- </PrivacyProtection>
29
- </div>
30
- );
31
- };
32
-
33
- export default compose(
34
- connect(
35
- (state, props) => ({
36
- data_query: state.content.subrequests?.[props.id]?.data?.data_query,
37
- data_provenance:
38
- state.content.subrequests?.[props.id]?.data?.data_provenance,
39
- }),
40
- {
41
- getContent,
42
- },
43
- ),
44
- )(View);
@@ -1,96 +0,0 @@
1
- import React from 'react';
2
- import { Modal, Button, Grid } from 'semantic-ui-react';
3
- import Webmap from '../Webmap';
4
-
5
- import { FormFieldWrapper, InlineForm } from '@plone/volto/components';
6
-
7
- import PanelsSchema from './panelsSchema';
8
-
9
- const MapEditorWidget = (props) => {
10
- const [open, setOpen] = React.useState(false);
11
- const { onChange = {}, id } = props;
12
- const block = React.useMemo(() => props.block, [props.block]);
13
- const value = React.useMemo(() => props.value, [props.value]);
14
-
15
- const [intValue, setIntValue] = React.useState(value);
16
-
17
- const dataForm = { map_data: intValue };
18
- const handleApplyChanges = () => {
19
- onChange(id, intValue);
20
-
21
- //set map data for screenshot
22
- // if (intValue.layers?.map_layers[0].map_layer?.map_service_url) {
23
- // onChange(
24
- // 'url',
25
- // `${intValue.layers?.map_layers[0].map_layer?.map_service_url}?f=jsapi`,
26
- // );
27
- // }
28
- setOpen(false);
29
- };
30
-
31
- const handleClose = () => {
32
- setIntValue(value);
33
- setOpen(false);
34
- };
35
-
36
- const handleChangeField = (id, fieldVal) => {
37
- setIntValue(fieldVal);
38
- };
39
-
40
- let schema = PanelsSchema({ data: dataForm });
41
- return (
42
- <FormFieldWrapper {...props}>
43
- <Modal
44
- id="map-editor-modal"
45
- className="map-editor-modal"
46
- onClose={handleClose}
47
- onOpen={() => setOpen(true)}
48
- open={open}
49
- trigger={
50
- <Button size="tiny" className="map-modal-trigger-button">
51
- Open Map Editor
52
- </Button>
53
- }
54
- >
55
- <Modal.Content scrolling>
56
- <Grid stackable reversed="mobile vertically tablet vertically">
57
- <Grid.Column
58
- mobile={12}
59
- tablet={12}
60
- computer={5}
61
- className="map-editor-column"
62
- >
63
- <InlineForm
64
- block={block}
65
- schema={schema}
66
- onChangeField={(id, value) => {
67
- handleChangeField(id, value);
68
- }}
69
- formData={dataForm}
70
- />
71
- </Grid.Column>
72
- <Grid.Column mobile={12} tablet={12} computer={7}>
73
- <div className="webmap-container">
74
- <Webmap data={intValue} editMode={true} />
75
- </div>
76
- </Grid.Column>
77
- </Grid>
78
- </Modal.Content>
79
- <Modal.Actions>
80
- <Grid>
81
- <Grid.Row>
82
- <div className="map-edit-actions-container">
83
- <Button onClick={handleClose}>Close</Button>
84
- <Button color="green" onClick={handleApplyChanges}>
85
- Apply changes
86
- </Button>
87
- </div>
88
- </Grid.Row>
89
- </Grid>
90
- </Modal.Actions>
91
- </Modal>
92
- </FormFieldWrapper>
93
- );
94
- };
95
-
96
- export default MapEditorWidget;
@@ -1,151 +0,0 @@
1
- import { base_layers } from '../../constants';
2
-
3
- const BaseLayerSchema = {
4
- title: 'Base Layer',
5
- fieldsets: [
6
- {
7
- id: 'base',
8
- title: 'Base Layer',
9
- fields: ['base_layer'],
10
- },
11
- ],
12
- properties: {
13
- base_layer: {
14
- title: 'Base Layer',
15
- choices: base_layers,
16
- },
17
- },
18
- required: [],
19
- };
20
-
21
- const LayerSchema = {
22
- title: 'Layer',
23
- fieldsets: [
24
- {
25
- id: 'default',
26
- title: 'Layer',
27
- fields: ['map_layer'],
28
- },
29
- ],
30
- properties: {
31
- map_layer: {
32
- title: 'Map layer configuration',
33
- widget: 'map_layers_widget',
34
- },
35
- },
36
- required: [],
37
- };
38
-
39
- const MapLayersSchema = {
40
- title: 'Map Layers',
41
- fieldsets: [
42
- {
43
- id: 'default',
44
- title: 'Map Data',
45
- fields: ['map_layers'],
46
- },
47
- ],
48
- properties: {
49
- map_layers: {
50
- title: 'Map Layers',
51
- description: 'Add/Edit Map Layers',
52
- widget: 'object_list',
53
- schema: LayerSchema,
54
- },
55
- },
56
- required: [],
57
- };
58
-
59
- const GeneralSchema = ({ data = {} }) => {
60
- const centerOnExtent = data?.map_data?.general?.centerOnExtent;
61
-
62
- return {
63
- title: 'General',
64
- fieldsets: [
65
- {
66
- id: 'default',
67
- title: 'Zoom',
68
- fields: [
69
- 'print_position',
70
- 'zoom_position',
71
- 'centerOnExtent',
72
- ...(!centerOnExtent ? ['zoom_level', 'long', 'lat'] : []),
73
- ],
74
- },
75
- ],
76
- properties: {
77
- centerOnExtent: {
78
- title: 'Center on extent',
79
- type: 'boolean',
80
- description:
81
- 'This will override latitude/longitude/zoom level and will lock zoom/moving the map.',
82
- },
83
- zoom_position: {
84
- title: 'Zoom position',
85
- choices: ['bottom-right', 'bottom-left', 'top-right', 'top-left'].map(
86
- (n) => {
87
- return [n, n];
88
- },
89
- ),
90
- },
91
- zoom_level: {
92
- title: 'Zoom level',
93
- type: 'number',
94
- },
95
- long: {
96
- title: 'Longitude',
97
- type: 'number',
98
- },
99
- lat: {
100
- title: 'Latitude',
101
- type: 'number',
102
- },
103
-
104
- print_position: {
105
- title: 'Print position',
106
- choices: ['bottom-right', 'bottom-left', 'top-right', 'top-left'].map(
107
- (n) => {
108
- return [n, n];
109
- },
110
- ),
111
- },
112
- },
113
- required: [],
114
- };
115
- };
116
-
117
- export default ({ data = {} }) => {
118
- const generalSchema = GeneralSchema({ data });
119
-
120
- return {
121
- title: 'Map Editor',
122
- fieldsets: [
123
- {
124
- id: 'default',
125
- title: 'Map Editor Sections',
126
- fields: ['map_data'],
127
- },
128
- ],
129
- properties: {
130
- map_data: {
131
- title: 'Panels',
132
- widget: 'object_types_widget',
133
- schemas: [
134
- {
135
- id: 'general',
136
- schema: generalSchema,
137
- },
138
- {
139
- id: 'base',
140
- schema: BaseLayerSchema,
141
- },
142
- {
143
- id: 'layers',
144
- schema: MapLayersSchema,
145
- },
146
- ],
147
- },
148
- },
149
- required: [],
150
- };
151
- };