Skip to content

Commit

Permalink
#1532 #1533 - only show concept dois and fix editing form
Browse files Browse the repository at this point in the history
Need to get content from version DOI
API is currently broken so need to wait for a fix for further testing
  • Loading branch information
louise-davies committed Feb 2, 2024
1 parent bc8f4fc commit 84c9498
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
28 changes: 26 additions & 2 deletions packages/datagateway-common/src/api/dataPublications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const useDataPublicationsInfinite = (
};

export const useDataPublication = (
dataPublicationId: number
dataPublicationId?: number
): UseQueryResult<DataPublication[], AxiosError> => {
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);

Expand All @@ -164,7 +164,7 @@ export const useDataPublication = (
DataPublication[],
[string, number]
>(
['dataPublication', dataPublicationId],
['dataPublication', dataPublicationId ?? -1],
() => {
return fetchDataPublications(apiUrl, { sort: {}, filters: {} }, [
{
Expand Down Expand Up @@ -194,6 +194,30 @@ export const useDataPublication = (
},
]);
},
{
onError: (error) => {
handleICATError(error);
},
retry: retryICATErrors,
enabled: typeof dataPublicationId !== 'undefined',
}
);
};

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

return useQuery(
['dataPublication', additionalFilters],
() => {
return fetchDataPublications(
apiUrl,
{ sort: {}, filters: {} },
additionalFilters
);
},
{
onError: (error) => {
handleICATError(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
readSciGatewayToken,
RelatedDOI,
useDataPublication,
useDataPublicationByFilters,
useUpdateDOI,
} from 'datagateway-common';
import React from 'react';
Expand Down Expand Up @@ -45,6 +46,38 @@ const DLSDataPublicationEditForm: React.FC<DLSDataPublicationEditFormProps> = (
);
const dataPublication = dataPublications?.[0];

const { data: versionDataPublications } = useDataPublicationByFilters([
{
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',
},
},
]),
},
]);
const versionDataPublication = versionDataPublications?.[0];

React.useEffect(() => {
if (dataPublication) {
setTitle(dataPublication.title);
Expand Down Expand Up @@ -129,7 +162,7 @@ const DLSDataPublicationEditForm: React.FC<DLSDataPublicationEditFormProps> = (
setRelatedDOIs={setRelatedDOIs}
disableMintButton={false}
onMintClick={() => {
if (dataPublication) {
if (dataPublication && versionDataPublication) {
setShowMintConfirmation(true);
const creatorsList = selectedUsers
.filter(
Expand All @@ -148,15 +181,15 @@ const DLSDataPublicationEditForm: React.FC<DLSDataPublicationEditFormProps> = (
// TODO: add ability for user to edit the content
content: {
investigation_ids:
dataPublication.content?.dataCollectionInvestigations?.map(
versionDataPublication.content?.dataCollectionInvestigations?.map(
(dci) => dci.investigation.id
) ?? [],
dataset_ids:
dataPublication.content?.dataCollectionDatasets?.map(
versionDataPublication.content?.dataCollectionDatasets?.map(
(dcd) => dcd.dataset.id
) ?? [],
datafile_ids:
dataPublication.content?.dataCollectionDatafiles?.map(
versionDataPublication.content?.dataCollectionDatafiles?.map(
(dcd) => dcd.datafile.id
) ?? [],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const DLSMyDOIsTable = (): React.ReactElement => {
[location.search]
);

/** TODO do we want to display concept dois instead of latest version DOIs (like Zenodo does iirc?)
* Is there a nicer way of checking for version vs concept? idk
*/
const { data: totalDataCount } = useDataPublicationCount([
{
filterType: 'where',
Expand All @@ -45,6 +48,12 @@ const DLSMyDOIsTable = (): React.ReactElement => {
},
}),
},
{
filterType: 'where',
filterValue: JSON.stringify({
'relatedItems.relationType': { eq: 'HasVersion' },
}),
},
]);

const { fetchNextPage, data } = useDataPublicationsInfinite([
Expand All @@ -63,6 +72,12 @@ const DLSMyDOIsTable = (): React.ReactElement => {
},
}),
},
{
filterType: 'where',
filterValue: JSON.stringify({
'relatedItems.relationType': { eq: 'HasVersion' },
}),
},
]);

/* istanbul ignore next */
Expand Down

0 comments on commit 84c9498

Please sign in to comment.