From b542a72191bd7f35747d290d84c66d486b531d83 Mon Sep 17 00:00:00 2001 From: Miu Razvan Date: Sun, 11 Oct 2020 18:07:42 +0300 Subject: [PATCH] Update --- .../manage/Blocks/DetailedLink/Edit.jsx | 23 +++++- .../manage/Blocks/DetailedLink/View.jsx | 71 +++++++++++-------- .../manage/Blocks/DetailedLink/schema.jsx | 8 ++- .../manage/Blocks/NavigationBlock/Edit.jsx | 2 +- .../manage/Blocks/NavigationBlock/View.jsx | 4 +- theme/site/globals/site.overrides | 7 +- 6 files changed, 78 insertions(+), 37 deletions(-) diff --git a/src/components/manage/Blocks/DetailedLink/Edit.jsx b/src/components/manage/Blocks/DetailedLink/Edit.jsx index f8cd0538..822e1ac6 100644 --- a/src/components/manage/Blocks/DetailedLink/Edit.jsx +++ b/src/components/manage/Blocks/DetailedLink/Edit.jsx @@ -17,21 +17,38 @@ const Edit = (props) => { schema: getSchema(props), }); const pageLink = props.data.page; + const outsideLink = props.data.outsideLink; useEffect(() => { - if (props.pages && props.pages?.[pageLink]) { + if (props.pages && props.pages?.[pageLink] && !outsideLink) { handleChangeBlock('detailedLink', { ...props.data.detailedLink, title: props.pages[pageLink].title, description: props.pages[pageLink].description, path: pageLink, }); + } else if (outsideLink) { + try { + new URL(pageLink); + handleChangeBlock('detailedLink', { + ...props.data.detailedLink, + title: '', + description: '', + path: pageLink, + }); + } catch { + handleChangeBlock('detailedLink', null); + } } /* eslint-disable-next-line */ - }, [props.pages]) + }, [props.pages, pageLink, outsideLink]) useEffect(() => { - if (pageLink) { + setState({ schema: getSchema(props) }); + }, [outsideLink]); + + useEffect(() => { + if (!outsideLink && pageLink) { props.dispatch(getPage(pageLink)); } /* eslint-disable-next-line */ diff --git a/src/components/manage/Blocks/DetailedLink/View.jsx b/src/components/manage/Blocks/DetailedLink/View.jsx index 29c10b71..41c98836 100644 --- a/src/components/manage/Blocks/DetailedLink/View.jsx +++ b/src/components/manage/Blocks/DetailedLink/View.jsx @@ -63,34 +63,49 @@ const View = (props) => { '' )}
- { - if ( - props.discodata_query.search.facilityInspireId || - props.discodata_query.search.installationInspireId || - props.discodata_query.search.lcpInspireId - ) { - props.deleteQueryParam({ - queryParam: [ - 'facilityInspireId', - 'installationInspireId', - 'lcpInspireId', - ], - }); - } - if (backButton) { - history.goBack(); - } - return e.preventDefault; - }} - to={!backButton && getPath(detailedLink?.path)} - > - {buttonTitle || detailedLink?.title || 'Go'} - + {!props.data.outsideLink ? ( + { + if ( + props.discodata_query.search.facilityInspireId || + props.discodata_query.search.installationInspireId || + props.discodata_query.search.lcpInspireId + ) { + props.deleteQueryParam({ + queryParam: [ + 'facilityInspireId', + 'installationInspireId', + 'lcpInspireId', + ], + }); + } + if (backButton) { + history.goBack(); + } + return e.preventDefault; + }} + to={!backButton && getPath(detailedLink?.path)} + > + {buttonTitle || detailedLink?.title || 'Go'} + + ) : detailedLink?.path ? ( + + {buttonTitle || detailedLink?.title || 'Go'} + + ) : ( + '' + )}
)) || ( diff --git a/src/components/manage/Blocks/DetailedLink/schema.jsx b/src/components/manage/Blocks/DetailedLink/schema.jsx index 1c66bc2d..52e82bd2 100644 --- a/src/components/manage/Blocks/DetailedLink/schema.jsx +++ b/src/components/manage/Blocks/DetailedLink/schema.jsx @@ -6,7 +6,7 @@ export const getSchema = (props) => { { id: 'default', title: 'Default', - fields: ['page'], + fields: ['outsideLink', 'page'], }, { id: 'properties', @@ -45,9 +45,13 @@ export const getSchema = (props) => { title: 'Hide description', type: 'boolean', }, + outsideLink: { + title: 'Outside link', + type: 'boolean', + }, page: { title: 'Page', - widget: 'object_by_path', + widget: props.data.outsideLink ? 'text' : 'object_by_path', }, title: { title: 'Title', diff --git a/src/components/manage/Blocks/NavigationBlock/Edit.jsx b/src/components/manage/Blocks/NavigationBlock/Edit.jsx index 270f3efe..7974b167 100644 --- a/src/components/manage/Blocks/NavigationBlock/Edit.jsx +++ b/src/components/manage/Blocks/NavigationBlock/Edit.jsx @@ -64,7 +64,7 @@ const Edit = (props) => { return (
- +
); }; diff --git a/src/components/manage/Blocks/NavigationBlock/View.jsx b/src/components/manage/Blocks/NavigationBlock/View.jsx index 2a5c1dbe..49fda5b2 100644 --- a/src/components/manage/Blocks/NavigationBlock/View.jsx +++ b/src/components/manage/Blocks/NavigationBlock/View.jsx @@ -131,11 +131,13 @@ const View = ({ content, ...props }) => { })} - ) : ( + ) : props.mode === 'edit' ? (

There are no pages inside of selected page. Make sure you add pages or delete the block

+ ) : ( + '' ); }; diff --git a/theme/site/globals/site.overrides b/theme/site/globals/site.overrides index 40f7746f..9a43a5d3 100644 --- a/theme/site/globals/site.overrides +++ b/theme/site/globals/site.overrides @@ -1343,6 +1343,7 @@ body.has-sidebar { margin-left: auto !important; margin-right: auto !important; font-size: 18px; + align-items: center; &:before { display: none; } @@ -1358,8 +1359,10 @@ body.has-sidebar { } .item { width: fit-content !important; - margin-right: 1em !important; - margin-left: 1em !important; + margin-right: 1rem !important; + margin-left: 1rem !important; + padding-top: 0.5rem; + padding-bottom: 0.5rem; } } .active.item {