import React, { useRef } from 'react'; import { PopoverController, Popover, ClickOutsideWrapper, Icon, Tooltip, useStyles2 } from '@grafana/ui'; import { FunctionEditorControls, FunctionEditorControlsProps } from './FunctionEditorControls'; import { FuncInstance } from '../gfunc'; import { css } from '@emotion/css'; import { GrafanaTheme2 } from '@grafana/data'; interface FunctionEditorProps extends FunctionEditorControlsProps { func: FuncInstance; } const getStyles = (theme: GrafanaTheme2) => { return { icon: css` margin-right: ${theme.spacing(0.5)}; `, label: css({ fontWeight: theme.typography.fontWeightMedium, fontSize: theme.typography.bodySmall.fontSize, // to match .gf-form-label cursor: 'pointer', display: 'inline-block', paddingBottom: '2px', }), }; }; const FunctionEditor: React.FC = ({ onMoveLeft, onMoveRight, func, ...props }) => { const triggerRef = useRef(null); const styles = useStyles2(getStyles); const renderContent = ({ updatePopperPosition }: any) => ( { onMoveLeft(func); updatePopperPosition(); }} onMoveRight={() => { onMoveRight(func); updatePopperPosition(); }} /> ); return ( {(showPopper, hidePopper, popperProps) => { return ( <> {triggerRef.current && ( (
)} /> )} { if (popperProps.show) { hidePopper(); } }} > {func.def.unknown && ( } placement="bottom"> )} {func.def.name} ); }} ); }; const TooltipContent = React.memo(() => { return ( This function is not supported. Check your function for typos and{' '} read the docs {' '} to see whether you need to upgrade your data source’s version to make this function available. ); }); TooltipContent.displayName = 'FunctionEditorTooltipContent'; export { FunctionEditor };