diff --git a/public/app/plugins/datasource/prometheus/components/PromExploreExtraField.test.tsx b/public/app/plugins/datasource/prometheus/components/PromExploreExtraField.test.tsx index ab9901d1b5a..a0dc88def26 100644 --- a/public/app/plugins/datasource/prometheus/components/PromExploreExtraField.test.tsx +++ b/public/app/plugins/datasource/prometheus/components/PromExploreExtraField.test.tsx @@ -1,28 +1,35 @@ import React from 'react'; -import { shallow } from 'enzyme'; -import { PromExploreExtraField, PromExploreExtraFieldProps } from './PromExploreExtraField'; +import { render, screen } from '@testing-library/react'; +import { PromExploreExtraFieldProps, PromExploreExtraField } from './PromExploreExtraField'; const setup = (propOverrides?: PromExploreExtraFieldProps) => { - const label = 'Prometheus Explore Extra Field'; - const value = '123'; - const onChangeFunc = jest.fn(); + const queryType = 'range'; + const stepValue = '1'; + const onStepChange = jest.fn(); + const onQueryTypeChange = jest.fn(); const onKeyDownFunc = jest.fn(); const props: any = { - label, - value, - onChangeFunc, + queryType, + stepValue, + onStepChange, + onQueryTypeChange, onKeyDownFunc, }; Object.assign(props, propOverrides); - return shallow(); + return render(); }; -describe('PrometheusExploreExtraField', () => { - it('should render component', () => { - const wrapper = setup(); - expect(wrapper).toMatchSnapshot(); +describe('PromExploreExtraField', () => { + it('should render step field', () => { + setup(); + expect(screen.getByTestId('stepField')).toBeInTheDocument(); + }); + + it('should render query type field', () => { + setup(); + expect(screen.getByTestId('queryTypeField')).toBeInTheDocument(); }); }); diff --git a/public/app/plugins/datasource/prometheus/components/PromExploreExtraField.tsx b/public/app/plugins/datasource/prometheus/components/PromExploreExtraField.tsx index 8c7e300df7a..2c05ed14c31 100644 --- a/public/app/plugins/datasource/prometheus/components/PromExploreExtraField.tsx +++ b/public/app/plugins/datasource/prometheus/components/PromExploreExtraField.tsx @@ -1,38 +1,72 @@ // Libraries import React, { memo } from 'react'; +import { css, cx } from 'emotion'; // Types -import { InlineFormLabel } from '@grafana/ui'; +import { InlineFormLabel, RadioButtonGroup } from '@grafana/ui'; export interface PromExploreExtraFieldProps { - label: string; - onChangeFunc: (e: React.SyntheticEvent) => void; + queryType: string; + stepValue: string; + onStepChange: (e: React.SyntheticEvent) => void; onKeyDownFunc: (e: React.KeyboardEvent) => void; - value: string; - hasTooltip?: boolean; - tooltipContent?: string; + onQueryTypeChange: (value: string) => void; } -export function PromExploreExtraField(props: PromExploreExtraFieldProps) { - const { label, onChangeFunc, onKeyDownFunc, value, hasTooltip, tooltipContent } = props; +export const PromExploreExtraField: React.FC = memo( + ({ queryType, stepValue, onStepChange, onQueryTypeChange, onKeyDownFunc }) => { + const rangeOptions = [ + { value: 'range', label: 'Range' }, + { value: 'instant', label: 'Instant' }, + { value: 'both', label: 'Both' }, + ]; - return ( -
-
- - {label} - - + return ( +
+ {/*QueryTypeField */} +
+ Query type + + +
+ {/*Step field*/} +
+ + Step + + +
-
- ); -} - -export default memo(PromExploreExtraField); + ); + } +); diff --git a/public/app/plugins/datasource/prometheus/components/PromExploreQueryEditor.tsx b/public/app/plugins/datasource/prometheus/components/PromExploreQueryEditor.tsx index 676adee1491..18dc1cdace0 100644 --- a/public/app/plugins/datasource/prometheus/components/PromExploreQueryEditor.tsx +++ b/public/app/plugins/datasource/prometheus/components/PromExploreQueryEditor.tsx @@ -1,9 +1,7 @@ import React, { memo, FC } from 'react'; -import { css } from 'emotion'; // Types import { ExploreQueryFieldProps } from '@grafana/data'; -import { RadioButtonGroup } from '@grafana/ui'; import { PrometheusDatasource } from '../datasource'; import { PromQuery, PromOptions } from '../types'; @@ -28,6 +26,12 @@ export const PromExploreQueryEditor: FC = (props: Props) => { } } + function onReturnKeyDown(e: React.KeyboardEvent) { + if (e.key === 'Enter' && (e.shiftKey || e.ctrlKey)) { + onRunQuery(); + } + } + function onQueryTypeChange(value: string) { const { query, onChange } = props; let nextQuery; @@ -41,69 +45,25 @@ export const PromExploreQueryEditor: FC = (props: Props) => { onChange(nextQuery); } - function onReturnKeyDown(e: React.KeyboardEvent) { - if (e.key === 'Enter') { - onRunQuery(); - } - } - return ( - <> - {}} - history={history} - data={data} - ExtraFieldElement={ - - } - /> - - - ); -}; - -type PromExploreRadioButtonProps = { - selected: string; - onQueryTypeChange: (value: string) => void; -}; - -const PromExploreRadioButton: React.FunctionComponent = ({ - selected, - onQueryTypeChange, -}) => { - const rangeOptions = [ - { value: 'range', label: 'Range' }, - { value: 'instant', label: 'Instant' }, - { value: 'both', label: 'Both' }, - ]; - - return ( -
- - -
+ {}} + history={history} + data={data} + ExtraFieldElement={ + + } + /> ); }; diff --git a/public/app/plugins/datasource/prometheus/components/PromQueryField.tsx b/public/app/plugins/datasource/prometheus/components/PromQueryField.tsx index b03f6c2ed69..afef93577a3 100644 --- a/public/app/plugins/datasource/prometheus/components/PromQueryField.tsx +++ b/public/app/plugins/datasource/prometheus/components/PromQueryField.tsx @@ -331,7 +331,7 @@ class PromQueryField extends React.PureComponent
-
+
- {ExtraFieldElement}
+ {ExtraFieldElement} {hint ? (
diff --git a/public/app/plugins/datasource/prometheus/components/__snapshots__/PromExploreExtraField.test.tsx.snap b/public/app/plugins/datasource/prometheus/components/__snapshots__/PromExploreExtraField.test.tsx.snap deleted file mode 100644 index 140e32ece72..00000000000 --- a/public/app/plugins/datasource/prometheus/components/__snapshots__/PromExploreExtraField.test.tsx.snap +++ /dev/null @@ -1,26 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`PrometheusExploreExtraField should render component 1`] = ` -
-
- - Prometheus Explore Extra Field - - -
-
-`; diff --git a/public/app/plugins/datasource/prometheus/components/__snapshots__/PromExploreQueryEditor.test.tsx.snap b/public/app/plugins/datasource/prometheus/components/__snapshots__/PromExploreQueryEditor.test.tsx.snap index 59ec675cbf2..6012d55660c 100644 --- a/public/app/plugins/datasource/prometheus/components/__snapshots__/PromExploreQueryEditor.test.tsx.snap +++ b/public/app/plugins/datasource/prometheus/components/__snapshots__/PromExploreQueryEditor.test.tsx.snap @@ -1,43 +1,25 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`PromExploreQueryEditor should render component 1`] = ` - - - } - data={ - Object { - "request": Object { - "app": "Grafana", - "dashboardId": 1, - "interval": "1s", - "intervalMs": 1000, - "panelId": 1, - "range": Object { - "from": "2020-01-01T00:00:00.000Z", - "raw": Object { - "from": "2020-01-01T00:00:00.000Z", - "to": "2020-01-02T00:00:00.000Z", - }, - "to": "2020-01-02T00:00:00.000Z", - }, - "requestId": "1", - "scopedVars": Object {}, - "startTime": 0, - "targets": Array [], - "timezone": "GMT", - }, - "series": Array [], - "state": "NotStarted", - "timeRange": Object { + + } + data={ + Object { + "request": Object { + "app": "Grafana", + "dashboardId": 1, + "interval": "1s", + "intervalMs": 1000, + "panelId": 1, + "range": Object { "from": "2020-01-01T00:00:00.000Z", "raw": Object { "from": "2020-01-01T00:00:00.000Z", @@ -45,24 +27,35 @@ exports[`PromExploreQueryEditor should render component 1`] = ` }, "to": "2020-01-02T00:00:00.000Z", }, - } + "requestId": "1", + "scopedVars": Object {}, + "startTime": 0, + "targets": Array [], + "timezone": "GMT", + }, + "series": Array [], + "state": "NotStarted", + "timeRange": Object { + "from": "2020-01-01T00:00:00.000Z", + "raw": Object { + "from": "2020-01-01T00:00:00.000Z", + "to": "2020-01-02T00:00:00.000Z", + }, + "to": "2020-01-02T00:00:00.000Z", + }, } - datasource={Object {}} - history={Array []} - onBlur={[Function]} - onChange={[MockFunction]} - onRunQuery={[MockFunction]} - query={ - Object { - "expr": "", - "interval": "1s", - "refId": "A", - } + } + datasource={Object {}} + history={Array []} + onBlur={[Function]} + onChange={[MockFunction]} + onRunQuery={[MockFunction]} + query={ + Object { + "expr": "", + "interval": "1s", + "refId": "A", } - /> - - + } +/> `;