Skip to content

Commit

Permalink
Added back button
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Sep 23, 2020
1 parent 8f661c5 commit 6c4e9f1
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 52 deletions.
116 changes: 64 additions & 52 deletions src/components/manage/Blocks/DetailedLink/View.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { Link } from 'react-router-dom';
import { settings } from '~/config';
import cx from 'classnames';
Expand All @@ -15,8 +16,13 @@ const getPath = (url) => {
};

const View = (props) => {
const history = useHistory();
const detailedLink = props.data.detailedLink || null;
const { hideTitle = false, hideDescription = false } = props.data;
const {
backButton = false,
hideTitle = false,
hideDescription = false,
} = props.data;
const {
textAlign = null,
title = '',
Expand All @@ -36,58 +42,64 @@ const View = (props) => {
`text-align-${textAlign || 'left'}`,
)}
>
{(detailedLink && (
<>
{!hideTitle ? (
<div className={cx('detailed-link-title', titleClassname || '')}>
{title || detailedLink.title || ''}
{detailedLink ||
(backButton && (
<>
{!hideTitle && (title || detailedLink?.title) ? (
<div className={cx('detailed-link-title', titleClassname || '')}>
{title || detailedLink?.title || ''}
</div>
) : (
''
)}
{!hideDescription && (description || detailedLink?.description) ? (
<p
className={cx(
'detailed-link-description',
descriptionClassname || '',
)}
>
{description || detailedLink?.description || ''}
</p>
) : (
''
)}
<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>
</div>
) : (
''
)}
{!hideDescription && (description || detailedLink.description) ? (
<p
className={cx(
'detailed-link-description',
descriptionClassname || '',
)}
>
{description || detailedLink.description || ''}
</p>
) : (
''
)}
<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',
],
});
}
return e.preventDefault;
}}
to={getPath(detailedLink.path)}
>
<span>{buttonTitle || detailedLink.title || 'Go'}</span>
</Link>
</div>
</>
)) || (
<p className="detailed-link-placeholder">Select a page from sidebar</p>
)}
</>
)) || (
<p className="detailed-link-placeholder">
Select a page from sidebar
</p>
)}
</div>
);
};
Expand Down
5 changes: 5 additions & 0 deletions src/components/manage/Blocks/DetailedLink/schema.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const getSchema = (props) => {
id: 'properties',
title: 'Properties',
fields: [
'backButton',
'hideTitle',
'hideDescription',
'title',
Expand All @@ -32,6 +33,10 @@ export const getSchema = (props) => {
],

properties: {
backButton: {
title: 'Back button',
type: 'boolean',
},
hideTitle: {
title: 'Hide title',
type: 'boolean',
Expand Down
1 change: 1 addition & 0 deletions theme/site/globals/site.overrides
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ p {

// BROWSE TABLE
.browse-table {
overflow-x: auto;
.ui.grid {
margin-top: 0 !important;
}
Expand Down

0 comments on commit 6c4e9f1

Please sign in to comment.