Skip to content

Commit

Permalink
CORE-1967 Replace usage of URL.canParse
Browse files Browse the repository at this point in the history
Chromatic is throwing errors that URL.canParse is not a function,
even though CanIUse and MDN docs indicate there's wide support for it.
  • Loading branch information
psarando committed Feb 29, 2024
1 parent f084b0d commit d030330
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/data/listing/Listing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/components/data/listing/TableView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/components/metadata/templates/LocalContextsField.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -91,7 +93,7 @@ const LocalContextsField = ({
getLocalContextsProject({
projectID,
}),
enabled: URL.canParse(projectHubURI),
enabled: projectHubURI && !fieldError,
onSuccess: (project) => {
let newValue = avu.value || "";

Expand Down Expand Up @@ -202,9 +204,7 @@ const LocalContextsField = ({
}
};

const { touched, errors } = form;
const errorMsg =
getFormError(field.name, touched, errors) || projectHubError;
const errorMsg = fieldError || projectHubError;

return (
<>
Expand Down

0 comments on commit d030330

Please sign in to comment.