import React from 'react'; import { PopoverController, Popover } from '@grafana/ui'; // @ts-ignore import rst2html from 'rst2html'; import { FunctionDescriptor, FunctionEditorControlsProps, FunctionEditorControls } from './FunctionEditorControls'; interface FunctionEditorProps extends FunctionEditorControlsProps { func: FunctionDescriptor; } interface FunctionEditorState { showingDescription: boolean; } class FunctionEditor extends React.PureComponent { private triggerRef = React.createRef(); constructor(props: FunctionEditorProps) { super(props); this.state = { showingDescription: false, }; } renderContent = ({ updatePopperPosition }: any) => { const { onMoveLeft, onMoveRight, func: { def: { name, description }, }, } = this.props; const { showingDescription } = this.state; if (showingDescription) { return (

{name}

); } return ( { onMoveLeft(this.props.func); updatePopperPosition(); }} onMoveRight={() => { onMoveRight(this.props.func); updatePopperPosition(); }} onDescriptionShow={() => { this.setState({ showingDescription: true }, () => { updatePopperPosition(); }); }} /> ); }; render() { return ( {(showPopper, hidePopper, popperProps) => { return ( <> {this.triggerRef && ( { this.setState({ showingDescription: false }); hidePopper(); }} onMouseEnter={showPopper} renderArrow={({ arrowProps, placement }) => (
)} /> )} { hidePopper(); this.setState({ showingDescription: false }); }} style={{ cursor: 'pointer' }} > {this.props.func.def.name} ); }} ); } } export { FunctionEditor };