From d0303303b53d0c2038f289d3e8e3e6f58a07ef51 Mon Sep 17 00:00:00 2001 From: Paul Sarando Date: Wed, 28 Feb 2024 17:49:02 -0700 Subject: [PATCH] CORE-1967 Replace usage of URL.canParse Chromatic is throwing errors that URL.canParse is not a function, even though CanIUse and MDN docs indicate there's wide support for it. --- src/components/data/listing/Listing.js | 2 +- src/components/data/listing/TableView.js | 2 +- src/components/metadata/templates/LocalContextsField.js | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/data/listing/Listing.js b/src/components/data/listing/Listing.js index f44e1ddb2..d88a9e07c 100644 --- a/src/components/data/listing/Listing.js +++ b/src/components/data/listing/Listing.js @@ -280,7 +280,7 @@ function Listing(props) { const { data: localContextsProject } = useQuery({ queryKey: [LOCAL_CONTEXTS_QUERY_KEY, projectID], queryFn: () => getLocalContextsProject({ projectID }), - enabled: URL.canParse(localContextsProjectURI), + enabled: !!localContextsProjectURI, onError: (error) => console.log("Error fetching Local Contexts project.", { localContextsProjectURI, diff --git a/src/components/data/listing/TableView.js b/src/components/data/listing/TableView.js index d071e451a..f8a07c381 100644 --- a/src/components/data/listing/TableView.js +++ b/src/components/data/listing/TableView.js @@ -102,7 +102,7 @@ function ResourceNameCell({ const { data: project } = useQuery({ queryKey: [LOCAL_CONTEXTS_QUERY_KEY, projectID], queryFn: () => getLocalContextsProject({ projectID }), - enabled: URL.canParse(localContextsProjectURI), + enabled: !!localContextsProjectURI, onError: (error) => console.log("Error fetching Local Contexts project.", { localContextsProjectURI, diff --git a/src/components/metadata/templates/LocalContextsField.js b/src/components/metadata/templates/LocalContextsField.js index 88ec66ebf..9156432a7 100644 --- a/src/components/metadata/templates/LocalContextsField.js +++ b/src/components/metadata/templates/LocalContextsField.js @@ -83,6 +83,8 @@ const LocalContextsField = ({ return schemeURI; }); + const { touched, errors } = form; + const fieldError = getFormError(field.name, touched, errors); const projectID = parseProjectID(projectHubURI); const { data: project, isFetching } = useQuery({ @@ -91,7 +93,7 @@ const LocalContextsField = ({ getLocalContextsProject({ projectID, }), - enabled: URL.canParse(projectHubURI), + enabled: projectHubURI && !fieldError, onSuccess: (project) => { let newValue = avu.value || ""; @@ -202,9 +204,7 @@ const LocalContextsField = ({ } }; - const { touched, errors } = form; - const errorMsg = - getFormError(field.name, touched, errors) || projectHubError; + const errorMsg = fieldError || projectHubError; return ( <>