/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ import React, { ChangeEvent } from "react"; import { EuiFormRow, EuiFieldText, EuiSpacer } from "@elastic/eui"; import { SnapshotAction, UIAction } from "../../../../../models/interfaces"; import { makeId } from "../../../../utils/helpers"; import { ActionType } from "../../utils/constants"; import EuiFormCustomLabel from "../EuiFormCustomLabel"; export default class SnapshotUIAction implements UIAction { id: string; action: SnapshotAction; type = ActionType.Snapshot; constructor(action: SnapshotAction, id: string = makeId()) { this.action = action; this.id = id; } content = () => `Snapshot`; clone = (action: SnapshotAction) => new SnapshotUIAction(action, this.id); isValid = () => { return !!this.action.snapshot.snapshot && !!this.action.snapshot.repository; }; render = (action: UIAction, onChangeAction: (action: UIAction) => void) => { return ( <> ) => { const repository = e.target.value; onChangeAction( this.clone({ snapshot: { ...action.action.snapshot, repository, }, }) ); }} data-test-subj="action-render-snapshot-repository" /> ) => { const snapshot = e.target.value; onChangeAction( this.clone({ snapshot: { ...action.action.snapshot, snapshot, }, }) ); }} data-test-subj="action-render-snapshot-snapshot" /> ); }; toAction = () => this.action; }