/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ import React, { useState } from 'react'; import ReactDOM from 'react-dom' import { Modal, Button, SpaceBetween, Box, Container, Header, FormField, Input, Select, Multiselect, Checkbox, Alert, ExpandableSection, Link, Tabs } from '@awsui/components-react'; import {getNestedValuePath, setNestedValuePath} from "../resources/main"; import ToolHelpEdit from "./ToolHelpEdit"; import ToolHelp from "./ToolHelp"; import SchemaAttributeConditionsEdit from "./SchemaAttributeConditionsEdit"; type Props = { children: React.ReactChild, closeModal: () => void, confirmAction: () => void }; const SchemaAttributeAmendModal = React.memo(({ children, closeModal , confirmAction, title , attribute , action, schema, activeSchema}: Props) => { const domEl = document.getElementById('modal-root') const [localAttr, setLocalAttr] = useState(attribute); const [testRegexStr, setTestRegexStr] = useState(''); const [saving, setSaving] = useState(false); function handleUserInput (value){ let newAttr = Object.assign({}, localAttr); setNestedValuePath(newAttr, value.field, value.value); if (value.field === "rel_entity") { newAttr['rel_display_attribute'] = ''; newAttr['rel_key'] = ''; } setLocalAttr(newAttr); } function handleUserInputEditSchemaHelp(key, update) { let tempUpdate = Object.assign({}, localAttr); if (!tempUpdate.help_content){ tempUpdate['help_content'] = {}; } tempUpdate['help_content'][key] = update setLocalAttr(tempUpdate); } function handleUserInputEditSchemaConditions(key, update) { let tempUpdate = Object.assign({}, localAttr) setNestedValuePath(tempUpdate, key, update) setLocalAttr(tempUpdate); } function handleSave (e){ setSaving(true); confirmAction(localAttr, action); } function returnValidationMessage(regex , value , errorMessage){ try { return !value.match(regex) ? errorMessage : undefined; } catch (e) { return "Error in validation regular expression format: " + e.message; } } function getErrorText(localAttr){ if (localAttr.group_order && isNaN(parseInt(localAttr.group_order))){ return 'Must be a whole number.'; } else { return undefined; } } if (!domEl) return null return ReactDOM.createPortal( ) : undefined } header={title} > This is a system defined attribute, Programmatic name and Type cannot be altered. handleUserInput({field: 'name', value: event.detail.value})} readOnly={localAttr.system ? localAttr.system : false} /> handleUserInput({field: 'description', value: event.detail.value})} /> handleUserInput({field: 'long_desc', value: event.detail.value})} /> {!localAttr.system ? ( } {localAttr.type !== "relationship" ? undefined : {!localAttr.system ? } {!localAttr.system ? } {!localAttr.system ? } {!localAttr.system ? {return {label: item, value: item}})} //onChange={event => handleUserInput({field: 'rel_additional_attributes', value: event.detail.selectedOption.value})} onChange={event => handleUserInput({ field: 'rel_additional_attributes', value: event.detail.selectedOptions != null ? event.detail.selectedOptions.map(valueItem => valueItem.value) : [], })} options={ localAttr.rel_entity ? schema[localAttr.rel_entity].attributes.map((item, index) => { return { label: item.name, value: item.name }; }) : [] } selectedAriaLabel={'selected'} filteringType="auto" /> : } < Input value={localAttr.listvalue} onChange={event => handleUserInput({field: 'listvalue', value: event.detail.value})} readOnly={localAttr.system} /> {!localAttr.system ? } {!localAttr.system ? } } {localAttr.type === 'list' ? handleUserInput({field: 'listvalue', value: event.detail.value})} /> : null } {localAttr.type === 'list' || localAttr.type === 'relationship' ? handleUserInput({field: 'listMultiSelect', value: event.detail.checked})} checked={localAttr.listMultiSelect} disabled={localAttr.system ? true : false} > {'Multiple selection possible'} : null } handleUserInput({field: 'required', value: event.detail.checked})} checked={localAttr.required} disabled={localAttr.system ? true : false} > {'Attribute has to be populated'} handleUserInput({field: 'hidden', value: event.detail.checked})} checked={localAttr.hidden} disabled={localAttr.system ? true : false} > {'Attribute will not be displayed on screen.'} }, { label: 'Preview', id: 'preview_help', content: } ] } /> Attribute Grouping & Positioning (optional) } > handleUserInput({field: 'group', value: event.detail.value})} /> handleUserInput({field: 'group_order', value: event.detail.value})} /> Input validation(optional) } > A full description of this syntax and its constructs can be viewed in the Java documentation, here: > handleUserInput({field: 'validation_regex', value: event.detail.value})} /> handleUserInput({field: 'validation_regex_msg', value: event.detail.value})} /> Validation simulator } > setTestRegexStr(event.detail.value)} /> Example data } > handleUserInput({field: 'sample_data_intake', value: event.detail.value})} /> handleUserInput({field: 'sample_data_form', value: event.detail.value})} /> handleUserInput({field: 'sample_data_api', value: event.detail.value})} /> {children} , domEl ) }); export default SchemaAttributeAmendModal;