mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Use ToggleTip instead of Hovercard in the info popup on Math expressions (#70881)
* Use ToggleTip instead of Hovercard in the info popup on Math expressions * Address review comments
This commit is contained in:
parent
75a81e5b9f
commit
0e4a8b01ab
@ -1,3 +1,4 @@
|
|||||||
|
import { css, cx } from '@emotion/css';
|
||||||
import { Placement } from '@popperjs/core';
|
import { Placement } from '@popperjs/core';
|
||||||
import React, { useCallback, useEffect, useRef } from 'react';
|
import React, { useCallback, useEffect, useRef } from 'react';
|
||||||
import { usePopperTooltip } from 'react-popper-tooltip';
|
import { usePopperTooltip } from 'react-popper-tooltip';
|
||||||
@ -28,6 +29,8 @@ export interface ToggletipProps {
|
|||||||
footer?: JSX.Element | string;
|
footer?: JSX.Element | string;
|
||||||
/** The UI control users interact with to display toggletips */
|
/** The UI control users interact with to display toggletips */
|
||||||
children: JSX.Element;
|
children: JSX.Element;
|
||||||
|
/** Determine whether the toggletip should fit its content or not */
|
||||||
|
fitContent?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Toggletip = React.memo(
|
export const Toggletip = React.memo(
|
||||||
@ -40,6 +43,7 @@ export const Toggletip = React.memo(
|
|||||||
closeButton = true,
|
closeButton = true,
|
||||||
onClose,
|
onClose,
|
||||||
footer,
|
footer,
|
||||||
|
fitContent = false,
|
||||||
}: ToggletipProps) => {
|
}: ToggletipProps) => {
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
const style = styles[theme];
|
const style = styles[theme];
|
||||||
@ -91,7 +95,7 @@ export const Toggletip = React.memo(
|
|||||||
<div
|
<div
|
||||||
data-testid="toggletip-content"
|
data-testid="toggletip-content"
|
||||||
ref={setTooltipRef}
|
ref={setTooltipRef}
|
||||||
{...getTooltipProps({ className: style.container })}
|
{...getTooltipProps({ className: cx(style.container, fitContent && styles.fitContent) })}
|
||||||
>
|
>
|
||||||
{Boolean(title) && <div className={style.header}>{title}</div>}
|
{Boolean(title) && <div className={style.header}>{title}</div>}
|
||||||
{closeButton && (
|
{closeButton && (
|
||||||
@ -139,5 +143,8 @@ export const getStyles = (theme: GrafanaTheme2) => {
|
|||||||
return {
|
return {
|
||||||
info,
|
info,
|
||||||
error,
|
error,
|
||||||
|
fitContent: css`
|
||||||
|
max-width: fit-content;
|
||||||
|
`,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -3,8 +3,7 @@ import React, { ChangeEvent } from 'react';
|
|||||||
|
|
||||||
import { GrafanaTheme2 } from '@grafana/data';
|
import { GrafanaTheme2 } from '@grafana/data';
|
||||||
import { Stack } from '@grafana/experimental';
|
import { Stack } from '@grafana/experimental';
|
||||||
import { Icon, InlineField, InlineLabel, TextArea, useStyles2 } from '@grafana/ui';
|
import { Icon, InlineField, InlineLabel, TextArea, Toggletip, useStyles2 } from '@grafana/ui';
|
||||||
import { HoverCard } from 'app/features/alerting/unified/components/HoverCard';
|
|
||||||
|
|
||||||
import { ExpressionQuery } from '../types';
|
import { ExpressionQuery } from '../types';
|
||||||
|
|
||||||
@ -37,12 +36,10 @@ export const Math = ({ labelWidth, onChange, query, onRunQuery }: Props) => {
|
|||||||
<InlineField
|
<InlineField
|
||||||
label={
|
label={
|
||||||
<InlineLabel width="auto">
|
<InlineLabel width="auto">
|
||||||
<HoverCard
|
<Toggletip
|
||||||
|
fitContent
|
||||||
content={
|
content={
|
||||||
<div className={styles.documentationContainer}>
|
<div className={styles.documentationContainer}>
|
||||||
<header className={styles.documentationHeader}>
|
|
||||||
<Icon name="book-open" /> Math operator
|
|
||||||
</header>
|
|
||||||
<div>
|
<div>
|
||||||
Run math operations on one or more queries. You reference the query by {'${refId}'} ie. $A, $B, $C
|
Run math operations on one or more queries. You reference the query by {'${refId}'} ie. $A, $B, $C
|
||||||
etc.
|
etc.
|
||||||
@ -92,25 +89,34 @@ export const Math = ({ labelWidth, onChange, query, onRunQuery }: Props) => {
|
|||||||
description="rounds the number down to the nearest integer value. It's able to operate on series or escalar values."
|
description="rounds the number down to the nearest integer value. It's able to operate on series or escalar values."
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
See our additional documentation on{' '}
|
|
||||||
<a
|
|
||||||
className={styles.documentationLink}
|
|
||||||
target="_blank"
|
|
||||||
href="https://grafana.com/docs/grafana/latest/panels/query-a-data-source/use-expressions-to-manipulate-data/about-expressions/#math"
|
|
||||||
rel="noreferrer"
|
|
||||||
>
|
|
||||||
<Icon size="xs" name="external-link-alt" /> Math expressions
|
|
||||||
</a>
|
|
||||||
.
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
title={
|
||||||
|
<Stack gap={1} direction="row">
|
||||||
|
<Icon name="book-open" /> Math operator
|
||||||
|
</Stack>
|
||||||
|
}
|
||||||
|
footer={
|
||||||
|
<div>
|
||||||
|
See our additional documentation on{' '}
|
||||||
|
<a
|
||||||
|
className={styles.documentationLink}
|
||||||
|
target="_blank"
|
||||||
|
href="https://grafana.com/docs/grafana/latest/panels/query-a-data-source/use-expressions-to-manipulate-data/about-expressions/#math"
|
||||||
|
rel="noreferrer"
|
||||||
|
>
|
||||||
|
<Icon size="xs" name="external-link-alt" /> Math expressions
|
||||||
|
</a>
|
||||||
|
.
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
closeButton={true}
|
||||||
|
placement="bottom-start"
|
||||||
>
|
>
|
||||||
<span>
|
<div className={styles.info}>
|
||||||
Expression <Icon name="info-circle" />
|
Expression <Icon name="info-circle" />
|
||||||
</span>
|
</div>
|
||||||
</HoverCard>
|
</Toggletip>
|
||||||
</InlineLabel>
|
</InlineLabel>
|
||||||
}
|
}
|
||||||
labelWidth={labelWidth}
|
labelWidth={labelWidth}
|
||||||
@ -166,6 +172,13 @@ const getStyles = (theme: GrafanaTheme2) => ({
|
|||||||
grid-template-columns: max-content auto;
|
grid-template-columns: max-content auto;
|
||||||
column-gap: ${theme.spacing(2)};
|
column-gap: ${theme.spacing(2)};
|
||||||
`,
|
`,
|
||||||
|
info: css`
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
cursor: pointer;
|
||||||
|
gap: ${theme.spacing(1)};
|
||||||
|
`,
|
||||||
});
|
});
|
||||||
|
|
||||||
const getDocumentedFunctionStyles = (theme: GrafanaTheme2) => ({
|
const getDocumentedFunctionStyles = (theme: GrafanaTheme2) => ({
|
||||||
|
Loading…
Reference in New Issue
Block a user