diff --git a/ui/src/app/metadata/copy/CopySource.js b/ui/src/app/metadata/copy/CopySource.js index 65e90a5e5..33836da9b 100644 --- a/ui/src/app/metadata/copy/CopySource.js +++ b/ui/src/app/metadata/copy/CopySource.js @@ -1,13 +1,14 @@ import React from 'react'; import { useForm } from 'react-hook-form'; -import Check from 'react-bootstrap/FormCheck'; import Button from 'react-bootstrap/Button'; +import Form from 'react-bootstrap/Form'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faArrowCircleRight, faAsterisk, faCheck, faTimes } from '@fortawesome/free-solid-svg-icons'; import { Translate } from '../../i18n/components/translate'; import { EntityTypeahead } from './EntityTypeahead'; import kebabCase from 'lodash/kebabCase'; +import { useMetadataSources } from '../hooks/api'; const sections = [ { i18nKey: 'organizationInformation', property: 'organization' }, @@ -23,6 +24,8 @@ const sections = [ export function CopySource({ copy, onNext }) { + const { data = [] } = useMetadataSources({ cachePolicy: 'no-cache' }, []); + const [selected, setSelected] = React.useState(copy.properties); const onSelect = (item, checked) => { let s = [...selected]; @@ -59,6 +62,8 @@ export function CopySource({ copy, onNext }) { setValue('properties', selected); }, [selected, setValue]); + const sourceIds = data.map(p => p.entityId); + return ( <>
@@ -120,28 +125,24 @@ export function CopySource({ copy, onNext }) { Service Resolver Name is required }
-
- - + - {errors?.entityId && - - {errors.entityId.type === 'required' && - Entity ID is required + {...register('entityId', { + required: true, validate: { + unique: v => !(sourceIds.indexOf(v) > -1) } - {errors.entityId.type === 'unique' && - Entity ID must be unique - } - - } -
+ })} /> + + {errors?.entityId?.type === 'unique' && } + {errors?.entityId?.type === 'required' && } + + @@ -158,7 +159,7 @@ export function CopySource({ copy, onNext }) { - ({ ...c, ...{ [section]: target[section] } }), {})); @@ -37,7 +33,7 @@ export function SaveCopy ({ copy, saving, onSave, onBack }) { const model = useCopiedModel(copy); const configuration = useCopiedConfiguration(model, schema, definition); - const { register, handleSubmit } = useForm({ + const { handleSubmit } = useForm({ mode: 'onChange', reValidateMode: 'onBlur', defaultValues: { @@ -59,61 +55,42 @@ export function SaveCopy ({ copy, saving, onSave, onBack }) { return ( <> -
-
-
    -
  • - -
  • -
  • -

    - - - - Finished! -

    -
  • -
  • - -
  • -
-
+
+
+
    +
  • + +
  • +
  • +

    + + + + Finished! +

    +
  • +
  • + +
  • +
-
-
-
-
-
- - - -
-
-
-
-
- +
); diff --git a/ui/src/app/metadata/view/MetadataCopy.js b/ui/src/app/metadata/view/MetadataCopy.js index 1584e4897..af4567b59 100644 --- a/ui/src/app/metadata/view/MetadataCopy.js +++ b/ui/src/app/metadata/view/MetadataCopy.js @@ -5,12 +5,15 @@ import { CopySource } from '../copy/CopySource'; import { SaveCopy } from '../copy/SaveCopy'; import { useMetadataEntity } from '../hooks/api'; import { useHistory } from 'react-router'; +import { createNotificationAction, NotificationTypes, useNotificationDispatcher } from '../../notifications/hoc/Notifications'; export function MetadataCopy ({ onShowNav }) { const { post, response, loading } = useMetadataEntity('source'); const history = useHistory(); + const dispatch = useNotificationDispatcher(); + const [copy, setCopy] = React.useState({ target: null, serviceProviderName: null, @@ -34,6 +37,12 @@ export function MetadataCopy ({ onShowNav }) { await post('', data); if (response.ok) { history.push('/'); + } else { + const { errorCode, errorMessage, cause } = response.data; + dispatch(createNotificationAction( + `${errorCode}: ${errorMessage} ${cause ? `-${cause}` : ''}`, + NotificationTypes.ERROR + )); } }