Skip to content

Commit abd7860

Browse files
Merge pull request #30 from quickwit-oss/feat_remove_script_plugin
Issue #16: remove Script field
2 parents 271eda2 + 653dae6 commit abd7860

File tree

4 files changed

+4
-56
lines changed

4 files changed

+4
-56
lines changed

src/components/QueryEditor/MetricAggregationsEditor/MetricEditor.test.tsx

+1-38
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,10 @@ import { defaultBucketAgg } from '../../../queryDef';
1010
import { ElasticsearchQuery } from '../../../types';
1111
import { ElasticsearchProvider } from '../ElasticsearchQueryContext';
1212

13-
import { Average, Count, UniqueCount } from './../../../types';
13+
import { Count, UniqueCount } from './../../../types';
1414
import { MetricEditor } from './MetricEditor';
1515

1616
describe('Metric Editor', () => {
17-
it('Should display a "None" option for "field" if the metric supports inline script', async () => {
18-
const avg: Average = {
19-
id: '1',
20-
type: 'avg',
21-
};
22-
23-
const query: ElasticsearchQuery = {
24-
refId: 'A',
25-
query: '',
26-
metrics: [avg],
27-
bucketAggs: [defaultBucketAgg('2')],
28-
};
29-
30-
const getFields: ElasticDatasource['getFields'] = jest.fn(() => from([[]]));
31-
32-
const wrapper = ({ children }: PropsWithChildren<{}>) => (
33-
<ElasticsearchProvider
34-
datasource={{ getFields } as ElasticDatasource}
35-
query={query}
36-
app={undefined}
37-
range={getDefaultTimeRange()}
38-
onChange={() => {}}
39-
onRunQuery={() => {}}
40-
>
41-
{children}
42-
</ElasticsearchProvider>
43-
);
44-
45-
render(<MetricEditor value={avg} />, { wrapper });
46-
47-
act(() => {
48-
fireEvent.click(screen.getByText('Select Field'));
49-
});
50-
51-
expect(await screen.findByText('None')).toBeInTheDocument();
52-
});
53-
5417
it('Should not display a "None" option for "field" if the metric does not support inline script', async () => {
5518
const avg: UniqueCount = {
5619
id: '1',

src/components/QueryEditor/MetricAggregationsEditor/MetricEditor.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ import { segmentStyles } from '../styles';
1515
import { SettingsEditor } from './SettingsEditor';
1616
import {
1717
isMetricAggregationWithField,
18-
isMetricAggregationWithInlineScript,
1918
isMetricAggregationWithSettings,
2019
isPipelineAggregation,
21-
isPipelineAggregationWithMultipleBucketPaths,
20+
isPipelineAggregationWithMultipleBucketPaths
2221
} from './aggregations';
2322
import { changeMetricField, changeMetricType } from './state/actions';
2423
import { getStyles } from './styles';
@@ -64,13 +63,8 @@ export const MetricEditor = ({ value }: Props) => {
6463
const loadOptions = useCallback(async () => {
6564
const remoteFields = await getFields();
6665

67-
// Metric aggregations that have inline script support don't require a field to be set.
68-
if (isMetricAggregationWithInlineScript(value)) {
69-
return [{ label: 'None' }, ...remoteFields];
70-
}
71-
7266
return remoteFields;
73-
}, [getFields, value]);
67+
}, [getFields]);
7468

7569
const previousMetrics = query.metrics!.slice(
7670
0,

src/components/QueryEditor/MetricAggregationsEditor/SettingsEditor/index.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { extendedStats } from '../../../../queryDef';
77
import { MetricAggregation, ExtendedStat } from '../../../../types';
88
import { useQuery } from '../../ElasticsearchQueryContext';
99
import { SettingsEditorContainer } from '../../SettingsEditorContainer';
10-
import { isMetricAggregationWithInlineScript, isMetricAggregationWithMissingSupport } from '../aggregations';
10+
import { isMetricAggregationWithMissingSupport } from '../aggregations';
1111
import { changeMetricMeta, changeMetricSetting } from '../state/actions';
1212
import { metricAggregationConfig } from '../utils';
1313

@@ -152,10 +152,6 @@ export const SettingsEditor = ({ metric, previousMetrics }: Props) => {
152152
</>
153153
)}
154154

155-
{isMetricAggregationWithInlineScript(metric) && (
156-
<SettingField label="Script" metric={metric} settingName="script" placeholder="_value * 1" />
157-
)}
158-
159155
{isMetricAggregationWithMissingSupport(metric) && (
160156
<SettingField
161157
label="Missing"

src/components/QueryEditor/MetricAggregationsEditor/aggregations.ts

-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
BaseMetricAggregation,
77
MetricAggregationWithField,
88
MetricAggregationWithMissingSupport,
9-
MetricAggregationWithInlineScript,
109
PipelineMetricAggregation,
1110
MetricAggregationWithSettings,
1211
} from '../../../types';
@@ -62,10 +61,6 @@ export const isMetricAggregationWithMeta = (
6261
metric: BaseMetricAggregation | MetricAggregationWithMeta
6362
): metric is MetricAggregationWithMeta => metricAggregationConfig[metric.type].hasMeta;
6463

65-
export const isMetricAggregationWithInlineScript = (
66-
metric: BaseMetricAggregation | MetricAggregationWithInlineScript
67-
): metric is MetricAggregationWithInlineScript => metricAggregationConfig[metric.type].supportsInlineScript;
68-
6964
export const METRIC_AGGREGATION_TYPES: MetricAggregationType[] = [
7065
'count',
7166
'avg',

0 commit comments

Comments
 (0)