|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import React, { ChangeEvent } from "react"; |
| 7 | +import { EuiCompressedFormRow, EuiCompressedFieldText, EuiSpacer } from "@elastic/eui"; |
| 8 | +import { ConvertIndexToRemoteAction, UIAction } from "../../../../../models/interfaces"; |
| 9 | +import { makeId } from "../../../../utils/helpers"; |
| 10 | +import { ActionType } from "../../utils/constants"; |
| 11 | +import EuiFormCustomLabel from "../EuiFormCustomLabel"; |
| 12 | + |
| 13 | +export default class ConvertIndexToRemoteUIAction implements UIAction<ConvertIndexToRemoteAction> { |
| 14 | + id: string; |
| 15 | + action: ConvertIndexToRemoteAction; |
| 16 | + type = ActionType.ConvertIndexToRemote; |
| 17 | + |
| 18 | + constructor(action: ConvertIndexToRemoteAction, id: string = makeId()) { |
| 19 | + this.action = action; |
| 20 | + this.id = id; |
| 21 | + } |
| 22 | + |
| 23 | + content = () => `Convert Index To Remote`; |
| 24 | + |
| 25 | + clone = (action: ConvertIndexToRemoteAction) => new ConvertIndexToRemoteUIAction(action, this.id); |
| 26 | + |
| 27 | + isValid = () => { |
| 28 | + return !!this.action.convert_index_to_remote.snapshot && !!this.action.convert_index_to_remote.repository; |
| 29 | + }; |
| 30 | + |
| 31 | + render = (action: UIAction<ConvertIndexToRemoteAction>, onChangeAction: (action: UIAction<ConvertIndexToRemoteAction>) => void) => { |
| 32 | + return ( |
| 33 | + <> |
| 34 | + <EuiFormCustomLabel |
| 35 | + title="Repository" |
| 36 | + helpText="The repository name that you register through the native snapshot API operations." |
| 37 | + isInvalid={!this.isValid()} |
| 38 | + /> |
| 39 | + <EuiCompressedFormRow fullWidth isInvalid={!this.isValid()} error={null}> |
| 40 | + <EuiCompressedFieldText |
| 41 | + fullWidth |
| 42 | + value={(action.action as ConvertIndexToRemoteAction).convert_index_to_remote.repository} |
| 43 | + onChange={(e: ChangeEvent<HTMLInputElement>) => { |
| 44 | + const repository = e.target.value; |
| 45 | + onChangeAction( |
| 46 | + this.clone({ |
| 47 | + convert_index_to_remote: { |
| 48 | + ...action.action.convert_index_to_remote, |
| 49 | + repository, |
| 50 | + }, |
| 51 | + }) |
| 52 | + ); |
| 53 | + }} |
| 54 | + data-test-subj="action-render-convert-index-to-remote-repository" |
| 55 | + /> |
| 56 | + </EuiCompressedFormRow> |
| 57 | + <EuiSpacer size="s" /> |
| 58 | + <EuiFormCustomLabel title="Snapshot" helpText="The name of the snapshot." isInvalid={!this.isValid()} /> |
| 59 | + <EuiCompressedFormRow fullWidth isInvalid={!this.isValid()} error={null}> |
| 60 | + <EuiCompressedFieldText |
| 61 | + fullWidth |
| 62 | + value={(action.action as ConvertIndexToRemoteAction).convert_index_to_remote.snapshot} |
| 63 | + onChange={(e: ChangeEvent<HTMLInputElement>) => { |
| 64 | + const snapshot = e.target.value; |
| 65 | + onChangeAction( |
| 66 | + this.clone({ |
| 67 | + convert_index_to_remote: { |
| 68 | + ...action.action.convert_index_to_remote, |
| 69 | + snapshot, |
| 70 | + }, |
| 71 | + }) |
| 72 | + ); |
| 73 | + }} |
| 74 | + data-test-subj="action-render-convert-index-to-remote-snapshot" |
| 75 | + /> |
| 76 | + </EuiCompressedFormRow> |
| 77 | + </> |
| 78 | + ); |
| 79 | + }; |
| 80 | + |
| 81 | + toAction = () => this.action; |
| 82 | +} |
0 commit comments