@eeacms/volto-embed 3.0.0 → 4.0.1

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,8 +4,34 @@ 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
+ #### [4.0.1](https://github.com/eea/volto-embed/compare/4.0.0...4.0.1)
8
+
9
+ - dedupe getFiltered method, use from datablocks [`7f7b1b5`](https://github.com/eea/volto-embed/commit/7f7b1b51b280edc856e19d6b02a37f3f8894bd04)
10
+ - fix regex [`1dc059f`](https://github.com/eea/volto-embed/commit/1dc059fa58f7a1789e4b570d1631226b404fa805)
11
+ - early return [`467e6fc`](https://github.com/eea/volto-embed/commit/467e6fc2c053d2e17526ad6fb4cbf34c2bb8abe1)
12
+ - safari: don't use lookbehind [`a4e4ece`](https://github.com/eea/volto-embed/commit/a4e4ece2891a5e2bcbf7f47a4345d0adca5258e6)
13
+
14
+ ### [4.0.0](https://github.com/eea/volto-embed/compare/3.0.1...4.0.0)
15
+
16
+ > 5 April 2022
17
+
18
+ - Breaking. Volto 15.x compatibility [`#22`](https://github.com/eea/volto-embed/pull/22)
19
+ - Prettier [`fffa1c9`](https://github.com/eea/volto-embed/commit/fffa1c9f42c9dacc7de1fed730e0a4494c04d2f8)
20
+ - Prettier [`f9ca05d`](https://github.com/eea/volto-embed/commit/f9ca05d3c55d204080f8769bd7d556b4d8f0ce21)
21
+ - Breaking changes. Bumped to version 4.0.0 [`eb78abf`](https://github.com/eea/volto-embed/commit/eb78abf98103ee8831814b3df4c441279c586da2)
22
+ - Volto 15.x compatibility: updated react-cookie library [`a480372`](https://github.com/eea/volto-embed/commit/a480372f47e6e34d6f3e14d7b54b345dc83fd328)
23
+
24
+ #### [3.0.1](https://github.com/eea/volto-embed/compare/3.0.0...3.0.1)
25
+
26
+ > 11 February 2022
27
+
28
+ - fix query case [`#20`](https://github.com/eea/volto-embed/pull/20)
29
+
7
30
  #### [3.0.0](https://github.com/eea/volto-embed/compare/3.0.0-beta.0...3.0.0)
8
31
 
32
+ > 7 February 2022
33
+
34
+ - Make this compatible with volto-datablocks@3.x [`#19`](https://github.com/eea/volto-embed/pull/19)
9
35
 
10
36
  #### [3.0.0-beta.0](https://github.com/eea/volto-embed/compare/2.0.11...3.0.0-beta.0)
11
37
 
package/Jenkinsfile CHANGED
@@ -184,10 +184,10 @@ pipeline {
184
184
  unstash "xunit-reports"
185
185
  unstash "cypress-coverage"
186
186
  def scannerHome = tool 'SonarQubeScanner';
187
- def nodeJS = tool 'NodeJS11';
187
+ def nodeJS = tool 'NodeJS';
188
188
  withSonarQubeEnv('Sonarqube') {
189
189
  sh '''sed -i "s#/opt/frontend/my-volto-project/src/addons/${GIT_NAME}/##g" xunit-reports/coverage/lcov.info'''
190
- sh "export PATH=$PATH:${scannerHome}/bin:${nodeJS}/bin; sonar-scanner -Dsonar.javascript.lcov.reportPaths=./xunit-reports/coverage/lcov.info,./cypress-coverage/coverage/lcov.info -Dsonar.sources=./src -Dsonar.projectKey=$GIT_NAME-$BRANCH_NAME -Dsonar.projectVersion=$BRANCH_NAME-$BUILD_NUMBER"
190
+ sh "export PATH=${scannerHome}/bin:${nodeJS}/bin:$PATH; sonar-scanner -Dsonar.javascript.lcov.reportPaths=./xunit-reports/coverage/lcov.info,./cypress-coverage/coverage/lcov.info -Dsonar.sources=./src -Dsonar.projectKey=$GIT_NAME-$BRANCH_NAME -Dsonar.projectVersion=$BRANCH_NAME-$BUILD_NUMBER"
191
191
  sh '''try=2; while [ \$try -gt 0 ]; do curl -s -XPOST -u "${SONAR_AUTH_TOKEN}:" "${SONAR_HOST_URL}api/project_tags/set?project=${GIT_NAME}-${BRANCH_NAME}&tags=${SONARQUBE_TAGS},${BRANCH_NAME}" > set_tags_result; if [ \$(grep -ic error set_tags_result ) -eq 0 ]; then try=0; else cat set_tags_result; echo "... Will retry"; sleep 60; try=\$(( \$try - 1 )); fi; done'''
192
192
  }
193
193
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-embed",
3
- "version": "3.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Embed external content",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -16,6 +16,7 @@ import aheadSVG from '@plone/volto/icons/ahead.svg';
16
16
  import mapsBlockSVG from '@plone/volto/components/manage/Blocks/Maps/block-maps.svg';
17
17
  import schema from './schema';
18
18
  import { addPrivacyProtectionToSchema } from '../PrivacyProtection';
19
+ import { PrivacyProtection } from '../PrivacyProtection';
19
20
 
20
21
  const messages = defineMessages({
21
22
  MapsBlockInputPlaceholder: {
@@ -182,15 +183,20 @@ class Edit extends Component {
182
183
  'full-width': this.props.data.align === 'full',
183
184
  })}
184
185
  >
185
- <iframe
186
- title={this.props.intl.formatMessage(
187
- messages.GoogleMapsEmbeddedBlock,
188
- )}
189
- src={this.props.data.url}
190
- className="google-map"
191
- frameBorder="0"
192
- allowFullScreen
193
- />
186
+ <PrivacyProtection
187
+ data={this.props.data}
188
+ editable={this.props.editable}
189
+ >
190
+ <iframe
191
+ title={this.props.intl.formatMessage(
192
+ messages.GoogleMapsEmbeddedBlock,
193
+ )}
194
+ src={this.props.data.url}
195
+ className="google-map"
196
+ frameBorder="0"
197
+ allowFullScreen
198
+ />
199
+ </PrivacyProtection>
194
200
  </div>
195
201
  ) : (
196
202
  <Message>
@@ -22,7 +22,7 @@ const messages = defineMessages({
22
22
  * @extends Component
23
23
  */
24
24
 
25
- const View = ({ data, intl }) => {
25
+ const View = ({ data, intl, id }) => {
26
26
  return (
27
27
  <div
28
28
  className={cx(
@@ -42,7 +42,7 @@ const View = ({ data, intl }) => {
42
42
  })}
43
43
  style={{ height: '100%' }}
44
44
  >
45
- <PrivacyProtection data={data}>
45
+ <PrivacyProtection data={data} id={id}>
46
46
  <iframe
47
47
  title={intl.formatMessage(messages.EmbededGoogleMaps)}
48
48
  src={data.url}
@@ -1,9 +1,9 @@
1
1
  import React, { useState } from 'react';
2
+ import { compose } from 'redux';
2
3
  import { useSelector } from 'react-redux';
3
4
  import VisibilitySensor from 'react-visibility-sensor';
4
5
  import { Placeholder, Dimmer, Loader } from 'semantic-ui-react';
5
- import cookie from 'react-cookie';
6
-
6
+ import { withCookies } from 'react-cookie';
7
7
  //import { find, without } from 'lodash';
8
8
  import { serializeNodes } from 'volto-slate/editor/render';
9
9
  import { Button, Checkbox } from 'semantic-ui-react';
@@ -13,7 +13,10 @@ import { toast } from 'react-toastify';
13
13
  import config from '@plone/volto/registry';
14
14
  import { getBaseUrl } from '@plone/volto/helpers';
15
15
  import { Toast } from '@plone/volto/components';
16
- import { getConnectedDataParametersForContext } from '@eeacms/volto-datablocks/helpers';
16
+ import {
17
+ getConnectedDataParametersForContext,
18
+ getFilteredURL,
19
+ } from '@eeacms/volto-datablocks/helpers';
17
20
 
18
21
  import { createImageUrl } from './helpers';
19
22
  import { ProtectionSchema } from './schema';
@@ -38,29 +41,29 @@ const getExpDays = () =>
38
41
  ? config.settings.embedCookieExpirationDays
39
42
  : 90;
40
43
 
41
- function saveCookie(domain_key) {
44
+ function saveCookie(domain_key, cookies) {
42
45
  const date = new Date();
43
46
  date.setDate(date.getDate() + getExpDays());
44
47
 
45
- cookie.save(key(domain_key), 'true', {
48
+ cookies.set(key(domain_key), 'true', {
46
49
  path: '/',
47
50
  expires: date,
48
51
  });
49
52
  }
50
53
 
51
- function canShow(domain_key) {
52
- return cookie.load(key(domain_key)) === 'true';
54
+ function canShow(domain_key, cookies) {
55
+ return cookies.get(key(domain_key)) === 'true';
53
56
  }
54
57
 
55
- const cookieExist = (domain_key) => cookie.load(key(domain_key));
58
+ const cookieExist = (domain_key, cookies) => cookies.get(key(domain_key));
56
59
 
57
- const CookieWatcher = (cookie, pollingRate = 250) => {
60
+ const CookieWatcher = (domain_key, cookies, pollingRate = 250) => {
58
61
  // state for cookie existence
59
- const [exist, setExist] = useState(cookieExist(cookie));
62
+ const [exist, setExist] = useState(cookieExist(domain_key, cookies));
60
63
 
61
64
  React.useEffect(() => {
62
65
  const interval = setInterval(
63
- () => setExist(cookieExist(cookie)),
66
+ () => setExist(cookieExist(domain_key, cookies)),
64
67
  pollingRate,
65
68
  );
66
69
  return () => clearInterval(interval);
@@ -69,196 +72,168 @@ const CookieWatcher = (cookie, pollingRate = 250) => {
69
72
  return exist;
70
73
  };
71
74
 
72
- const getFilteredURL = (url, connected_data_parameters = []) => {
73
- if (!connected_data_parameters?.length) return url;
74
- let decodedURL = decodeURIComponent(url);
75
- const queries = decodedURL.match(/(?<=(<<))(.*?)(?=(>>))/g);
76
- if (!queries.length) return url;
77
- const keys = connected_data_parameters.map((param) => param.i);
78
- for (let poz in queries) {
79
- const key = queries[poz];
80
- const paramPoz = keys.indexOf(key);
81
- if (paramPoz > -1) {
82
- decodedURL = decodedURL.replace(
83
- `<<${key}>>`,
84
- connected_data_parameters[paramPoz].v[0],
85
- );
86
-
87
- continue;
88
- }
89
- }
90
- return decodedURL;
91
- };
92
-
93
- export default injectIntl(
94
- ({
95
- children,
96
- data = {},
97
- id,
98
- isEditMode,
99
- onChangeBlock,
100
- intl,
101
- path,
102
- properties,
103
- ...rest
104
- }) => {
105
- const { dataprotection = {}, height } = data;
106
- const { background_image: bgImg, enabled = false } = dataprotection;
107
- const [image, setImage] = React.useState(null);
108
- const [visible, setVisibility] = useState(false);
109
- const defaultShow = canShow(dataprotection.privacy_cookie_key);
110
- const [show, setShow] = useState(defaultShow);
111
- const [remember, setRemember] = useState(
112
- cookieExist(dataprotection.privacy_cookie_key) ? defaultShow : true,
75
+ const PrivacyProtection = (props) => {
76
+ const { children, data = {}, id, editable, intl, path, cookies } = props;
77
+ const {
78
+ enabled = false,
79
+ privacy_statement,
80
+ background_image: bgImg,
81
+ privacy_cookie_key = 'esri-maps',
82
+ } = data.dataprotection || {};
83
+
84
+ const [image, setImage] = React.useState(null);
85
+ const [visible, setVisibility] = useState(false);
86
+ const defaultShow = canShow(privacy_cookie_key, cookies);
87
+ const [show, setShow] = useState(defaultShow);
88
+ const [remember, setRemember] = useState(
89
+ cookieExist(privacy_cookie_key, cookies) ? defaultShow : true,
90
+ );
91
+ const dispatch = useDispatch();
92
+ const checkExistance = CookieWatcher(privacy_cookie_key, cookies);
93
+ const connected_data_parameters = useSelector((state) => {
94
+ return getConnectedDataParametersForContext(
95
+ state?.connected_data_parameters,
96
+ state.router?.location?.pathname,
113
97
  );
114
- const dispatch = useDispatch();
115
- const checkExistance = CookieWatcher(dataprotection.privacy_cookie_key);
116
- const connected_data_parameters = useSelector((state) => {
117
- return getConnectedDataParametersForContext(
118
- state?.connected_data_parameters,
119
- state.router?.location?.pathname,
120
- );
121
- });
98
+ });
99
+ const url = getFilteredURL(data.url, connected_data_parameters);
122
100
 
123
- const url = getFilteredURL(data.url, connected_data_parameters);
101
+ React.useEffect(() => {
102
+ if (bgImg) {
103
+ setImage(createImageUrl(bgImg)); //create imageUrl from uploaded image
104
+ }
105
+ }, [bgImg]);
124
106
 
125
- const styles = {
126
- minHeight: `${height || 200}px`,
127
- position: 'relative',
128
- };
129
- React.useEffect(() => {
130
- if (bgImg) {
131
- setImage(createImageUrl(bgImg)); //create imageUrl from uploaded image
107
+ //Effect hook for polling the cookie_key
108
+ React.useEffect(
109
+ () => {
110
+ if (!editable && defaultShow) {
111
+ setShow(true);
132
112
  }
133
- }, [bgImg]);
113
+ },
114
+ // eslint-disable-next-line react-hooks/exhaustive-deps
115
+ [checkExistance],
116
+ );
134
117
 
135
- //Effect hook for polling the cookie_key
136
- React.useEffect(
137
- () => {
138
- if (!isEditMode && defaultShow) {
139
- setShow(true);
140
- }
141
- },
142
- // eslint-disable-next-line react-hooks/exhaustive-deps
143
- [checkExistance],
144
- );
145
-
146
- //screenshot api
147
- React.useEffect(() => {
148
- if (enabled && !bgImg && !show) {
149
- fetch(
150
- `${getBaseUrl(
151
- '',
152
- )}/cors-proxy/https://screenshot.eea.europa.eu/api/v1/retrieve_image_for_url?url=${encodeURIComponent(
153
- url,
154
- )}&w=1920&waitfor=4000`,
155
- )
156
- .then((e) => e.blob())
157
- .then((blob) => {
158
- setImage(URL.createObjectURL(blob));
159
- if (isEditMode) {
160
- toast.success(
161
- <Toast
162
- success
163
- title={intl.formatMessage(messages.success)}
164
- content={intl.formatMessage(messages.image)}
165
- />,
166
- );
167
- }
168
- })
169
- .catch(() => {
170
- if (__DEVELOPMENT__) {
171
- /* eslint-disable-next-line */
172
- console.log('Please enable your VPN!');
173
- }
174
- });
175
- }
176
- }, [enabled, url, path, dispatch, bgImg, show, intl, isEditMode]);
118
+ //screenshot api
119
+ React.useEffect(() => {
120
+ if (enabled && !bgImg && !show) {
121
+ fetch(
122
+ `${getBaseUrl(
123
+ '',
124
+ )}/cors-proxy/https://screenshot.eea.europa.eu/api/v1/retrieve_image_for_url?url=${encodeURIComponent(
125
+ url,
126
+ )}&w=1920&waitfor=4000`,
127
+ )
128
+ .then((e) => e.blob())
129
+ .then((blob) => {
130
+ setImage(URL.createObjectURL(blob));
131
+ if (editable) {
132
+ toast.success(
133
+ <Toast
134
+ success
135
+ title={intl.formatMessage(messages.success)}
136
+ content={intl.formatMessage(messages.image)}
137
+ />,
138
+ );
139
+ }
140
+ })
141
+ .catch(() => {
142
+ if (__DEVELOPMENT__) {
143
+ /* eslint-disable-next-line */
144
+ console.log('Please enable your VPN!');
145
+ }
146
+ });
147
+ }
148
+ }, [enabled, url, path, dispatch, bgImg, show, intl, editable]);
149
+
150
+ return (
151
+ <VisibilitySensor
152
+ onChange={(isVisible) => {
153
+ !visible && isVisible && setVisibility(true);
154
+ }}
155
+ partialVisibility={true}
156
+ offset={{ bottom: 200 }}
157
+ >
158
+ {visible ? (
159
+ <div
160
+ className="privacy-protection-wrapper"
161
+ style={{ position: 'relative', minHeight: '200px' }}
162
+ >
163
+ {!enabled || show ? (
164
+ children
165
+ ) : !__DEVELOPMENT__ && !image ? (
166
+ <Dimmer active>
167
+ <Loader />
168
+ </Dimmer>
169
+ ) : (
170
+ <div
171
+ className="privacy-protection"
172
+ style={
173
+ image
174
+ ? {
175
+ backgroundImage: `url(${image})`,
176
+ backgroundRepeat: 'no-repeat',
177
+ backgroundSize: 'cover',
178
+ backgroundPosition: 'center -70px',
179
+ }
180
+ : {}
181
+ }
182
+ >
183
+ <div className="overlay">
184
+ <div className="wrapped">
185
+ <div className="privacy-button">
186
+ <Button
187
+ primary
188
+ onClick={() => {
189
+ setShow(true);
190
+ if (remember) {
191
+ saveCookie(privacy_cookie_key, cookies);
192
+ }
193
+ }}
194
+ >
195
+ Show external content
196
+ </Button>
197
+ </div>
177
198
 
178
- return (
179
- <VisibilitySensor
180
- onChange={(isVisible) => {
181
- !visible && isVisible && setVisibility(true);
182
- }}
183
- partialVisibility={true}
184
- offset={{ bottom: 200 }}
185
- >
186
- {visible ? (
187
- <div className="privacy-protection-wrapper" style={styles}>
188
- {!dataprotection.enabled || show ? (
189
- children
190
- ) : !__DEVELOPMENT__ && !image ? (
191
- <Dimmer active>
192
- <Loader />
193
- </Dimmer>
194
- ) : (
195
- <div
196
- className="privacy-protection"
197
- {...rest}
198
- style={
199
- image
200
- ? {
201
- backgroundImage: `url(${image})`,
202
- backgroundRepeat: 'no-repeat',
203
- backgroundSize: 'cover',
204
- backgroundPosition: 'center -70px',
205
- }
206
- : {}
207
- }
208
- >
209
- <div className="overlay">
210
- <div className="wrapped">
211
- <div className="privacy-button">
212
- <Button
213
- primary
214
- onClick={() => {
215
- setShow(true);
216
- if (remember) {
217
- saveCookie(dataprotection.privacy_cookie_key);
218
- }
199
+ {!editable && (
200
+ <div className="privacy-toggle">
201
+ <Checkbox
202
+ toggle
203
+ label="Remember my choice"
204
+ id={`remember-choice-${id}`}
205
+ onChange={(ev, { checked }) => {
206
+ setRemember(checked);
219
207
  }}
220
- >
221
- Show external content
222
- </Button>
208
+ checked={remember}
209
+ />
223
210
  </div>
224
-
225
- {!isEditMode && (
226
- <div className="privacy-toggle">
227
- <Checkbox
228
- toggle
229
- label="Remember my choice"
230
- id={`remember-choice-${id}`}
231
- onChange={(ev, { checked }) => {
232
- setRemember(checked);
233
- }}
234
- checked={remember}
235
- />
236
- </div>
211
+ )}
212
+
213
+ <p className="discreet">
214
+ Your choice will be saved in a cookie managed by{' '}
215
+ {config.settings.ownDomain || '.eea.europa.eu'} that will
216
+ expire in {getExpDays()} days.
217
+ </p>
218
+ <p className="discreet">
219
+ {serializeNodes(
220
+ privacy_statement ||
221
+ ProtectionSchema().properties.privacy_statement
222
+ .defaultValue,
237
223
  )}
238
-
239
- <p className="discreet">
240
- Your choice will be saved in a cookie managed by{' '}
241
- {config.settings.ownDomain || '.eea.europa.eu'} that will
242
- expire in {getExpDays()} days.
243
- </p>
244
- <p className="discreet">
245
- {serializeNodes(
246
- dataprotection.privacy_statement ||
247
- ProtectionSchema().properties.privacy_statement
248
- .defaultValue,
249
- )}
250
- </p>
251
- </div>
224
+ </p>
252
225
  </div>
253
226
  </div>
254
- )}
255
- </div>
256
- ) : (
257
- <Placeholder style={{ height: '100%', width: '100%' }}>
258
- <Placeholder.Image rectangular />
259
- </Placeholder>
260
- )}
261
- </VisibilitySensor>
262
- );
263
- },
264
- );
227
+ </div>
228
+ )}
229
+ </div>
230
+ ) : (
231
+ <Placeholder style={{ height: '100%', width: '100%' }}>
232
+ <Placeholder.Image rectangular />
233
+ </Placeholder>
234
+ )}
235
+ </VisibilitySensor>
236
+ );
237
+ };
238
+
239
+ export default compose(injectIntl, withCookies)(PrivacyProtection);
@@ -18,7 +18,7 @@
18
18
  }
19
19
 
20
20
  .privacy-button {
21
- margin-top: 2rem;
21
+ margin-top: 0.5rem;
22
22
  }
23
23
 
24
24
  .privacy-toggle {