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

NickAkhmetov/CAT-977 Revise Collection DOI links to copy on click #3589

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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.
37 changes: 35 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,9 @@ 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';

interface Contributor {
last_name: string;
Expand All @@ -24,11 +27,41 @@ 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 (
<IconLink
href={doi_url}
onClick={(e) => {
e.preventDefault();
copy(doi_url);
}}
icon={<ContentCopyIcon />}
>
{doi_url}
</IconLink>
);
}

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 +71,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
Loading