import { css } from '@emotion/css'; import React, { useState } from 'react'; import { GrafanaTheme2, SelectableValue } from '@grafana/data'; import { FlexItem } from '@grafana/experimental'; import { Button, Select, useStyles2 } from '@grafana/ui'; import { OperationInfoButton } from './OperationInfoButton'; import { VisualQueryModeller, QueryBuilderOperation, QueryBuilderOperationDef } from './types'; export interface Props { operation: QueryBuilderOperation; def: QueryBuilderOperationDef; index: number; queryModeller: VisualQueryModeller; dragHandleProps: any; onChange: (index: number, update: QueryBuilderOperation) => void; onRemove: (index: number) => void; } interface State { isOpen?: boolean; alternatives?: Array>; } export const OperationHeader = React.memo( ({ operation, def, index, onChange, onRemove, queryModeller, dragHandleProps }) => { const styles = useStyles2(getStyles); const [state, setState] = useState({}); const onToggleSwitcher = () => { if (state.isOpen) { setState({ ...state, isOpen: false }); } else { const alternatives = queryModeller .getAlternativeOperations(def.alternativesKey!) .map((alt) => ({ label: alt.name, value: alt })); setState({ isOpen: true, alternatives }); } }; return (
{!state.isOpen && ( <>
{def.name ?? def.id}
)} {state.isOpen && (