Skip to content

Commit

Permalink
Fixed validation regex for sources
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Oct 18, 2022
1 parent 93f3d7d commit fb8a2f9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions ui/src/app/metadata/wizard/MetadataSourceProtocolSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Translate from '../../i18n/components/translate';
import { InfoIcon } from '../../form/component/InfoIcon';
import { useTranslator } from '../../i18n/hooks';
import { useMetadataSources } from '../hooks/api';
import { useUserGroup } from '../../core/user/UserContext';
import Button from 'react-bootstrap/Button';

export function MetadataSourceProtocolSelector({ types = [], loading, children}) {
Expand Down Expand Up @@ -51,7 +52,7 @@ export function MetadataSourceProtocolSelector({ types = [], loading, children})
setSourceIds(data.map(s => s.entityId));
}, [data]);

React.useState(() => console.log(sourceNames), [sourceNames]);
const group = useUserGroup();

return (
<>{showSelector ?
Expand Down Expand Up @@ -135,12 +136,17 @@ export function MetadataSourceProtocolSelector({ types = [], loading, children})
<Form.Control
id="root_entityId"
isInvalid={errors.entityId}
type="text" {...register('entityId', {required: true, validate: {
unique: v => !(sourceIds.indexOf(v) > -1)
}})} />
type="text" {...register('entityId', {
required: true,
validate: {
unique: v => !(sourceIds.indexOf(v) > -1)
},
pattern: new RegExp(group?.validationRegex)
})} />
<Form.Text className={errors.entityId ? 'text-danger' : 'text-muted'}>
{errors?.entityId?.type === 'unique' && <Translate value={`message.must-be-unique`} />}
{errors?.entityId?.type === 'required' && <Translate value={`message.service-resolver-name-required`} />}
{errors?.entityId?.type === 'pattern' && <Translate value={`message.group-pattern-fail`} params={{regex: group?.validationRegex}} />}
</Form.Text>
</Form.Group>
</Form>
Expand Down

0 comments on commit fb8a2f9

Please sign in to comment.