Skip to content

Commit

Permalink
NickAkhmetov/CAT-977 Revise Collection DOI links to copy on click (#3589
Browse files Browse the repository at this point in the history
)
  • Loading branch information
NickAkhmetov authored Nov 4, 2024
1 parent fa9b969 commit 73ec064
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-cat-977.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Revise Collection DOI links to copy on click instead of opening a new tab that leads to the same page.
40 changes: 38 additions & 2 deletions context/app/static/js/components/detailPage/Citation/Citation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import Typography from '@mui/material/Typography';

import OutboundIconLink from 'js/shared-styles/Links/iconLinks/OutboundIconLink';
import LabelledSectionText from 'js/shared-styles/sections/LabelledSectionText';
import ContentCopyIcon from '@mui/icons-material/ContentCopyRounded';
import { useHandleCopyClick } from 'js/hooks/useCopyText';
import IconLink from 'js/shared-styles/Links/iconLinks/IconLink';
import { SecondaryBackgroundTooltip } from 'js/shared-styles/tooltips';

interface Contributor {
last_name: string;
Expand All @@ -24,11 +28,43 @@ interface CitationProps {
doi_url: string;
doi: string;
className?: string;
internalDoi?: boolean;
}

function Citation({ contributors, citationTitle, created_timestamp, doi_url, doi, className }: CitationProps) {
function ExternalDoiLink({ doi_url }: { doi_url: string }) {
return <OutboundIconLink href={doi_url}>{doi_url}</OutboundIconLink>;
}

function InternalDoiLink({ doi_url }: { doi_url: string }) {
const copy = useHandleCopyClick();
return (
<SecondaryBackgroundTooltip title="This DOI link leads to the page you are currently viewing. Click to copy.">
<IconLink
href={doi_url}
onClick={(e) => {
e.preventDefault();
copy(doi_url);
}}
icon={<ContentCopyIcon />}
>
{doi_url}
</IconLink>
</SecondaryBackgroundTooltip>
);
}

function Citation({
contributors,
citationTitle,
created_timestamp,
doi_url,
doi,
className,
internalDoi,
}: CitationProps) {
const citation = buildNLMCitation(contributors, citationTitle, created_timestamp);

const DOI = internalDoi ? InternalDoiLink : ExternalDoiLink;
return (
<LabelledSectionText
label="Citation"
Expand All @@ -38,7 +74,7 @@ function Citation({ contributors, citationTitle, created_timestamp, doi_url, doi
childContainerComponent="div"
>
<Typography variant="body1">
{citation} Available from: <OutboundIconLink href={doi_url}>{doi_url}</OutboundIconLink>
{citation} Available from: <DOI doi_url={doi_url} />
</Typography>
<OutboundIconLink href={`https://commons.datacite.org/doi.org/${doi}`}>View DataCite Page</OutboundIconLink>
</LabelledSectionText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function CollectionCitation() {
contributors={contributors}
citationTitle={title}
created_timestamp={created_timestamp}
internalDoi
/>
);
}
Expand Down
22 changes: 2 additions & 20 deletions context/app/static/js/pages/Collection/Collection.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,21 @@
import React from 'react';

import OutboundIconLink from 'js/shared-styles/Links/iconLinks/OutboundIconLink';
import Summary from 'js/components/detailPage/summary/Summary';
import CollectionDatasetsTable from 'js/components/detailPage/CollectionDatasetsTable';
import ContributorsTable from 'js/components/detailPage/ContributorsTable';
import useTrackID from 'js/hooks/useTrackID';
import { Collection } from 'js/components/types';

import { getCollectionDOI } from './utils';

function DOILink({ doi_url }: Pick<Collection, 'doi_url'>) {
if (!doi_url) {
return null;
}
const doi = getCollectionDOI(doi_url);

return (
<OutboundIconLink href={doi_url} variant="body1">
doi:{doi}
</OutboundIconLink>
);
}

function CollectionDetail({ collection: collectionData }: { collection: Collection }) {
const { entity_type, hubmap_id, doi_url, datasets, contributors, contacts } = collectionData;
const { entity_type, hubmap_id, datasets, contributors, contacts } = collectionData;

useTrackID({ entity_type, hubmap_id });

return (
<div>
{collectionData && (
<>
<Summary title={hubmap_id}>
<DOILink doi_url={doi_url} />
</Summary>
<Summary title={hubmap_id} />
{'datasets' in collectionData && <CollectionDatasetsTable datasets={datasets} />}
{contributors && Boolean(contributors.length) && (
<ContributorsTable contributors={contributors} contacts={contacts} title="Contributors" />
Expand Down

0 comments on commit 73ec064

Please sign in to comment.