/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ import React, { useState } from "react"; import { EuiButton, EuiFlexGroup, EuiFlexItem, EuiForm, EuiFormRow, EuiPanel, EuiCodeEditor, EuiSpacer } from "@elastic/eui"; import { TRANSFORM_AGG_TYPE, TransformAggItem } from "../../../../../../../models/interfaces"; interface ScriptedMetricsPanelProps { name: string; aggSelection: any; handleAggSelectionChange: (aggItem: TransformAggItem) => void; closePopover: () => void; } export default function ScriptedMetricsPanel({ name, aggSelection, handleAggSelectionChange, closePopover }: ScriptedMetricsPanelProps) { const [script, setScript] = useState(""); return ( setScript(value)} mode="json" /> closePopover()}> Cancel { const aggItem: TransformAggItem = { type: TRANSFORM_AGG_TYPE.scripted_metric, name: `scripted_metric_${name}`, item: { scripted_metric: JSON.parse(script), }, }; aggSelection[`scripted_metric_${name}`] = { scripted_metric: JSON.parse(script), }; handleAggSelectionChange(aggItem); }} style={{ minWidth: 55 }} > OK ); }