From 1a7ca3f0de35d8e81d0e67c18f51e0ea95926e1f Mon Sep 17 00:00:00 2001 From: Gilles De Mey Date: Mon, 16 May 2022 11:30:27 +0200 Subject: [PATCH] Expressions: adds inline documentation for the Math expression (#48784) --- .../src/components/Forms/InlineField.tsx | 11 +- .../features/expressions/components/Math.tsx | 153 ++++++++++++++++-- 2 files changed, 147 insertions(+), 17 deletions(-) diff --git a/packages/grafana-ui/src/components/Forms/InlineField.tsx b/packages/grafana-ui/src/components/Forms/InlineField.tsx index a46ec3d642f..4e249d2b537 100644 --- a/packages/grafana-ui/src/components/Forms/InlineField.tsx +++ b/packages/grafana-ui/src/components/Forms/InlineField.tsx @@ -18,6 +18,8 @@ export interface Props extends Omit = ({ className, htmlFor, grow, + shrink, error, transparent, interactive, ...htmlProps }) => { const theme = useTheme2(); - const styles = getStyles(theme, grow); + const styles = getStyles(theme, grow, shrink); const inputId = htmlFor ?? getChildId(children); const labelElement = @@ -79,7 +82,7 @@ export const InlineField: FC = ({ InlineField.displayName = 'InlineField'; -const getStyles = (theme: GrafanaTheme2, grow?: boolean) => { +const getStyles = (theme: GrafanaTheme2, grow?: boolean, shrink?: boolean) => { return { container: css` display: flex; @@ -87,11 +90,11 @@ const getStyles = (theme: GrafanaTheme2, grow?: boolean) => { align-items: flex-start; text-align: left; position: relative; - flex: ${grow ? 1 : 0} 0 auto; + flex: ${grow ? 1 : 0} ${shrink ? 1 : 0} auto; margin: 0 ${theme.spacing(0.5)} ${theme.spacing(0.5)} 0; `, childContainer: css` - flex: ${grow ? 1 : 0} 0 auto; + flex: ${grow ? 1 : 0} ${shrink ? 1 : 0} auto; `, fieldValidationWrapper: css` margin-top: ${theme.spacing(0.5)}; diff --git a/public/app/features/expressions/components/Math.tsx b/public/app/features/expressions/components/Math.tsx index 140e569b20b..712fec63412 100644 --- a/public/app/features/expressions/components/Math.tsx +++ b/public/app/features/expressions/components/Math.tsx @@ -1,7 +1,10 @@ import { css } from '@emotion/css'; import React, { ChangeEvent, FC } from 'react'; +import { useToggle } from 'react-use'; -import { InlineField, TextArea } from '@grafana/ui'; +import { GrafanaTheme2 } from '@grafana/data'; +import { Stack } from '@grafana/experimental'; +import { Button, Icon, InlineField, TextArea, useStyles2 } from '@grafana/ui'; import { ExpressionQuery } from '../types'; @@ -12,24 +15,148 @@ interface Props { } const mathPlaceholder = - 'Math operations on one more queries, you reference the query by ${refId} ie. $A, $B, $C etc\n' + - 'Example: $A + $B\n' + - 'Available functions: abs(), log(), is_number(), round(), ceil(), floor(), is_inf(), is_nan(), is_null(), '; + 'Math operations on one or more queries. You reference the query by ${refId} ie. $A, $B, $C etc\n' + + 'The sum of two scalar values: $A + $B > 10'; export const Math: FC = ({ labelWidth, onChange, query }) => { + const [showHelp, toggleShowHelp] = useToggle(true); + const onExpressionChange = (event: ChangeEvent) => { onChange({ ...query, expression: event.target.value }); }; + const styles = useStyles2((theme) => getStyles(theme, showHelp)); + return ( - -