Skip to content

Commit 3cc0ad8

Browse files
authored
Merge pull request #1741 from VEuPathDB/bug-1738
Fix: Invalid field links in error message not always behaving as expected.
2 parents 6bd3ec8 + 236397f commit 3cc0ad8

2 files changed

Lines changed: 31 additions & 13 deletions

File tree

packages/libs/user-datasets/src/lib/Components/Upload/UploadForm/Components/UploadErrorBanner.tsx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, { ReactElement, ReactNode } from 'react';
22
import Banner from '@veupathdb/coreui/lib/components/banners/Banner';
33
import { ValidationErrors } from '../../../../Service';
44
import { BadUpload } from '../../../../StoreModules';
5-
import { Link } from 'react-router-dom';
65

76
export interface UploadErrorBannerProps {
87
readonly errors: BadUpload | undefined;
@@ -52,20 +51,30 @@ function makeValidationErrorMessage(errors: ValidationErrors): ReactElement {
5251

5352
if ('byKey' in errors) {
5453
for (const jsonPath of Object.keys(errors.byKey)) {
55-
const link = document.getElementById(jsonPath) ? (
56-
<Link to={`#${encodeURI(jsonPath)}`}>{formatJPath(jsonPath)}</Link>
57-
) : (
58-
formatJPath(jsonPath)
59-
);
54+
// using `<a href` instead of `<Link` as Link does not properly handle
55+
// standard hash/anchor links. For that the library
56+
// `react-router-hash-link` is needed, however in this situation, we are
57+
// not changing the view in any way, so a normal HTML anchor link works
58+
// fine.
59+
const element = document.getElementById(jsonPath);
60+
61+
const link = element == null
62+
? formatJPath(jsonPath)
63+
: (
64+
<button
65+
className="error-link"
66+
type="button"
67+
onClick={() => {
68+
element.scrollIntoView();
69+
element.focus();
70+
}}
71+
>
72+
{formatJPath(jsonPath)}
73+
</button>
74+
);
6075

6176
for (const msg of errors.byKey[jsonPath]) {
62-
elements.push(
63-
newLI(
64-
<>
65-
{link}: {msg}
66-
</>
67-
)
68-
);
77+
elements.push(newLI(<>{link}: {msg}</>));
6978
}
7079
}
7180
}

packages/libs/user-datasets/src/lib/Components/Upload/UploadForm/UploadForm.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@
4444
font-style: italic;
4545
}
4646

47+
button.error-link {
48+
background: none;
49+
border: none;
50+
color: var(--coreui-blue-700);
51+
padding: 0;
52+
margin: 0;
53+
display: inline;
54+
}
55+
4756
div.input-block {
4857
border-width: 1px;
4958
border-style: solid;

0 commit comments

Comments
 (0)