mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Elasticsearch: Show Size setting for raw_data metric (#30980)
This commit is contained in:
parent
50da456bd0
commit
0a7c6c689f
@ -0,0 +1,80 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { fireEvent, render, screen } from '@testing-library/react';
|
||||||
|
import { SettingsEditor } from '.';
|
||||||
|
import { ElasticsearchProvider } from '../../ElasticsearchQueryContext';
|
||||||
|
import { ElasticDatasource } from 'app/plugins/datasource/elasticsearch/datasource';
|
||||||
|
import { ElasticsearchQuery } from 'app/plugins/datasource/elasticsearch/types';
|
||||||
|
|
||||||
|
describe('Settings Editor', () => {
|
||||||
|
describe('Raw Data', () => {
|
||||||
|
it('Should correctly render the settings editor and trigger correct state changes', () => {
|
||||||
|
const metricId = '1';
|
||||||
|
const initialSize = '500';
|
||||||
|
const query: ElasticsearchQuery = {
|
||||||
|
refId: 'A',
|
||||||
|
metrics: [
|
||||||
|
{
|
||||||
|
id: metricId,
|
||||||
|
type: 'raw_data',
|
||||||
|
settings: {
|
||||||
|
size: initialSize,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const onChange = jest.fn();
|
||||||
|
|
||||||
|
const { rerender } = render(
|
||||||
|
<ElasticsearchProvider
|
||||||
|
query={query}
|
||||||
|
datasource={{} as ElasticDatasource}
|
||||||
|
onChange={onChange}
|
||||||
|
onRunQuery={() => {}}
|
||||||
|
>
|
||||||
|
<SettingsEditor metric={query.metrics![0]} previousMetrics={[]} />
|
||||||
|
</ElasticsearchProvider>
|
||||||
|
);
|
||||||
|
|
||||||
|
let settingsButtonEl = screen.getByRole('button', {
|
||||||
|
name: /Size: \d+$/i,
|
||||||
|
});
|
||||||
|
|
||||||
|
// The metric row should have a settings button
|
||||||
|
expect(settingsButtonEl).toBeInTheDocument();
|
||||||
|
expect(settingsButtonEl.textContent).toBe(`Size: ${initialSize}`);
|
||||||
|
|
||||||
|
// Open the settings editor
|
||||||
|
fireEvent.click(settingsButtonEl);
|
||||||
|
|
||||||
|
// The settings editor should have a Size input
|
||||||
|
const sizeInputEl = screen.getByLabelText('Size');
|
||||||
|
expect(sizeInputEl).toBeInTheDocument();
|
||||||
|
|
||||||
|
// We change value and trigger a blur event to trigger an update
|
||||||
|
const newSizeValue = '23';
|
||||||
|
fireEvent.change(sizeInputEl, { target: { value: newSizeValue } });
|
||||||
|
fireEvent.blur(sizeInputEl);
|
||||||
|
|
||||||
|
// the onChange handler should have been called correctly, and the resulting
|
||||||
|
// query state should match what expected
|
||||||
|
expect(onChange).toHaveBeenCalledTimes(1);
|
||||||
|
rerender(
|
||||||
|
<ElasticsearchProvider
|
||||||
|
query={onChange.mock.calls[0][0]}
|
||||||
|
datasource={{} as ElasticDatasource}
|
||||||
|
onChange={onChange}
|
||||||
|
onRunQuery={() => {}}
|
||||||
|
>
|
||||||
|
<SettingsEditor metric={onChange.mock.calls[0][0].metrics![0]} previousMetrics={[]} />
|
||||||
|
</ElasticsearchProvider>
|
||||||
|
);
|
||||||
|
|
||||||
|
settingsButtonEl = screen.getByRole('button', {
|
||||||
|
name: /Size: \d+$/i,
|
||||||
|
});
|
||||||
|
expect(settingsButtonEl).toBeInTheDocument();
|
||||||
|
expect(settingsButtonEl.textContent).toBe(`Size: ${newSizeValue}`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -16,6 +16,7 @@ import { useDescription } from './useDescription';
|
|||||||
import { MovingAverageSettingsEditor } from './MovingAverageSettingsEditor';
|
import { MovingAverageSettingsEditor } from './MovingAverageSettingsEditor';
|
||||||
import { uniqueId } from 'lodash';
|
import { uniqueId } from 'lodash';
|
||||||
import { metricAggregationConfig } from '../utils';
|
import { metricAggregationConfig } from '../utils';
|
||||||
|
import { useQuery } from '../../ElasticsearchQueryContext';
|
||||||
|
|
||||||
// TODO: Move this somewhere and share it with BucketsAggregation Editor
|
// TODO: Move this somewhere and share it with BucketsAggregation Editor
|
||||||
const inlineFieldProps: Partial<ComponentProps<typeof InlineField>> = {
|
const inlineFieldProps: Partial<ComponentProps<typeof InlineField>> = {
|
||||||
@ -30,6 +31,7 @@ interface Props {
|
|||||||
export const SettingsEditor: FunctionComponent<Props> = ({ metric, previousMetrics }) => {
|
export const SettingsEditor: FunctionComponent<Props> = ({ metric, previousMetrics }) => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const description = useDescription(metric);
|
const description = useDescription(metric);
|
||||||
|
const query = useQuery();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SettingsEditorContainer label={description} hidden={metric.hide}>
|
<SettingsEditorContainer label={description} hidden={metric.hide}>
|
||||||
@ -63,6 +65,7 @@ export const SettingsEditor: FunctionComponent<Props> = ({ metric, previousMetri
|
|||||||
{(metric.type === 'raw_data' || metric.type === 'raw_document') && (
|
{(metric.type === 'raw_data' || metric.type === 'raw_document') && (
|
||||||
<InlineField label="Size" {...inlineFieldProps}>
|
<InlineField label="Size" {...inlineFieldProps}>
|
||||||
<Input
|
<Input
|
||||||
|
id={`ES-query-${query.refId}_metric-${metric.id}-size`}
|
||||||
onBlur={(e) => dispatch(changeMetricSetting(metric, 'size', e.target.value))}
|
onBlur={(e) => dispatch(changeMetricSetting(metric, 'size', e.target.value))}
|
||||||
defaultValue={metric.settings?.size ?? metricAggregationConfig['raw_data'].defaults.settings?.size}
|
defaultValue={metric.settings?.size ?? metricAggregationConfig['raw_data'].defaults.settings?.size}
|
||||||
/>
|
/>
|
||||||
|
@ -208,7 +208,7 @@ export const metricAggregationConfig: MetricsConfiguration = {
|
|||||||
isPipelineAgg: false,
|
isPipelineAgg: false,
|
||||||
supportsMissing: false,
|
supportsMissing: false,
|
||||||
supportsMultipleBucketPaths: false,
|
supportsMultipleBucketPaths: false,
|
||||||
hasSettings: false,
|
hasSettings: true,
|
||||||
supportsInlineScript: false,
|
supportsInlineScript: false,
|
||||||
hasMeta: false,
|
hasMeta: false,
|
||||||
defaults: {
|
defaults: {
|
||||||
|
Loading…
Reference in New Issue
Block a user