diff --git a/public/app/plugins/datasource/loki/querybuilder/components/LokiQueryEditorSelector.tsx b/public/app/plugins/datasource/loki/querybuilder/components/LokiQueryEditorSelector.tsx index 498ec229885..98864f2d872 100644 --- a/public/app/plugins/datasource/loki/querybuilder/components/LokiQueryEditorSelector.tsx +++ b/public/app/plugins/datasource/loki/querybuilder/components/LokiQueryEditorSelector.tsx @@ -1,12 +1,14 @@ import { css } from '@emotion/css'; import { GrafanaTheme2, LoadingState } from '@grafana/data'; -import { EditorHeader, FlexItem, InlineSelect, Space, Stack } from '@grafana/experimental'; -import { Button, Switch, useStyles2 } from '@grafana/ui'; +import { EditorHeader, FlexItem, InlineSelect, Space } from '@grafana/experimental'; +import { Button, useStyles2 } from '@grafana/ui'; import { QueryEditorModeToggle } from 'app/plugins/datasource/prometheus/querybuilder/shared/QueryEditorModeToggle'; +import { QueryHeaderSwitch } from 'app/plugins/datasource/prometheus/querybuilder/shared/QueryHeaderSwitch'; import { QueryEditorMode } from 'app/plugins/datasource/prometheus/querybuilder/shared/types'; -import React, { useCallback, useState } from 'react'; +import React, { SyntheticEvent, useCallback, useState } from 'react'; import { LokiQueryEditor } from '../../components/LokiQueryEditor'; import { LokiQueryEditorProps } from '../../components/types'; +import { LokiQueryType } from '../../types'; import { lokiQueryModeller } from '../LokiQueryModeller'; import { getDefaultEmptyQuery, LokiVisualQuery } from '../types'; import { LokiQueryBuilder } from './LokiQueryBuilder'; @@ -35,6 +37,11 @@ export const LokiQueryEditorSelector = React.memo((props) }); }; + const onInstantChange = (event: SyntheticEvent) => { + onChange({ ...query, queryType: event.currentTarget.checked ? LokiQueryType.Instant : LokiQueryType.Range }); + onRunQuery(); + }; + // If no expr (ie new query) then default to builder const editorMode = query.editorMode ?? (query.expr ? QueryEditorMode.Code : QueryEditorMode.Builder); @@ -53,14 +60,11 @@ export const LokiQueryEditorSelector = React.memo((props) > Run query - - - - - - - - + ((props) > Run query - - - - + {showExemplarSwitch && ( - - - - + )} {editorMode === QueryEditorMode.Builder && ( <> diff --git a/public/app/plugins/datasource/prometheus/querybuilder/shared/QueryHeaderSwitch.tsx b/public/app/plugins/datasource/prometheus/querybuilder/shared/QueryHeaderSwitch.tsx new file mode 100644 index 00000000000..2df17673f48 --- /dev/null +++ b/public/app/plugins/datasource/prometheus/querybuilder/shared/QueryHeaderSwitch.tsx @@ -0,0 +1,38 @@ +import { css } from '@emotion/css'; +import { GrafanaTheme2 } from '@grafana/data'; +import { Stack } from '@grafana/experimental'; +import { Switch, useStyles2 } from '@grafana/ui'; +import { uniqueId } from 'lodash'; +import React, { HTMLProps, useRef } from 'react'; + +export interface Props extends Omit, 'value' | 'ref'> { + value?: boolean; + label: string; +} + +export function QueryHeaderSwitch({ label, ...inputProps }: Props) { + const switchIdRef = useRef(uniqueId(`switch-${label}`)); + const styles = useStyles2(getStyles); + + return ( + + + + + ); +} + +const getStyles = (theme: GrafanaTheme2) => { + return { + switchLabel: css({ + color: theme.colors.text.secondary, + cursor: 'pointer', + fontSize: theme.typography.bodySmall.fontSize, + '&:hover': { + color: theme.colors.text.primary, + }, + }), + }; +};