From f5f0b77768d9d86ce6d32e42346e95bb6e25e729 Mon Sep 17 00:00:00 2001 From: Giulia Ghisini Date: Fri, 15 Dec 2023 13:25:07 +0100 Subject: [PATCH] fix: gdpr privacy conditional embed to work in diff view --- package.json | 2 +- .../ConditionalEmbed/ConditionalEmbed.jsx | 135 ------------------ yarn.lock | 10 +- 3 files changed, 6 insertions(+), 141 deletions(-) delete mode 100644 src/customizations/volto-gdpr-privacy/components/ConditionalEmbed/ConditionalEmbed.jsx diff --git a/package.json b/package.json index c26b52a2b..015826480 100644 --- a/package.json +++ b/package.json @@ -146,7 +146,7 @@ "volto-editablefooter": "5.0.1", "volto-feedback": "0.1.5", "volto-form-block": "3.1.0", - "volto-gdpr-privacy": "2.1.0", + "volto-gdpr-privacy": "2.1.1", "volto-google-analytics": "2.0.0", "volto-multilingual-widget": "3.0.0", "volto-querywidget-with-browser": "0.4.0", diff --git a/src/customizations/volto-gdpr-privacy/components/ConditionalEmbed/ConditionalEmbed.jsx b/src/customizations/volto-gdpr-privacy/components/ConditionalEmbed/ConditionalEmbed.jsx deleted file mode 100644 index b0f7326c1..000000000 --- a/src/customizations/volto-gdpr-privacy/components/ConditionalEmbed/ConditionalEmbed.jsx +++ /dev/null @@ -1,135 +0,0 @@ -/* -CUSTOMIZATIONS - - permit render if server, cannot use in history diff otherwise -*/ - -import React, { useEffect, useState } from 'react'; -import { useSelector, useDispatch } from 'react-redux'; -import { useIntl, defineMessages } from 'react-intl'; -import { useLocation } from 'react-router-dom'; -import { - displayBanner, - updateGdprPrivacyConsent, -} from 'volto-gdpr-privacy/actions'; - -import { - usePanelConfigAndPreferences, - GDPRCookies, - getLocaleConf, -} from 'volto-gdpr-privacy/helpers'; - -import 'volto-gdpr-privacy/components/ConditionalEmbed/conditional-embed.css'; - -const messages = defineMessages({ - conditionalEmbedAcceptCookiesDefaultDescription: { - id: 'volto-gdpr-privacy-conditional-embed-default-description', - defaultMessage: - 'Please, accept {cookie_type} cookies to view this content.', - }, - conditionalEmbedAcceptCookiesAcceptMessage: { - id: 'volto-gdpr-privacy-conditional-embed-accept-message', - defaultMessage: '{enable_cookie_button}, or {manage_preferences_button}', - }, - specificCookieLink: { - id: 'volto-gdpr-privacy-conditional-embed-specific-cookie-link', - defaultMessage: 'Enable {cookie_type} cookies', - }, - genericCookieLink: { - id: 'volto-gdpr-privacy-conditional-embed-generic-cookie-link', - defaultMessage: 'manage your cookie preferences', - }, -}); -const ConditionalEmbed = ({ code, url, children }) => { - const intl = useIntl(); - const cookies = new GDPRCookies(); - const embed = code ?? url ?? ''; - const dispatch = useDispatch(); - const location = useLocation(); - - const { defaultPreferences } = usePanelConfigAndPreferences(cookies); - const profilingConfig = useSelector((state) => - state.gdprPrivacyConfig?.config?.profiling?.choices?.filter( - (c) => c?.referenceUrls?.length > 0, - ), - ); - const gdprPreferences = useSelector( - (state) => state.gdprPrivacyConsent.preferences ?? defaultPreferences, - ); - const [urlReferenceConfig, setUrlReferenceConfig] = useState(null); - - useEffect(() => { - if (profilingConfig && !urlReferenceConfig) { - let conditionalConfig = profilingConfig.filter( - (c) => - c.referenceUrls.filter((r) => embed?.indexOf(r) >= 0)?.length > 0, - ); - - setUrlReferenceConfig(conditionalConfig?.[0] ?? null); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [profilingConfig, setUrlReferenceConfig, urlReferenceConfig, embed]); - - //return value - let ret = <>; - let embedDisabled = true; - - embedDisabled = - urlReferenceConfig != null && - !gdprPreferences[urlReferenceConfig.config_key]; - const isDiffView = location.pathname?.includes('/diff'); - if (__CLIENT__ && !gdprPreferences && !isDiffView) { - return <>; - } else if (embedDisabled && !isDiffView) { - //embed disabled - const text = getLocaleConf(urlReferenceConfig.text, intl.locale); - const key = urlReferenceConfig.config_key; - ret = ( -
- {text.conditional_embed_text ?? - intl.formatMessage( - messages.conditionalEmbedAcceptCookiesDefaultDescription, - { cookie_type: key }, - )}{' '} - {intl.formatMessage( - messages.conditionalEmbedAcceptCookiesAcceptMessage, - { - enable_cookie_button: ( - - ), - manage_preferences_button: ( - - ), - }, - )} -
- ); - } else { - ret = <>{children}; - } - - return ret; -}; - -export default ConditionalEmbed; diff --git a/yarn.lock b/yarn.lock index ccd8b3f3e..07ccf443e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6479,7 +6479,7 @@ __metadata: volto-editablefooter: 5.0.1 volto-feedback: 0.1.5 volto-form-block: 3.1.0 - volto-gdpr-privacy: 2.1.0 + volto-gdpr-privacy: 2.1.1 volto-google-analytics: 2.0.0 volto-multilingual-widget: 3.0.0 volto-querywidget-with-browser: 0.4.0 @@ -14159,14 +14159,14 @@ __metadata: languageName: node linkType: hard -"volto-gdpr-privacy@npm:2.1.0": - version: 2.1.0 - resolution: "volto-gdpr-privacy@npm:2.1.0" +"volto-gdpr-privacy@npm:2.1.1": + version: 2.1.1 + resolution: "volto-gdpr-privacy@npm:2.1.1" dependencies: react-focus-lock: 2.9.4 peerDependencies: "@plone/volto": ">=16.0.0-alpha.38" - checksum: d83bfafaeee0ba773a98d7f8a43d99fc39e7cbf65b7fd36f0961926413e49611928fe8b36e8bab2572a2f8a8e610024835501864bdd52d2e9ddbaf73f9e874cb + checksum: 2246b9402782f305a45f6ee8dd69fe30f0fcc33dbbb0dcc493e3bcd53bad27263fc9da586ae23c28e0ce04f9c05d583b4e7809b510a59a99923bbb75bb8923fb languageName: node linkType: hard