From 0d22718affc6a848ae434c8408b0200d784d8caa Mon Sep 17 00:00:00 2001 From: Ryan Mathis Date: Thu, 13 May 2021 09:13:19 -0700 Subject: [PATCH] Implemented create from url --- ui/src/app/metadata/copy/CopySource.js | 11 +++ .../component/DeleteSourceConfirmation.js | 2 +- ui/src/app/metadata/view/MetadataCopy.js | 6 +- ui/src/app/metadata/view/MetadataUpload.js | 69 ++++++++++++------- 4 files changed, 58 insertions(+), 30 deletions(-) diff --git a/ui/src/app/metadata/copy/CopySource.js b/ui/src/app/metadata/copy/CopySource.js index 99ce15bbf..49114d01a 100644 --- a/ui/src/app/metadata/copy/CopySource.js +++ b/ui/src/app/metadata/copy/CopySource.js @@ -188,6 +188,17 @@ export function CopySource({ copy, onNext }) { + ); diff --git a/ui/src/app/metadata/domain/source/component/DeleteSourceConfirmation.js b/ui/src/app/metadata/domain/source/component/DeleteSourceConfirmation.js index 49124108b..f2d992a5d 100644 --- a/ui/src/app/metadata/domain/source/component/DeleteSourceConfirmation.js +++ b/ui/src/app/metadata/domain/source/component/DeleteSourceConfirmation.js @@ -38,7 +38,7 @@ export function DeleteSourceConfirmation ({children}) { <> {children(onDeleteSource)} setDeleting(null)}> - setDeleting(null)}>Delete Metadata Source? + Delete Metadata Source?

diff --git a/ui/src/app/metadata/view/MetadataCopy.js b/ui/src/app/metadata/view/MetadataCopy.js index bc2c19f79..7240ae42d 100644 --- a/ui/src/app/metadata/view/MetadataCopy.js +++ b/ui/src/app/metadata/view/MetadataCopy.js @@ -1,11 +1,7 @@ import React from 'react'; -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { faArrowCircleRight } from '@fortawesome/free-solid-svg-icons'; - -import { Translate } from '../../i18n/components/translate'; import { MetadataSchema } from '../hoc/MetadataSchema'; -import {CopySource} from '../copy/CopySource'; +import { CopySource } from '../copy/CopySource'; import { SaveCopy } from '../copy/SaveCopy'; import { useMetadataEntity } from '../hooks/api'; import { useHistory } from 'react-router'; diff --git a/ui/src/app/metadata/view/MetadataUpload.js b/ui/src/app/metadata/view/MetadataUpload.js index 687bfa270..35c0fdb56 100644 --- a/ui/src/app/metadata/view/MetadataUpload.js +++ b/ui/src/app/metadata/view/MetadataUpload.js @@ -4,7 +4,7 @@ import { useForm } from "react-hook-form"; import { useHistory } from 'react-router-dom'; import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; -import { faAsterisk, faSave } from '@fortawesome/free-solid-svg-icons'; +import { faAsterisk, faSave, faSpinner } from '@fortawesome/free-solid-svg-icons'; import Translate from '../../i18n/components/translate'; import { readFileContents } from '../../core/utility/read_file_contents'; @@ -18,26 +18,42 @@ export function MetadataUpload() { const history = useHistory(); const dispatch = useNotificationDispatcher(); + const [saving, setSaving] = React.useState(false); + async function save({serviceProviderName, file, url}) { - const f = file.length > 0 ? file[0] : null; + + setSaving(true); + + const f = file?.length > 0 ? file[0] : null; + + let body = ''; + let type = ''; + if (f) { - const body = await readFileContents(f); - const response = await fetch(`${API_BASE_PATH}${getMetadataPath('source')}?spName=${serviceProviderName}`, { - method: 'POST', - cache: 'no-cache', - headers: { - 'Content-Type': 'application/xml', - 'X-XSRF-TOKEN': get_cookie('XSRF-TOKEN') - }, - body - }); - - if (response.ok) { - history.push('/dashboard'); - } else { - const message = await response.json(); - dispatch(createNotificationAction(`${message.errorCode}: Unable to upload file ... ${message.errorMessage}`, 'danger', 5000)); - } + body = await readFileContents(f); + type = 'application/xml'; + } else if (url) { + body = `metadataUrl=${url}`; + type = 'application/x-www-form-urlencoded'; + } + + const response = await fetch(`${API_BASE_PATH}${getMetadataPath('source')}?spName=${serviceProviderName}`, { + method: 'POST', + cache: 'no-cache', + headers: { + 'Content-Type': type, + 'X-XSRF-TOKEN': get_cookie('XSRF-TOKEN') + }, + body + }); + + if (response.ok) { + setSaving(false); + history.push('/dashboard'); + } else { + const message = await response.json(); + dispatch(createNotificationAction(`${message.errorCode}: Unable to create file ... ${message.errorMessage}`, 'danger', 5000)); + setSaving(false); } } @@ -54,13 +70,11 @@ export function MetadataUpload() { const { errors, isValid } = formState; - // React.useEffect(() => console.log(formState), [formState]); + React.useEffect(() => console.log(isValid), [isValid]); const watchFile = watch('file'); const watchUrl = watch('url'); - // console.log(watchFile, errors); - return (

@@ -82,7 +96,7 @@ export function MetadataUpload() { - + Save @@ -124,12 +138,19 @@ export function MetadataUpload() {
- 0 } type="text" className="form-control" placeholder="" {...register('url')} /> + 0 } type="text" className="form-control"{...register('url')} />
Note: You can only import a file with a single entityID (EntityDescriptor element) in it. Anything more in that file will result in an error.
+