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

Simplify AnnotationFormManifestNetwork.js component

parent e3dce09f
No related branches found
No related tags found
1 merge request!10Draft: MigratingAnnotationCreation to MUI5.
Pipeline #1925 failed
...@@ -3,25 +3,10 @@ import { ...@@ -3,25 +3,10 @@ import {
Grid, Paper, TextField, Typography, Button, Link, Grid, Paper, TextField, Typography, Button, Link,
} from '@mui/material'; } from '@mui/material';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { isValidUrl } from '../utils';
/** 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 isValidUrl = (string) => {
if (string === '') {
return true;
}
try {
new URL(string);
return true;
} catch (_) {
return false;
}
};
const onChangeManifestNetworkInput = (event) => {
updateManifestNetwork(event.target.value.trim());
};
return ( return (
<Paper style={{ padding: '5px' }}> <Paper style={{ padding: '5px' }}>
<Typography variant="overline"> <Typography variant="overline">
...@@ -30,22 +15,19 @@ function AnnotationFormNetwork({ manifestNetwork, updateManifestNetwork }) { ...@@ -30,22 +15,19 @@ function AnnotationFormNetwork({ manifestNetwork, updateManifestNetwork }) {
<Grid> <Grid>
<TextField <TextField
value={manifestNetwork} value={manifestNetwork}
onChange={onChangeManifestNetworkInput} onChange={(event) => updateManifestNetwork(event.target.value.trim())}
label="Manifest URL" label="Manifest URL"
type="url" type="url"
/> />
{ {
isValidUrl(manifestNetwork) && ( isValidUrl(manifestNetwork) ? (
<Link <Link
href={manifestNetwork} href={manifestNetwork}
target="_blank" target="_blank"
> >
{manifestNetwork} {manifestNetwork}
</Link> </Link>
) ) : (
}
{
!isValidUrl(manifestNetwork) && (
<Typography variant="caption"> <Typography variant="caption">
Not a valid URL Not a valid URL
</Typography> </Typography>
......
...@@ -26,3 +26,15 @@ export function secondsToHMSarray(secs) { ...@@ -26,3 +26,15 @@ export function secondsToHMSarray(secs) {
seconds: secs % 60, seconds: secs % 60,
}; };
} }
export const isValidUrl = (string) => {
if (string === '') {
return true;
}
try {
new URL(string);
return true;
} catch (_) {
return false;
}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment