Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Oct 11, 2020
1 parent 9c9e6de commit b542a72
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 37 deletions.
23 changes: 20 additions & 3 deletions src/components/manage/Blocks/DetailedLink/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
71 changes: 43 additions & 28 deletions src/components/manage/Blocks/DetailedLink/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,34 +63,49 @@ const View = (props) => {
''
)}
<div>
<Link
className={cx(
'detailed-link-button display-inline-block',
buttonClassname || '',
)}
onClick={(e) => {
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)}
>
<span>{buttonTitle || detailedLink?.title || 'Go'}</span>
</Link>
{!props.data.outsideLink ? (
<Link
className={cx(
'detailed-link-button display-inline-block',
buttonClassname || '',
)}
onClick={(e) => {
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)}
>
<span>{buttonTitle || detailedLink?.title || 'Go'}</span>
</Link>
) : detailedLink?.path ? (
<a
target="_blank"
href={detailedLink.path}
className={cx(
'detailed-link-button display-inline-block',
buttonClassname || '',
)}
>
<span>{buttonTitle || detailedLink?.title || 'Go'}</span>
</a>
) : (
''
)}
</div>
</>
)) || (
Expand Down
8 changes: 6 additions & 2 deletions src/components/manage/Blocks/DetailedLink/schema.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const getSchema = (props) => {
{
id: 'default',
title: 'Default',
fields: ['page'],
fields: ['outsideLink', 'page'],
},
{
id: 'properties',
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/components/manage/Blocks/NavigationBlock/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const Edit = (props) => {
return (
<div>
<RenderFields schema={state.schema} {...props} title="Navigation block" />
<View {...props} id={state.id} />
<View {...props} id={state.id} mode="edit" />
</div>
);
};
Expand Down
4 changes: 3 additions & 1 deletion src/components/manage/Blocks/NavigationBlock/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ const View = ({ content, ...props }) => {
})}
</Menu>
</div>
) : (
) : props.mode === 'edit' ? (
<p>
There are no pages inside of selected page. Make sure you add pages or
delete the block
</p>
) : (
''
);
};

Expand Down
7 changes: 5 additions & 2 deletions theme/site/globals/site.overrides
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,7 @@ body.has-sidebar {
margin-left: auto !important;
margin-right: auto !important;
font-size: 18px;
align-items: center;
&:before {
display: none;
}
Expand All @@ -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 {
Expand Down

0 comments on commit b542a72

Please sign in to comment.