Skip to content

Commit

Permalink
#1532 - adjust concept/version DOI stuff
Browse files Browse the repository at this point in the history
- Add dates to versioning panel & ensure we order by createTime
- Show latest version DOI more prominently
- Remove concept panel in favour of concept short info item
  • Loading branch information
louise-davies committed Mar 20, 2024
1 parent de0b29f commit 490d6aa
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 98 deletions.
16 changes: 14 additions & 2 deletions packages/datagateway-common/src/api/dataPublications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ const fetchDataPublications = (

if (additionalFilters) {
additionalFilters.forEach((filter) => {
params.append(filter.filterType, filter.filterValue);
if (filter.filterType === 'order') {
const existingSorts = params.getAll('order');
params.delete('order');
params.append('order', filter.filterValue);
existingSorts.forEach((v) => params.append('order', v));
} else params.append(filter.filterType, filter.filterValue);
});
}

Expand Down Expand Up @@ -216,7 +221,13 @@ export const useDataPublication = (
};

export const useDataPublicationsByFilters = (
additionalFilters: AdditionalFilters
additionalFilters: AdditionalFilters,
queryOptions?: UseQueryOptions<
DataPublication[],
AxiosError,
DataPublication[],
[string, AdditionalFilters]
>
): UseQueryResult<DataPublication[], AxiosError> => {
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);

Expand All @@ -234,6 +245,7 @@ export const useDataPublicationsByFilters = (
handleICATError(error);
},
retry: retryICATErrors,
...queryOptions,
}
);
};
Expand Down
1 change: 1 addition & 0 deletions packages/datagateway-common/src/app.types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export type RelatedItem = Optional<
> & {
id: number;
publication?: DataPublication;
createTime: string;
};

