/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ import React, { Component } from "react"; import { EuiButton, EuiButtonEmpty, EuiModal, EuiModalBody, EuiModalFooter, EuiModalHeader, EuiModalHeaderTitle, EuiOverlayMask, EuiFormRow, EuiFieldText, } from "@elastic/eui"; import { BrowserServices } from "../../../../models/interfaces"; import { getErrorMessage } from "../../../../utils/helpers"; import { CoreServicesContext } from "../../../../components/core_services"; interface RolloverAliasModalProps { onClose: () => void; services: BrowserServices; index: string; } interface RolloverAliasModalState { rolloverAlias: string; } export default class RolloverAliasModal extends Component { static contextType = CoreServicesContext; state: RolloverAliasModalState = { rolloverAlias: "", }; onEditRolloverAlias = async (): Promise => { const { onClose, index, services: { indexService }, } = this.props; const { rolloverAlias } = this.state; try { const response = await indexService.editRolloverAlias(index, rolloverAlias); if (response.ok) { if (response.response.acknowledged) { this.context.notifications.toasts.addSuccess(`Edited rollover alias on ${index}`); } else { this.context.notifications.toasts.addDanger(`Failed to edit rollover alias on ${index}`); } } else { this.context.notifications.toasts.addDanger(response.error); } onClose(); } catch (err) { this.context.notifications.toasts.addDanger(getErrorMessage(err, `There was a problem editing rollover alias on ${index}`)); } }; onChange = (e: React.ChangeEvent): void => { this.setState({ rolloverAlias: e.target.value }); }; render() { const { rolloverAlias } = this.state; const { onClose } = this.props; return ( {/* // @ts-ignore */} Edit rollover alias Close Edit ); } }