mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Query builder operation docs popover improvements (#46006)
This commit is contained in:
@@ -3,8 +3,7 @@ import { GrafanaTheme2, renderMarkdown } from '@grafana/data';
|
|||||||
import { FlexItem } from '@grafana/experimental';
|
import { FlexItem } from '@grafana/experimental';
|
||||||
import { Button, Portal, useStyles2 } from '@grafana/ui';
|
import { Button, Portal, useStyles2 } from '@grafana/ui';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { usePopper } from 'react-popper';
|
import { usePopperTooltip } from 'react-popper-tooltip';
|
||||||
import { useToggle } from 'react-use';
|
|
||||||
import { QueryBuilderOperation, QueryBuilderOperationDef } from './types';
|
import { QueryBuilderOperation, QueryBuilderOperationDef } from './types';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
@@ -14,41 +13,39 @@ export interface Props {
|
|||||||
|
|
||||||
export const OperationInfoButton = React.memo<Props>(({ def, operation }) => {
|
export const OperationInfoButton = React.memo<Props>(({ def, operation }) => {
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
const [popperTrigger, setPopperTrigger] = useState<HTMLButtonElement | null>(null);
|
const [show, setShow] = useState(false);
|
||||||
const [popover, setPopover] = useState<HTMLDivElement | null>(null);
|
const { getTooltipProps, setTooltipRef, setTriggerRef, visible } = usePopperTooltip({
|
||||||
const [isOpen, toggleIsOpen] = useToggle(false);
|
|
||||||
|
|
||||||
const popper = usePopper(popperTrigger, popover, {
|
|
||||||
placement: 'top',
|
placement: 'top',
|
||||||
modifiers: [
|
visible: show,
|
||||||
{ name: 'arrow', enabled: true },
|
offset: [0, 16],
|
||||||
{
|
onVisibleChange: setShow,
|
||||||
name: 'preventOverflow',
|
interactive: true,
|
||||||
enabled: true,
|
trigger: ['click'],
|
||||||
options: {
|
|
||||||
rootBoundary: 'viewport',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
ref={setPopperTrigger}
|
title="Click to show description"
|
||||||
|
ref={setTriggerRef}
|
||||||
icon="info-circle"
|
icon="info-circle"
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
fill="text"
|
fill="text"
|
||||||
onClick={toggleIsOpen}
|
|
||||||
/>
|
/>
|
||||||
{isOpen && (
|
{visible && (
|
||||||
<Portal>
|
<Portal>
|
||||||
<div ref={setPopover} style={popper.styles.popper} {...popper.attributes.popper} className={styles.docBox}>
|
<div ref={setTooltipRef} {...getTooltipProps()} className={styles.docBox}>
|
||||||
<div className={styles.docBoxHeader}>
|
<div className={styles.docBoxHeader}>
|
||||||
<span>{def.renderer(operation, def, '<expr>')}</span>
|
<span>{def.renderer(operation, def, '<expr>')}</span>
|
||||||
<FlexItem grow={1} />
|
<FlexItem grow={1} />
|
||||||
<Button icon="times" onClick={toggleIsOpen} fill="text" variant="secondary" title="Remove operation" />
|
<Button
|
||||||
|
icon="times"
|
||||||
|
onClick={() => setShow(false)}
|
||||||
|
fill="text"
|
||||||
|
variant="secondary"
|
||||||
|
title="Remove operation"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={styles.docBoxBody}
|
className={styles.docBoxBody}
|
||||||
@@ -67,9 +64,9 @@ const getStyles = (theme: GrafanaTheme2) => {
|
|||||||
return {
|
return {
|
||||||
docBox: css({
|
docBox: css({
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
background: theme.colors.background.canvas,
|
background: theme.colors.background.primary,
|
||||||
border: `1px solid ${theme.colors.border.strong}`,
|
border: `1px solid ${theme.colors.border.strong}`,
|
||||||
boxShadow: theme.shadows.z2,
|
boxShadow: theme.shadows.z3,
|
||||||
maxWidth: '600px',
|
maxWidth: '600px',
|
||||||
padding: theme.spacing(1),
|
padding: theme.spacing(1),
|
||||||
borderRadius: theme.shape.borderRadius(),
|
borderRadius: theme.shape.borderRadius(),
|
||||||
|
|||||||
Reference in New Issue
Block a user