interface InstrumentScientist {
Expand Down
3 changes: 2 additions & 1 deletion packages/datagateway-dataview/public/res/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"title": "Title",
"description": "Description",
"pid": "DOI",
"concept": "Concept",
"latest_version": "Latest Version",
"id": "Data Publication ID",
"publication_date": "Publication Date",
"content_tab_label": "View Content",
Expand All @@ -69,7 +71,6 @@
"publisher": "Publisher",
"format": "Data Format",
"type": "Type",
"concept_panel_label": "Concept",
"version_panel_label": "Versions",
"citation_formatter": {
"label": "Data Citation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const fetchCitation = (
};

interface CitationFormatterProps {
label?: string;
doi: string | undefined;
formattedUsers: FormattedUser[];
title: string | undefined;
Expand Down Expand Up @@ -86,7 +87,7 @@ const useCitation = (
const CitationFormatter = (
props: CitationFormatterProps
): React.ReactElement => {
const { doi } = props;
const { doi, label } = props;

const [t] = useTranslation();
const [copiedCitation, setCopiedCitation] = React.useState(false);
Expand Down Expand Up @@ -119,7 +120,7 @@ const CitationFormatter = (
return (
<Box className="tour-dataview-citation-formatter">
<Subheading variant="h6" data-testid="citation-formatter-title">
{t('datapublications.details.citation_formatter.label')}
{label ?? t('datapublications.details.citation_formatter.label')}
</Subheading>
<Typography data-testid="citation-formatter-details">
{t('datapublications.details.citation_formatter.details') +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,36 +45,40 @@ const DLSDataPublicationEditForm: React.FC<DLSDataPublicationEditFormProps> = (
parseInt(dataPublicationId)
);

const { data: versionDataPublications } = useDataPublicationsByFilters([
{
filterType: 'where',
filterValue: JSON.stringify({
'relatedItems.relationType': { eq: 'IsVersionOf' },
}),
},
{
filterType: 'where',
filterValue: JSON.stringify({
'relatedItems.identifier': { eq: dataPublication?.pid },
}),
},
{
filterType: 'include',
filterValue: JSON.stringify([
{
content: {
dataCollectionInvestigations: {
investigation: {
investigationInstruments: 'instrument',
const { data: versionDataPublications } = useDataPublicationsByFilters(
[
{
filterType: 'where',
filterValue: JSON.stringify({
'relatedItems.relationType': { eq: 'IsVersionOf' },
}),
},
{
filterType: 'where',
filterValue: JSON.stringify({
'relatedItems.identifier': { eq: dataPublication?.pid },
}),
},
{
filterType: 'include',
filterValue: JSON.stringify([
{
content: {
dataCollectionInvestigations: {
investigation: {
investigationInstruments: 'instrument',
},
},
dataCollectionDatasets: 'dataset',
dataCollectionDatafiles: 'datafile',
},
dataCollectionDatasets: 'dataset',
dataCollectionDatafiles: 'datafile',
},
},
]),
},
]);
]),
},
{ filterType: 'order', filterValue: JSON.stringify('createTime desc') },
],
{ enabled: !!dataPublication?.pid }
);
const versionDataPublication = versionDataPublications?.[0];

React.useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import { useTranslation } from 'react-i18next';
import Branding from './dlsBranding.component';
import CitationFormatter from '../../citationFormatter.component';
import DLSDataPublicationContentTable from './dlsDataPublicationContentTable.component';
import DLSDataPublicationVersionPanel from './dlsDataPublicationVersionPanel.component';
import DLSDataPublicationVersionPanel, {
sortVersions,
} from './dlsDataPublicationVersionPanel.component';
import { Edit } from '@mui/icons-material';
import { useHistory } from 'react-router-dom';

Expand Down Expand Up @@ -129,6 +131,12 @@ const LandingPage = (props: LandingPageProps): React.ReactElement => {
[data]
);

const latestVersionPid = data?.relatedItems
?.filter(
(relatedItem) => relatedItem.relationType === DOIRelationType.HasVersion
)
.sort(sortVersions)?.[0]?.identifier;

const formattedUsers = React.useMemo(() => {
const principals: FormattedUser[] = [];
const experimenters: FormattedUser[] = [];
Expand Down Expand Up @@ -162,63 +170,118 @@ const LandingPage = (props: LandingPageProps): React.ReactElement => {
}, [data]);

React.useEffect(() => {
const scriptId = `dataPublication-${dataPublicationId}`;
let structuredDataScript = document.getElementById(scriptId);
// only add structured data for concept DOI landing pages
// TODO: we might want all versions to be searchable though - check with DLS
// in that case we'll likely need to exclude the concept to ensure we're not duplicating the latest version...
if (isVersionDOI === false) {
const scriptId = `dataPublication-${dataPublicationId}`;
let structuredDataScript = document.getElementById(scriptId);

if (!structuredDataScript) {
structuredDataScript = document.createElement('script');
structuredDataScript.id = scriptId;
(structuredDataScript as HTMLScriptElement).type = 'application/ld+json';
const head = document.getElementsByTagName('head')[0];
head.appendChild(structuredDataScript);
}
if (!structuredDataScript) {
structuredDataScript = document.createElement('script');
structuredDataScript.id = scriptId;
(structuredDataScript as HTMLScriptElement).type =
'application/ld+json';
const head = document.getElementsByTagName('head')[0];
head.appendChild(structuredDataScript);
}

structuredDataScript.innerHTML = JSON.stringify({
'@context': 'http://schema.org',
'@type': 'Dataset',
'@id': pid ? `https://doi.org/${pid}` : '',
url: pid ? `https://doi.org/${pid}` : '',
identifier: pid,
name: title,
description: description,
keywords: t('doi_constants.keywords', { returnObjects: true }),
publisher: {
'@type': 'Organization',
url: t('doi_constants.publisher.url'),
name: t('doi_constants.publisher.name'),
logo: t('doi_constants.publisher.logo'),
contactPoint: {
'@type': 'ContactPoint',
contactType: 'customer service',
email: t('doi_constants.publisher.email'),
structuredDataScript.innerHTML = JSON.stringify({
'@context': 'http://schema.org',
'@type': 'Dataset',
'@id': pid ? `https://doi.org/${pid}` : '',
url: pid ? `https://doi.org/${pid}` : '',
identifier: pid,
name: title,
description: description,
keywords: t('doi_constants.keywords', { returnObjects: true }),
publisher: {
'@type': 'Organization',
url: t('doi_constants.publisher.url'),
name: t('doi_constants.publisher.name'),
logo: t('doi_constants.publisher.logo'),
contactPoint: {
'@type': 'ContactPoint',
contactType: 'customer service',
email: t('doi_constants.publisher.email'),
url: t('doi_constants.publisher.url'),
},
},
},
creator: formattedUsers.map((user) => {
return { '@type': 'Person', name: user.fullName };
}),
includedInDataCatalog: {
'@type': 'DataCatalog',
url: t('doi_constants.distribution.content_url'),
},
license: t('doi_constants.distribution.license'),
});
creator: formattedUsers.map((user) => {
return { '@type': 'Person', name: user.fullName };
}),
includedInDataCatalog: {
'@type': 'DataCatalog',
url: t('doi_constants.distribution.content_url'),
},
license: t('doi_constants.distribution.license'),
});

return () => {
const currentScript = document.getElementById(scriptId);
if (currentScript) {
currentScript.remove();
}
};
}, [t, title, pid, dataPublicationId, description, formattedUsers]);
return () => {
const currentScript = document.getElementById(scriptId);
if (currentScript) {
currentScript.remove();
}
};
}
}, [
t,
title,
pid,
dataPublicationId,
description,
formattedUsers,
isVersionDOI,
]);

const shortInfo = [
{
content: function dataPublicationPidFormat(entity: DataPublication) {
return <StyledDOI doi={entity.pid} />;
},
label: t('datapublications.pid'),
},
...(isVersionDOI
? [
{
content: function dataPublicationPidFormat(
entity: DataPublication
) {
return <StyledDOI doi={entity.pid} />;
},
label: t('datapublications.pid'),
},
{
content: function dataPublicationPidFormat(
entity: DataPublication
) {
const conceptPid = data?.relatedItems?.filter(
(relatedItem) =>
relatedItem.relationType === DOIRelationType.IsVersionOf
)?.[0]?.identifier;
if (conceptPid) return <StyledDOI doi={conceptPid} />;
},
label: `${t('datapublications.concept')} ${t(
'datapublications.pid'
)}`,
},
]
: [
{
content: function dataPublicationPidFormat(
entity: DataPublication
) {
if (latestVersionPid) return <StyledDOI doi={latestVersionPid} />;
},
label: `${t('datapublications.latest_version')} ${t(
'datapublications.pid'
)}`,
},
{
content: function dataPublicationPidFormat(
entity: DataPublication
) {
return <StyledDOI doi={entity.pid} />;
},
label: `${t('datapublications.concept')} ${t(
'datapublications.pid'
)}`,
},
]),
{
content: (dataPublication: DataPublication) =>
dataPublication.publicationDate?.slice(0, 10) ?? '',
Expand Down Expand Up @@ -333,7 +396,25 @@ const LandingPage = (props: LandingPageProps): React.ReactElement => {
</div>
)}

{isVersionDOI === false && (
<CitationFormatter
label={`${t('datapublications.latest_version')} ${t(
'datapublications.details.citation_formatter.label'
)}`}
doi={latestVersionPid}
formattedUsers={formattedUsers}
title={title}
startDate={data?.publicationDate}
/>
)}
<CitationFormatter
label={
isVersionDOI === false
? `${t('datapublications.concept')} ${t(
'datapublications.details.citation_formatter.label'
)}`
: undefined
}
doi={pid}
formattedUsers={formattedUsers}
title={title}
Expand Down Expand Up @@ -371,7 +452,7 @@ const LandingPage = (props: LandingPageProps): React.ReactElement => {
</Grid>
)
)}
{data && (
{isVersionDOI === false && (
<Grid item sx={{ pt: '0px !important' }}>
<DLSDataPublicationVersionPanel
dataPublicationId={dataPublicationId}
Expand Down
Loading

0 comments on commit 490d6aa

Please sign in to comment.