From 626363f3f0ec3c9c98e40328c6e1431a2648c5bb Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 10 Aug 2023 18:00:29 +0200 Subject: [PATCH] feat(wizard): implement story embed, disable option based on page --- i18n/de.json | 1 + i18n/en.json | 1 + i18n/es.json | 1 + i18n/fr.json | 1 + i18n/nl.json | 1 + .../embed-checkbox-list.module.styl | 6 ++- .../embed-checkbox-list.tsx | 17 ++++++- .../main/embed-result/embed-result.tsx | 22 ++------- .../embed-settings/embed-settings.module.styl | 4 +- .../main/embed-wizard/embed-wizard.tsx | 16 ++----- .../stories/header/header.module.styl | 5 ++- .../components/stories/header/header.tsx | 45 ++++++++++++------- .../presentation-selector.tsx | 17 ++++--- .../showcase-selector/showcase-selector.tsx | 35 ++++++++------- .../stories-selector/stories-selector.tsx | 20 ++++++--- .../components/stories/story/story.tsx | 7 ++- src/scripts/config/main.ts | 10 ++++- src/scripts/libs/create-embed-url.ts | 11 +++++ src/scripts/reducers/embed-elements.ts | 7 ++- src/scripts/types/embed-elements.ts | 5 +++ 20 files changed, 149 insertions(+), 83 deletions(-) create mode 100644 src/scripts/libs/create-embed-url.ts diff --git a/i18n/de.json b/i18n/de.json index 072f96e1c..01f08a6d1 100644 --- a/i18n/de.json +++ b/i18n/de.json @@ -76,6 +76,7 @@ "copyEmbedLink": "Einbettungslink kopieren", "preview": "Vorschau", "previewTitle": "Link kopieren, damit jeder eine Vorschau sehen kann", + "story": "Geschichte", "tags.sea-surface-temperature": "Meeresoberflächentemperatur", "tags.sea-ice": "Meereis", "tags.ocean-colour": "Ozean Farbe", diff --git a/i18n/en.json b/i18n/en.json index 984a2e263..11e013fd3 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -76,6 +76,7 @@ "copyEmbedLink": "Copy embed link", "preview": "Preview", "previewTitle": "Copy link to allow anyone to preview", + "story": "Story", "tags.sea-surface-temperature": "Sea Surface Temperature", "tags.sea-ice": "Sea Ice", "tags.ocean-colour": "Ocean Colour", diff --git a/i18n/es.json b/i18n/es.json index 1c2747c4f..fc1a4462d 100644 --- a/i18n/es.json +++ b/i18n/es.json @@ -76,6 +76,7 @@ "copyEmbedLink": "Copiar enlace embed", "preview": "previsualizar", "previewTitle": "Copiar enlace para que cualquiera pueda previsualizar", + "story": "Historia", "tags.sea-surface-temperature": "Temperatura de la superficie del mar", "tags.sea-ice": "Hielo marino", "tags.ocean-colour": "Color del océano", diff --git a/i18n/fr.json b/i18n/fr.json index ea6ec9c09..418d8b91d 100644 --- a/i18n/fr.json +++ b/i18n/fr.json @@ -76,6 +76,7 @@ "copyEmbedLink": "Copier le lien d'intégration", "preview": "aperçu", "previewTitle": "Copier le lien pour permettre à n'importe qui de prévisualiser", + "story": "Histoire", "tags.sea-surface-temperature": "Température de surface de la mer", "tags.sea-ice": "Glace de mer", "tags.ocean-colour": "Couleur des océans", diff --git a/i18n/nl.json b/i18n/nl.json index 90847800c..43117febd 100644 --- a/i18n/nl.json +++ b/i18n/nl.json @@ -76,6 +76,7 @@ "copyEmbedLink": "Kopieer embed link", "preview": "voorbeeld", "previewTitle": "Link kopiëren zodat iedereen een voorbeeld kan bekijken", + "story": "Verhaal", "tags.sea-surface-temperature": "Zeewateroppervlaktetemperatuur", "tags.sea-ice": "Zee-ijs", "tags.ocean-colour": "Oceaankleur", diff --git a/src/scripts/components/main/embed-checkbox-list/embed-checkbox-list.module.styl b/src/scripts/components/main/embed-checkbox-list/embed-checkbox-list.module.styl index e7466e1fe..c32d76b0b 100644 --- a/src/scripts/components/main/embed-checkbox-list/embed-checkbox-list.module.styl +++ b/src/scripts/components/main/embed-checkbox-list/embed-checkbox-list.module.styl @@ -6,7 +6,11 @@ gap: emCalc(16px) .checkboxList.app - grid-area: 1 / 1 / 3 / 2 + grid-area: 1 / 1 / 4 / 2 + +.checkboxList.disabledEmbed + opacity: 0.5 + pointer-events: none .listTitle margin: 0 diff --git a/src/scripts/components/main/embed-checkbox-list/embed-checkbox-list.tsx b/src/scripts/components/main/embed-checkbox-list/embed-checkbox-list.tsx index 10e12f7a0..74398c6c8 100644 --- a/src/scripts/components/main/embed-checkbox-list/embed-checkbox-list.tsx +++ b/src/scripts/components/main/embed-checkbox-list/embed-checkbox-list.tsx @@ -1,5 +1,6 @@ import React, {FunctionComponent} from 'react'; import {FormattedMessage} from 'react-intl'; +import {useLocation} from 'react-router-dom'; import cx from 'classnames'; import {ElementOptions, UiEmbedElement} from '../../../types/embed-elements'; @@ -17,15 +18,29 @@ const EmbedCheckboxList: FunctionComponent = ({ elementsChecked, handleChange }) => { + const {pathname} = useLocation(); + const isDataPath = pathname === '/'; + const isStoriesPath = pathname === '/stories'; + const isStoryPath = pathname.startsWith('/stories/story-'); + const isStoriesList = elementList.title === 'stories'; + const isStory = elementList.title === 'story'; + const disabledEmbed = + (isDataPath && (isStoriesList || isStory)) || + (isStoriesPath && !isStoriesList) || + (isStoryPath && !isStory); + const checkboxListClasses = cx( styles.checkboxList, + disabledEmbed ? styles.disabledEmbed : null, styles[elementList.title] ); + const convertToTitleCase = (inputString: string) => inputString .split('_') .map(word => word.charAt(0).toUpperCase() + word.slice(1)) - .join(' '); + .join(' ') + .replace(/Story/g, ''); return (
diff --git a/src/scripts/components/main/embed-result/embed-result.tsx b/src/scripts/components/main/embed-result/embed-result.tsx index 7cb1e321c..682acec4f 100644 --- a/src/scripts/components/main/embed-result/embed-result.tsx +++ b/src/scripts/components/main/embed-result/embed-result.tsx @@ -3,6 +3,7 @@ import {FormattedMessage} from 'react-intl'; import Button from '../button/button'; import {CopyTextIcon} from '../icons/copy-text-icon'; +import {createEmbedUrl} from '../../../libs/create-embed-url'; import styles from './embed-result.module.styl'; @@ -12,26 +13,11 @@ interface Props { const EmbedResult: FunctionComponent = ({paramsString}) => { const iFrameRef = useRef(null); const linkRef = useRef(null); - const currentUrl = window.location.href; - - const createEmbedUrl = () => { - if (paramsString.length) { - return currentUrl.includes('?') - ? `${currentUrl}&${paramsString}` - : `${currentUrl}?${paramsString}`; - } - return ''; - }; const createiFrameCode = () => { - if (paramsString.length) { - const embedUrl = currentUrl.includes('?') - ? `${currentUrl}&${paramsString}` - : `${currentUrl}?${paramsString}`; + const embedUrl = createEmbedUrl(paramsString); - return ``; - } - return ''; + return ``; }; const copyUrl = (copyValue: string) => { @@ -69,7 +55,7 @@ const EmbedResult: FunctionComponent = ({paramsString}) => {