Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

routes: Render browser tab title based on literature title #599

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ export default class DocumentDetails extends Component {
if (!samePidFromRouter) {
fetchDocumentDetails(documentPid);
}

const { renderTabTitle, data } = this.props;
if (renderTabTitle) {
renderTabTitle({
title: data.metadata.title,
});
}
}

render() {
Expand Down Expand Up @@ -104,8 +111,10 @@ DocumentDetails.propTypes = {
documentPid: PropTypes.string,
}),
}).isRequired,
renderTabTitle: PropTypes.func,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you add as required prop, we can avoid the if statement on each function call

};

DocumentDetails.defaultProps = {
error: null,
renderTabTitle: null,
};
9 changes: 9 additions & 0 deletions src/lib/pages/backoffice/EItem/EItemDetails/EItemDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ export default class EItemDetails extends Component {
if (!samePidFromRouter) {
fetchEItemDetails(eitemPid);
}

const { renderTabTitle, data } = this.props;
if (renderTabTitle) {
renderTabTitle({
title: data.metadata.title,
});
}
}

render() {
Expand Down Expand Up @@ -77,8 +84,10 @@ EItemDetails.propTypes = {
eitemPid: PropTypes.string,
}),
}).isRequired,
renderTabTitle: PropTypes.func,
};

EItemDetails.defaultProps = {
error: null,
renderTabTitle: null,
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class DocumentRequestForm extends Component {
...props.location.state?.formData,
},
};

// const { renderTabTitle } = this.props;
// if (renderTabTitle) {
// document.title = renderTabTitle({ title: 'Request Resources' });
// }
}

onSerializeSubmit = (values) => {
Expand Down Expand Up @@ -272,6 +277,7 @@ DocumentRequestForm.propTypes = {
notes: PropTypes.object,
publisher: PropTypes.object,
location: PropTypes.object,
// renderTabTitle: PropTypes.func,
};

DocumentRequestForm.defaultProps = {
Expand Down Expand Up @@ -343,6 +349,7 @@ DocumentRequestForm.defaultProps = {
label: 'Publisher',
placeholder: 'Publisher',
},
// renderTabTitle: null,
};

export default Overridable.component(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ class DocumentDetails extends Component {
if (!samePidFromRouter) {
this.fetchDocumentsDetails(documentPid);
}

const { renderTabTitle, documentDetails } = this.props;
if (renderTabTitle) {
renderTabTitle({
title: documentDetails.metadata.title,
});
}
}

fetchDocumentsDetails(documentPid) {
Expand Down Expand Up @@ -223,10 +230,12 @@ DocumentDetails.propTypes = {
documentPid: PropTypes.string,
}),
}).isRequired,
renderTabTitle: PropTypes.func,
};

DocumentDetails.defaultProps = {
error: null,
renderTabTitle: null,
};

export default Overridable.component('DocumentDetails', DocumentDetails);
10 changes: 10 additions & 0 deletions src/lib/pages/frontsite/PatronProfile/PatronProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class PatronProfile extends Component {
pendingLoansRef: React.createRef(),
currentDoqRequestsRef: React.createRef(),
};

const { renderTabTitle } = this.props;
if (renderTabTitle) {
renderTabTitle({ title: 'My Profile' });
}
}

tabs = () => {
Expand Down Expand Up @@ -83,6 +88,11 @@ class PatronProfile extends Component {

PatronProfile.propTypes = {
user: PropTypes.object.isRequired,
renderTabTitle: PropTypes.func,
};

PatronProfile.defaultProps = {
renderTabTitle: null,
};

export default Overridable.component('Patron', PatronProfile);
6 changes: 6 additions & 0 deletions src/lib/pages/frontsite/Series/SeriesDetails/SeriesDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ class SeriesDetails extends React.Component {
if (!samePidFromRouter) {
this.fetchSeriesDetails(seriesPid);
}
const { renderTabTitle, series } = this.props;
if (renderTabTitle) {
renderTabTitle({ title: series.metadata.title });
}
}

fetchSeriesDetails(seriesPid) {
Expand Down Expand Up @@ -195,10 +199,12 @@ SeriesDetails.propTypes = {
}).isRequired,
hasError: PropTypes.bool.isRequired,
error: PropTypes.object,
renderTabTitle: PropTypes.func,
};

SeriesDetails.defaultProps = {
error: null,
renderTabTitle: null,
};

export default Overridable.component('SeriesDetails', SeriesDetails);
32 changes: 29 additions & 3 deletions src/lib/routes/backoffice/BackOfficeRoutesSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,25 @@ import Overridable from 'react-overridable';
import { Route, Switch } from 'react-router-dom';

export default class BackOfficeRoutesSwitch extends Component {
renderTabTitle = ({
title,
prefix = 'Admin: ',
suffix = ' | CERN Library Catalogue',
}) => {
document.title = `${prefix}${title}${suffix}`;
};

render() {
return (
<Switch>
<Route exact path={BackOfficeRoutes.home} component={Home} />
<Route
exact
path={BackOfficeRoutes.home}
render={(props) => {
this.renderTabTitle({ prefix: '', title: 'Admin Panel' });
return <Home {...props} />;
}}
/>
{/* documents */}
<Route
exact
Expand All @@ -69,7 +84,14 @@ export default class BackOfficeRoutesSwitch extends Component {
<Route
exact
path={BackOfficeRoutes.documentDetails}
component={DocumentDetails}
render={(props) => {
return (
<DocumentDetails
{...props}
renderTabTitle={this.renderTabTitle}
/>
);
}}
/>
{/* eitems */}
<Route
Expand All @@ -90,7 +112,11 @@ export default class BackOfficeRoutesSwitch extends Component {
<Route
exact
path={BackOfficeRoutes.eitemDetails}
component={EItemDetails}
render={(props) => {
return (
<EItemDetails {...props} renderTabTitle={this.renderTabTitle} />
);
}}
/>
{/*/!* items *!/*/}
<Route exact path={BackOfficeRoutes.itemsList} component={ItemSearch} />
Expand Down
28 changes: 24 additions & 4 deletions src/lib/routes/frontsite/Frontsite.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export default class FrontSite extends Component {
customStaticPages();
};

renderTabTitle = ({ title, suffix = ' | CERN Library Catalogue' }) => {
document.title = `${title}${suffix}`;
};

render() {
const staticPagesRoutes = getStaticPagesRoutes();
return (
Expand All @@ -48,22 +52,38 @@ export default class FrontSite extends Component {
<Route
exact
path={FrontSiteRoutes.documentDetails}
component={DocumentDetails}
render={(props) => (
<DocumentDetails
{...props}
renderTabTitle={this.renderTabTitle}
/>
)}
/>
<Route
exact
path={FrontSiteRoutes.seriesDetails}
component={SeriesDetails}
render={(props) => (
<SeriesDetails
{...props}
renderTabTitle={this.renderTabTitle}
/>
)}
/>
<Route
exact
path={FrontSiteRoutes.documentRequestForm}
component={DocumentRequestForm}
render={(props) => {
this.renderTabTitle({ title: 'Request Resources' });
return <DocumentRequestForm {...props} />;
}}
/>
<Route
exact
path={FrontSiteRoutes.patronProfile}
component={PatronProfile}
render={(props) => {
this.renderTabTitle({ title: 'Your Loans' });
return <PatronProfile {...props} />;
}}
/>
<Route
exact
Expand Down
Loading