Skip to content
Snippets Groups Projects
Commit e3dce09f authored by Anthony's avatar Anthony
Browse files

Improve manifest network input

parent 87f8ca44
No related branches found
No related tags found
1 merge request!10Draft: MigratingAnnotationCreation to MUI5.
import React from 'react'; import React from 'react';
import { import {
Grid, Paper, TextField, Typography, Button, Grid, Paper, TextField, Typography, Button, Link,
} from '@mui/material'; } from '@mui/material';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
/** Form part for edit annotation content and body */ /** Form part for edit annotation content and body */
function AnnotationFormNetwork({ manifestNetwork, updateManifestNetwork }) { function AnnotationFormNetwork({ manifestNetwork, updateManifestNetwork }) {
const addManifest = () => { const isValidUrl = (string) => {
updateManifestNetwork(manifestNetwork); if (string === '') {
return true;
}
try {
new URL(string);
return true;
} catch (_) {
return false;
}
};
const onChangeManifestNetworkInput = (event) => {
updateManifestNetwork(event.target.value.trim());
}; };
return ( return (
...@@ -18,9 +30,27 @@ function AnnotationFormNetwork({ manifestNetwork, updateManifestNetwork }) { ...@@ -18,9 +30,27 @@ function AnnotationFormNetwork({ manifestNetwork, updateManifestNetwork }) {
<Grid> <Grid>
<TextField <TextField
value={manifestNetwork} value={manifestNetwork}
onChange={(ev) => updateManifestNetwork(ev.target.value)} onChange={onChangeManifestNetworkInput}
label="Manifest URL" label="Manifest URL"
type="url"
/> />
{
isValidUrl(manifestNetwork) && (
<Link
href={manifestNetwork}
target="_blank"
>
{manifestNetwork}
</Link>
)
}
{
!isValidUrl(manifestNetwork) && (
<Typography variant="caption">
Not a valid URL
</Typography>
)
}
</Grid> </Grid>
</Paper> </Paper>
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment