From 397fb195240325b79fc38ebff766da792fc964d2 Mon Sep 17 00:00:00 2001 From: Idriss Neumann Date: Fri, 24 Nov 2023 11:27:40 +0100 Subject: [PATCH 1/2] Issue #16: remove Script field --- .../MetricAggregationsEditor/SettingsEditor/index.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/components/QueryEditor/MetricAggregationsEditor/SettingsEditor/index.tsx b/src/components/QueryEditor/MetricAggregationsEditor/SettingsEditor/index.tsx index 82b9111..e7317da 100644 --- a/src/components/QueryEditor/MetricAggregationsEditor/SettingsEditor/index.tsx +++ b/src/components/QueryEditor/MetricAggregationsEditor/SettingsEditor/index.tsx @@ -7,7 +7,7 @@ import { extendedStats } from '../../../../queryDef'; import { MetricAggregation, ExtendedStat } from '../../../../types'; import { useQuery } from '../../ElasticsearchQueryContext'; import { SettingsEditorContainer } from '../../SettingsEditorContainer'; -import { isMetricAggregationWithInlineScript, isMetricAggregationWithMissingSupport } from '../aggregations'; +import { isMetricAggregationWithMissingSupport } from '../aggregations'; import { changeMetricMeta, changeMetricSetting } from '../state/actions'; import { metricAggregationConfig } from '../utils'; @@ -152,10 +152,6 @@ export const SettingsEditor = ({ metric, previousMetrics }: Props) => { )} - {isMetricAggregationWithInlineScript(metric) && ( - - )} - {isMetricAggregationWithMissingSupport(metric) && ( Date: Fri, 24 Nov 2023 15:21:57 +0100 Subject: [PATCH 2/2] Issue #16: code review, delete unused code --- .../MetricEditor.test.tsx | 39 +------------------ .../MetricAggregationsEditor/MetricEditor.tsx | 10 +---- .../MetricAggregationsEditor/aggregations.ts | 5 --- 3 files changed, 3 insertions(+), 51 deletions(-) diff --git a/src/components/QueryEditor/MetricAggregationsEditor/MetricEditor.test.tsx b/src/components/QueryEditor/MetricAggregationsEditor/MetricEditor.test.tsx index a4798e3..d98b9a9 100644 --- a/src/components/QueryEditor/MetricAggregationsEditor/MetricEditor.test.tsx +++ b/src/components/QueryEditor/MetricAggregationsEditor/MetricEditor.test.tsx @@ -10,47 +10,10 @@ import { defaultBucketAgg } from '../../../queryDef'; import { ElasticsearchQuery } from '../../../types'; import { ElasticsearchProvider } from '../ElasticsearchQueryContext'; -import { Average, Count, UniqueCount } from './../../../types'; +import { Count, UniqueCount } from './../../../types'; import { MetricEditor } from './MetricEditor'; describe('Metric Editor', () => { - it('Should display a "None" option for "field" if the metric supports inline script', async () => { - const avg: Average = { - id: '1', - type: 'avg', - }; - - const query: ElasticsearchQuery = { - refId: 'A', - query: '', - metrics: [avg], - bucketAggs: [defaultBucketAgg('2')], - }; - - const getFields: ElasticDatasource['getFields'] = jest.fn(() => from([[]])); - - const wrapper = ({ children }: PropsWithChildren<{}>) => ( - {}} - onRunQuery={() => {}} - > - {children} - - ); - - render(, { wrapper }); - - act(() => { - fireEvent.click(screen.getByText('Select Field')); - }); - - expect(await screen.findByText('None')).toBeInTheDocument(); - }); - it('Should not display a "None" option for "field" if the metric does not support inline script', async () => { const avg: UniqueCount = { id: '1', diff --git a/src/components/QueryEditor/MetricAggregationsEditor/MetricEditor.tsx b/src/components/QueryEditor/MetricAggregationsEditor/MetricEditor.tsx index e64be88..b63f319 100644 --- a/src/components/QueryEditor/MetricAggregationsEditor/MetricEditor.tsx +++ b/src/components/QueryEditor/MetricAggregationsEditor/MetricEditor.tsx @@ -15,10 +15,9 @@ import { segmentStyles } from '../styles'; import { SettingsEditor } from './SettingsEditor'; import { isMetricAggregationWithField, - isMetricAggregationWithInlineScript, isMetricAggregationWithSettings, isPipelineAggregation, - isPipelineAggregationWithMultipleBucketPaths, + isPipelineAggregationWithMultipleBucketPaths } from './aggregations'; import { changeMetricField, changeMetricType } from './state/actions'; import { getStyles } from './styles'; @@ -64,13 +63,8 @@ export const MetricEditor = ({ value }: Props) => { const loadOptions = useCallback(async () => { const remoteFields = await getFields(); - // Metric aggregations that have inline script support don't require a field to be set. - if (isMetricAggregationWithInlineScript(value)) { - return [{ label: 'None' }, ...remoteFields]; - } - return remoteFields; - }, [getFields, value]); + }, [getFields]); const previousMetrics = query.metrics!.slice( 0, diff --git a/src/components/QueryEditor/MetricAggregationsEditor/aggregations.ts b/src/components/QueryEditor/MetricAggregationsEditor/aggregations.ts index 509c426..24e423b 100644 --- a/src/components/QueryEditor/MetricAggregationsEditor/aggregations.ts +++ b/src/components/QueryEditor/MetricAggregationsEditor/aggregations.ts @@ -6,7 +6,6 @@ import { BaseMetricAggregation, MetricAggregationWithField, MetricAggregationWithMissingSupport, - MetricAggregationWithInlineScript, PipelineMetricAggregation, MetricAggregationWithSettings, } from '../../../types'; @@ -62,10 +61,6 @@ export const isMetricAggregationWithMeta = ( metric: BaseMetricAggregation | MetricAggregationWithMeta ): metric is MetricAggregationWithMeta => metricAggregationConfig[metric.type].hasMeta; -export const isMetricAggregationWithInlineScript = ( - metric: BaseMetricAggregation | MetricAggregationWithInlineScript -): metric is MetricAggregationWithInlineScript => metricAggregationConfig[metric.type].supportsInlineScript; - export const METRIC_AGGREGATION_TYPES: MetricAggregationType[] = [ 'count', 'avg',