/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ import React, { ChangeEvent } from "react"; import { EuiFormRow, EuiFieldNumber } from "@elastic/eui"; import EuiFormCustomLabel from "../EuiFormCustomLabel"; import { ForceMergeAction, UIAction } from "../../../../../models/interfaces"; import { makeId } from "../../../../utils/helpers"; import { ActionType } from "../../utils/constants"; export default class ForceMergeUIAction implements UIAction { id: string; action: ForceMergeAction; type = ActionType.ForceMerge; constructor(action: ForceMergeAction, id: string = makeId()) { this.action = action; this.id = id; } content = () => `Force merge to ${this.action.force_merge.max_num_segments} segments`; clone = (action: ForceMergeAction) => new ForceMergeUIAction(action, this.id); isValid = () => { const segments = this.action.force_merge.max_num_segments; return !!segments && segments > 0; }; render = (action: UIAction, onChangeAction: (action: UIAction) => void) => { const segments = action.action.force_merge.max_num_segments; return ( <> ) => { const maxNumSegments = e.target.valueAsNumber; const forceMerge = { max_num_segments: maxNumSegments }; if (isNaN(maxNumSegments)) delete forceMerge.max_num_segments; onChangeAction(this.clone({ force_merge: forceMerge })); }} data-test-subj="action-render-force-merge" /> ); }; toAction = () => this.action; }