From 3d3b781c19eb9b4633731b0012a39bf8e5fa957c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 31 Jan 2025 15:16:37 +0000 Subject: [PATCH 01/11] Update dependency @stylistic/eslint-plugin-ts to v3 (#99897) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index fd551f5fe24..92812f0a25a 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "@rsdoctor/webpack-plugin": "^0.4.6", "@rtk-query/codegen-openapi": "^2.0.0", "@rtsao/plugin-proposal-class-properties": "7.0.1-patch.1", - "@stylistic/eslint-plugin-ts": "^2.9.0", + "@stylistic/eslint-plugin-ts": "^3.0.0", "@swc/core": "1.10.12", "@swc/helpers": "0.5.15", "@testing-library/dom": "10.4.0", diff --git a/yarn.lock b/yarn.lock index ebd1311fa78..24b650e7eb7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7775,16 +7775,16 @@ __metadata: languageName: node linkType: hard -"@stylistic/eslint-plugin-ts@npm:^2.9.0": - version: 2.13.0 - resolution: "@stylistic/eslint-plugin-ts@npm:2.13.0" +"@stylistic/eslint-plugin-ts@npm:^3.0.0": + version: 3.0.1 + resolution: "@stylistic/eslint-plugin-ts@npm:3.0.1" dependencies: "@typescript-eslint/utils": "npm:^8.13.0" eslint-visitor-keys: "npm:^4.2.0" espree: "npm:^10.3.0" peerDependencies: eslint: ">=8.40.0" - checksum: 10/222d6ec0094177f40ea43f28af257192655539fe4bb1495341bc9ff521bca975da2066e229798fcc8e28ea24e91d0ef4db05b4f212f615cad752ade5c1c68561 + checksum: 10/24dc9f67ff56bc200340807a1fd055e8f49332c244b0ba214ea68ed91773d922790645db34f014e0f703644cc605171e5190df385597dad12d127d92fd72d29b languageName: node linkType: hard @@ -17826,7 +17826,7 @@ __metadata: "@rsdoctor/webpack-plugin": "npm:^0.4.6" "@rtk-query/codegen-openapi": "npm:^2.0.0" "@rtsao/plugin-proposal-class-properties": "npm:7.0.1-patch.1" - "@stylistic/eslint-plugin-ts": "npm:^2.9.0" + "@stylistic/eslint-plugin-ts": "npm:^3.0.0" "@swc/core": "npm:1.10.12" "@swc/helpers": "npm:0.5.15" "@testing-library/dom": "npm:10.4.0" From a3eebd71578432ce83d9a9cb6e96d78e2f317632 Mon Sep 17 00:00:00 2001 From: Isabella Siu Date: Fri, 31 Jan 2025 10:20:14 -0500 Subject: [PATCH 02/11] Elasticsearch: Replace term size dropdown with text input (#99718) --- .../TermsSettingsEditor.test.tsx | 39 ++++++++++++++++++- .../SettingsEditor/TermsSettingsEditor.tsx | 25 ++++++------ .../BucketAggregationsEditor/utils.ts | 11 ------ 3 files changed, 51 insertions(+), 24 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/TermsSettingsEditor.test.tsx b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/TermsSettingsEditor.test.tsx index bbc46703aaa..a0bf21c4046 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/TermsSettingsEditor.test.tsx +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/TermsSettingsEditor.test.tsx @@ -1,12 +1,15 @@ -import { screen } from '@testing-library/react'; +import { fireEvent, screen } from '@testing-library/react'; import selectEvent from 'react-select-event'; +import { useDispatch } from '../../../../hooks/useStatelessReducer'; import { renderWithESProvider } from '../../../../test-helpers/render'; import { ElasticsearchQuery, Terms, Average, Derivative, TopMetrics } from '../../../../types'; import { describeMetric } from '../../../../utils'; import { TermsSettingsEditor } from './TermsSettingsEditor'; +jest.mock('../../../../hooks/useStatelessReducer'); + describe('Terms Settings Editor', () => { it('Pipeline aggregations should not be in "order by" options', () => { const termsAgg: Terms = { @@ -37,4 +40,38 @@ describe('Terms Settings Editor', () => { // All other metric aggregations can be used in order by expect(screen.getByText(describeMetric(avg))).toBeInTheDocument(); }); + + describe('Handling change', () => { + let dispatch = jest.fn(); + beforeEach(() => { + dispatch.mockClear(); + jest.mocked(useDispatch).mockReturnValue(dispatch); + }); + + test('updating size', async () => { + const termsAgg: Terms = { + id: '1', + type: 'terms', + }; + const avg: Average = { id: '2', type: 'avg', field: '@value' }; + const derivative: Derivative = { id: '3', field: avg.id, type: 'derivative' }; + const topMetrics: TopMetrics = { id: '4', type: 'top_metrics' }; + const query: ElasticsearchQuery = { + refId: 'A', + query: '', + bucketAggs: [termsAgg], + metrics: [avg, derivative, topMetrics], + }; + + renderWithESProvider(, { providerProps: { query } }); + + const sizeInput = screen.getByLabelText('Size'); + fireEvent.change(sizeInput, { target: { value: '30' } }); + fireEvent.blur(sizeInput); + + expect(dispatch).toHaveBeenCalledTimes(1); + expect(dispatch.mock.calls[0][0].payload.settingName).toBe('size'); + expect(dispatch.mock.calls[0][0].payload.newValue).toBe('30'); + }); + }); }); diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/TermsSettingsEditor.tsx b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/TermsSettingsEditor.tsx index e6292c75396..80bbd154e9f 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/TermsSettingsEditor.tsx +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/TermsSettingsEditor.tsx @@ -7,11 +7,10 @@ import { InlineField, Select, Input } from '@grafana/ui'; import { useDispatch } from '../../../../hooks/useStatelessReducer'; import { MetricAggregation, Percentiles, ExtendedStatMetaType, ExtendedStats, Terms } from '../../../../types'; import { describeMetric } from '../../../../utils'; -import { useCreatableSelectPersistedBehaviour } from '../../../hooks/useCreatableSelectPersistedBehaviour'; import { useQuery } from '../../ElasticsearchQueryContext'; import { isPipelineAggregation } from '../../MetricAggregationsEditor/aggregations'; import { changeBucketAggregationSetting } from '../state/actions'; -import { bucketAggregationConfig, orderByOptions, orderOptions, sizeOptions } from '../utils'; +import { bucketAggregationConfig, orderByOptions, orderOptions } from '../utils'; import { inlineFieldProps } from '.'; @@ -23,6 +22,12 @@ export const TermsSettingsEditor = ({ bucketAgg }: Props) => { const { metrics } = useQuery(); const orderBy = createOrderByOptions(metrics); const { current: baseId } = useRef(uniqueId('es-terms-')); + let size = bucketAgg.settings?.size || bucketAggregationConfig.terms.defaultSettings?.size; + if (!size || size === '') { + size = '10'; + } else if (size === '0') { + size = '500'; + } const dispatch = useDispatch(); @@ -40,16 +45,12 @@ export const TermsSettingsEditor = ({ bucketAgg }: Props) => { -