From 950ec4fee81e39df86873fbb259ec73a117642ed Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 22 Nov 2023 12:00:30 -0800 Subject: [PATCH 1/9] fix doi validation --- src/components/Tabs/IdentificationTab.jsx | 7 +++---- src/utils/validate.js | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/components/Tabs/IdentificationTab.jsx b/src/components/Tabs/IdentificationTab.jsx index c2c5fe7f..7d8600da 100644 --- a/src/components/Tabs/IdentificationTab.jsx +++ b/src/components/Tabs/IdentificationTab.jsx @@ -23,7 +23,7 @@ import RequiredMark from "../FormComponents/RequiredMark"; import SelectInput from "../FormComponents/SelectInput"; import licenses from "../../utils/licenses"; import recordToDataCite from "../../utils/recordToDataCite"; -import { validateField, doiRegexp } from "../../utils/validate"; +import { validateField, doiRegexp, validateDOI } from "../../utils/validate"; import { QuestionText, @@ -44,9 +44,8 @@ const IdentificationTab = ({ const { createDraftDoi, updateDraftDoi, deleteDraftDoi } = useContext(UserContext); const { language, region, userID } = useParams(); const regionInfo = regions[region]; - const doiIsValid = Boolean( - !record.datasetIdentifier || doiRegexp.test(record.datasetIdentifier) - ); + const doiIsValid =validateDOI(record.datasetIdentifier) + const languageUpperCase = language.toUpperCase(); const [doiGenerated, setDoiGenerated] = useState(false); const [doiErrorFlag, setDoiErrorFlag] = useState(false); diff --git a/src/utils/validate.js b/src/utils/validate.js index b5124564..331abf93 100644 --- a/src/utils/validate.js +++ b/src/utils/validate.js @@ -16,7 +16,7 @@ function isValidHttpUrl(string) { return url.protocol === "http:" || url.protocol === "https:"; } - +export const validateDOI = (val) => !val || (doiRegexp.test(val) && isValidHttpUrl(val)) const validateLatitude = (num) => num >= -90 && num <= 90; const deepCompare = (obj1, obj2) => @@ -81,7 +81,7 @@ const validators = { }, }, datasetIdentifier: { - validation: (val) => !val || (doiRegexp.test(val) && isValidHttpUrl(val)), + validation: validateDOI, optional: true, tab: "dataID", error: { From 0591b486fc7b046e29f57797d4235b10f8fd8806 Mon Sep 17 00:00:00 2001 From: Austen Sorochak Date: Thu, 30 Nov 2023 15:07:48 -0800 Subject: [PATCH 2/9] update doi example in form to remove url portion --- src/components/Tabs/IdentificationTab.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Tabs/IdentificationTab.jsx b/src/components/Tabs/IdentificationTab.jsx index 7d8600da..42279c4d 100644 --- a/src/components/Tabs/IdentificationTab.jsx +++ b/src/components/Tabs/IdentificationTab.jsx @@ -23,7 +23,7 @@ import RequiredMark from "../FormComponents/RequiredMark"; import SelectInput from "../FormComponents/SelectInput"; import licenses from "../../utils/licenses"; import recordToDataCite from "../../utils/recordToDataCite"; -import { validateField, doiRegexp, validateDOI } from "../../utils/validate"; +import { validateField, validateDOI } from "../../utils/validate"; import { QuestionText, @@ -700,7 +700,7 @@ const IdentificationTab = ({ What is the DOI for this dataset? Eg, Quel est le DOI de ce jeu de données ? Par exemple, {" "} - https://doi.org/10.0000/0000 + 10.0000/0000 {showGenerateDoi && ( From f017132d678bd5fc9bcf1612c7f8fb5845cf5259 Mon Sep 17 00:00:00 2001 From: Austen Sorochak Date: Mon, 4 Dec 2023 15:40:54 -0800 Subject: [PATCH 3/9] remove valid http check to validate DOI --- src/utils/validate.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/utils/validate.js b/src/utils/validate.js index 331abf93..24bf37a0 100644 --- a/src/utils/validate.js +++ b/src/utils/validate.js @@ -5,18 +5,18 @@ export const validateURL = (url) => !url || validator.isURL(url); // See https://stackoverflow.com/a/48524047/7416701 export const doiRegexp = /^(https:\/\/doi.org\/)?10\.\d{4,9}\/[-._;()/:A-Z0-9]+$/i; -function isValidHttpUrl(string) { - let url; +// function isValidHttpUrl(string) { +// let url; - try { - url = new URL(string); - } catch (_) { - return false; - } +// try { +// url = new URL(string); +// } catch (_) { +// return false; +// } - return url.protocol === "http:" || url.protocol === "https:"; -} -export const validateDOI = (val) => !val || (doiRegexp.test(val) && isValidHttpUrl(val)) +// return url.protocol === "http:" || url.protocol === "https:"; +// } +export const validateDOI = (val) => !val || doiRegexp.test(val); const validateLatitude = (num) => num >= -90 && num <= 90; const deepCompare = (obj1, obj2) => From c4c611872f612b27cd016bc6a2fe1270d8a33688 Mon Sep 17 00:00:00 2001 From: Austen Sorochak Date: Tue, 5 Dec 2023 12:00:56 -0800 Subject: [PATCH 4/9] return valid http check to validate DOI --- src/utils/validate.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/utils/validate.js b/src/utils/validate.js index 24bf37a0..c8f51b30 100644 --- a/src/utils/validate.js +++ b/src/utils/validate.js @@ -5,18 +5,18 @@ export const validateURL = (url) => !url || validator.isURL(url); // See https://stackoverflow.com/a/48524047/7416701 export const doiRegexp = /^(https:\/\/doi.org\/)?10\.\d{4,9}\/[-._;()/:A-Z0-9]+$/i; -// function isValidHttpUrl(string) { -// let url; +function isValidHttpUrl(string) { + let url; -// try { -// url = new URL(string); -// } catch (_) { -// return false; -// } + try { + url = new URL(string); + } catch (_) { + return false; + } -// return url.protocol === "http:" || url.protocol === "https:"; -// } -export const validateDOI = (val) => !val || doiRegexp.test(val); + return url.protocol === "http:" || url.protocol === "https:"; +} +export const validateDOI = (val) => !val || (doiRegexp.test(val) && isValidHttpUrl(val)); const validateLatitude = (num) => num >= -90 && num <= 90; const deepCompare = (obj1, obj2) => From 8efb81ed2c2993df4876d19767609e519e885f87 Mon Sep 17 00:00:00 2001 From: Austen Sorochak Date: Tue, 5 Dec 2023 12:02:01 -0800 Subject: [PATCH 5/9] update doi example in form to return url portion --- src/components/Tabs/IdentificationTab.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Tabs/IdentificationTab.jsx b/src/components/Tabs/IdentificationTab.jsx index 42279c4d..24c6f425 100644 --- a/src/components/Tabs/IdentificationTab.jsx +++ b/src/components/Tabs/IdentificationTab.jsx @@ -700,7 +700,7 @@ const IdentificationTab = ({ What is the DOI for this dataset? Eg, Quel est le DOI de ce jeu de données ? Par exemple, {" "} - 10.0000/0000 + https://doi.org/10.0000/0000 {showGenerateDoi && ( From 427e96e77f866b246508fe972ed4e8d48b4e9837 Mon Sep 17 00:00:00 2001 From: Austen Sorochak Date: Tue, 5 Dec 2023 12:32:52 -0800 Subject: [PATCH 6/9] prepend https://doi.org/ to the generated DOI --- src/components/Tabs/IdentificationTab.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Tabs/IdentificationTab.jsx b/src/components/Tabs/IdentificationTab.jsx index 24c6f425..15a143d2 100644 --- a/src/components/Tabs/IdentificationTab.jsx +++ b/src/components/Tabs/IdentificationTab.jsx @@ -88,13 +88,13 @@ const IdentificationTab = ({ }) .then(async (attributes) => { // Update the record object with datasetIdentifier and doiCreationStatus - updateRecord("datasetIdentifier")(attributes.doi); + updateRecord("datasetIdentifier")(`https://doi.org/${attributes.doi}`); updateRecord("doiCreationStatus")("draft"); // Create a new object with updated properties const updatedRecord = { ...record, - datasetIdentifier: attributes.doi, + datasetIdentifier: `https://doi.org/${attributes.doi}`, doiCreationStatus: "draft", }; From 9ed5ecae91b319825eca5d48b508003aa0d145cc Mon Sep 17 00:00:00 2001 From: Austen Sorochak Date: Tue, 5 Dec 2023 12:41:30 -0800 Subject: [PATCH 7/9] strip off url from datasetidentifier when updating doi with datacite --- src/components/Tabs/IdentificationTab.jsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/Tabs/IdentificationTab.jsx b/src/components/Tabs/IdentificationTab.jsx index 15a143d2..377937c4 100644 --- a/src/components/Tabs/IdentificationTab.jsx +++ b/src/components/Tabs/IdentificationTab.jsx @@ -133,8 +133,11 @@ const IdentificationTab = ({ delete mappedDataCiteObject.data.type; delete mappedDataCiteObject.data.attributes.prefix; + // Extract DOI from the full URL + const doi = record.datasetIdentifier.replace('https://doi.org/', ''); + const dataObject = { - doi: record.datasetIdentifier, + doi, data: mappedDataCiteObject, } From 801c5d0561c2191dfcbb45dcc05cd8b14bc0835b Mon Sep 17 00:00:00 2001 From: Austen Sorochak Date: Tue, 5 Dec 2023 12:44:08 -0800 Subject: [PATCH 8/9] strip off url from datasetidentifier when deleting doi with datacite --- src/components/Tabs/IdentificationTab.jsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/Tabs/IdentificationTab.jsx b/src/components/Tabs/IdentificationTab.jsx index 377937c4..a0dc93d8 100644 --- a/src/components/Tabs/IdentificationTab.jsx +++ b/src/components/Tabs/IdentificationTab.jsx @@ -163,7 +163,10 @@ const IdentificationTab = ({ setLoadingDoiDelete(true); try { - deleteDraftDoi(record.datasetIdentifier) + // Extract DOI from the full URL + const doi = record.datasetIdentifier.replace('https://doi.org/', ''); + + deleteDraftDoi(doi) .then((response) => response.data) .then(async (statusCode) => { if (statusCode === 204) { From 6eb9bf0f2eb527a834e10911a18cae7b6ee64d01 Mon Sep 17 00:00:00 2001 From: Austen Sorochak Date: Tue, 5 Dec 2023 12:48:17 -0800 Subject: [PATCH 9/9] remove the word draft from generate, update, and delete DOI buttons --- src/components/Tabs/IdentificationTab.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/Tabs/IdentificationTab.jsx b/src/components/Tabs/IdentificationTab.jsx index a0dc93d8..bff37e74 100644 --- a/src/components/Tabs/IdentificationTab.jsx +++ b/src/components/Tabs/IdentificationTab.jsx @@ -737,7 +737,7 @@ const IdentificationTab = ({ Loading... ) : ( - "Generate Draft DOI" + "Generate DOI" )} @@ -754,7 +754,7 @@ const IdentificationTab = ({ Loading... ) : ( - "Update Draft DOI" + "Update DOI" )} @@ -771,7 +771,7 @@ const IdentificationTab = ({ Loading... ) : ( - "Delete Draft DOI" + "Delete DOI" )}