/* * Copyright OpenSearch Contributors * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://www.apache.org/licenses/LICENSE-2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ import { EuiButton, EuiButtonEmpty, EuiModal, EuiModalBody, EuiModalFooter, EuiModalHeader, EuiModalHeaderTitle, EuiOverlayMask, EuiForm, EuiComboBox, } from '@elastic/eui'; import React, { useState } from 'react'; import { ComboBoxOptions, Action } from '../../types'; import { stringToComboBoxOption, comboBoxOptionToString, appendOptionToComboBoxHandler, } from '../../utils/combo-box-utils'; import { FormRow } from '../../utils/form-row'; import { NameRow } from '../../utils/name-row'; interface PermissionEditModalDeps { groupName: string; action: Action; allowedActions: string[]; optionUniverse: ComboBoxOptions; handleClose: () => void; handleSave: (groupName: string, allowedActions: string[]) => Promise; } const TITLE_DICT: { [key: string]: string } = { [Action.create]: 'Create new action group', [Action.edit]: 'Edit action group', [Action.duplicate]: 'Duplicate action group', }; export function PermissionEditModal(props: PermissionEditModalDeps) { const [groupName, setGroupName] = useState(props.groupName); const [allowedActions, setAllowedActions] = useState( props.allowedActions.map(stringToComboBoxOption) ); const [isFormValid, setIsFormValid] = useState(true); return ( {TITLE_DICT[props.action]} Cancel { await props.handleSave(groupName, allowedActions.map(comboBoxOptionToString)); }} fill disabled={!isFormValid} > {props.action === Action.create ? 'Create' : 'Save'} ); }