From d02ebe88ffecc721fc038c523e15cc68db80405e Mon Sep 17 00:00:00 2001 From: Ryan Mathis Date: Thu, 13 May 2021 08:27:58 -0700 Subject: [PATCH] Implemented copy --- ui/src/app/form/component/InfoIcon.js | 4 +- ui/src/app/metadata/copy/CopySource.js | 14 ++- ui/src/app/metadata/copy/SaveCopy.js | 107 +++++++++++++++++++++-- ui/src/app/metadata/view/MetadataCopy.js | 40 ++++++--- 4 files changed, 136 insertions(+), 29 deletions(-) diff --git a/ui/src/app/form/component/InfoIcon.js b/ui/src/app/form/component/InfoIcon.js index da27ca22f..5e0ba1b0f 100644 --- a/ui/src/app/form/component/InfoIcon.js +++ b/ui/src/app/form/component/InfoIcon.js @@ -5,9 +5,9 @@ import Popover from 'react-bootstrap/Popover'; import OverlayTrigger from 'react-bootstrap/OverlayTrigger'; import Translate from '../../i18n/components/translate'; -export function InfoIcon ({ value, ...props }) { +export function InfoIcon ({ value, placement='left', ...props }) { return( - diff --git a/ui/src/app/metadata/copy/CopySource.js b/ui/src/app/metadata/copy/CopySource.js index 19f40a821..99ce15bbf 100644 --- a/ui/src/app/metadata/copy/CopySource.js +++ b/ui/src/app/metadata/copy/CopySource.js @@ -6,9 +6,10 @@ import { faArrowCircleRight, faAsterisk, faCheck, faTimes } from '@fortawesome/f import { Translate } from '../../i18n/components/translate'; import { EntityTypeahead } from './EntityTypeahead'; +import kebabCase from 'lodash/kebabCase'; const sections = [ - { i18nKey: 'organizationInfo', property: 'organization' }, + { i18nKey: 'organizationInformation', property: 'organization' }, { i18nKey: 'contacts', property: 'contacts' }, { i18nKey: 'uiMduiInfo', property: 'mdui' }, { i18nKey: 'spSsoDescriptorInfo', property: 'serviceProviderSsoDescriptor' }, @@ -19,9 +20,9 @@ const sections = [ { i18nKey: 'attributeRelease', property: 'attributeRelease' } ]; -export function CopySource({ onNext }) { +export function CopySource({ copy, onNext }) { - const [selected, setSelected] = React.useState([]); + const [selected, setSelected] = React.useState(copy.properties); const onSelect = (item, checked) => { let s = [...selected]; if (checked) { @@ -42,10 +43,7 @@ export function CopySource({ onNext }) { mode: 'onChange', reValidateMode: 'onBlur', defaultValues: { - target: null, - serviceProviderName: null, - entityId: null, - properties: selected + ...copy }, resolver: undefined, context: undefined, @@ -157,7 +155,7 @@ export function CopySource({ onNext }) { {sections.map((item, i) => - + ({ ...c, ...{ [section]: target[section] } }), {})); - const model = [{ + const model = { serviceProviderName, entityId, ...copied - }]; - return useMetadataConfiguration(model, schema, definition); + }; + return model; +} + +export function useCopiedConfiguration(model, schema, definition) { + return useMetadataConfiguration([model], schema, definition); } -export function SaveCopy ({ copy }) { +export function SaveCopy ({ copy, saving, onSave, onBack }) { const definition = React.useContext(MetadataDefinitionContext); const schema = React.useContext(MetadataSchemaContext); - const configuration = useCopiedConfiguration(copy, schema, definition); + const model = useCopiedModel(copy); + const configuration = useCopiedConfiguration(model, schema, definition); + + const { register, handleSubmit, getValues } = useForm({ + mode: 'onChange', + reValidateMode: 'onBlur', + defaultValues: { + serviceEnabled: false + }, + resolver: undefined, + context: undefined, + criteriaMode: "firstError", + shouldFocusError: true, + shouldUnregister: false, + }); + + const onFinish = (data) => { + onSave({ + ...model, + ...data + }) + }; + + return ( + <> +
+
+
    +
  • + +
  • +
  • +

    + + + + Finished! +

    +
  • +
  • + +
  • +
+
+
+
+
+
+
+
+ + + +
+
+
+
+
- return (); + + + ); } \ No newline at end of file diff --git a/ui/src/app/metadata/view/MetadataCopy.js b/ui/src/app/metadata/view/MetadataCopy.js index 03031cad8..bc2c19f79 100644 --- a/ui/src/app/metadata/view/MetadataCopy.js +++ b/ui/src/app/metadata/view/MetadataCopy.js @@ -7,32 +7,48 @@ import { MetadataSchema } from '../hoc/MetadataSchema'; import {CopySource} from '../copy/CopySource'; import { SaveCopy } from '../copy/SaveCopy'; +import { useMetadataEntity } from '../hooks/api'; +import { useHistory } from 'react-router'; export function MetadataCopy () { + const { post, response, loading } = useMetadataEntity('source'); + const history = useHistory(); + + const [copy, setCopy] = React.useState({ + target: null, + serviceProviderName: null, + entityId: null, + properties: [] + }); + const [confirm, setConfirm] = React.useState(false); + const next = (data) => { setCopy(data); + setConfirm(true) + }; + + const back = (data) => { + setConfirm(false); }; - const [copy, setCopy] = React.useState(); + async function save (data) { + await post('', data); + if (response.ok) { + history.push('/'); + } + } return ( - {!copy && - + {!confirm && + } - {copy && + {confirm && copy && - + } - ); } \ No newline at end of file