Skip to content

Commit

Permalink
Merge pull request #30 from quickwit-oss/feat_remove_script_plugin
Browse files Browse the repository at this point in the history
Issue #16: remove Script field
  • Loading branch information
idrissneumann authored Nov 24, 2023
2 parents 271eda2 + 653dae6 commit abd7860
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<{}>) => (
<ElasticsearchProvider
datasource={{ getFields } as ElasticDatasource}
query={query}
app={undefined}
range={getDefaultTimeRange()}
onChange={() => {}}
onRunQuery={() => {}}
>
{children}
</ElasticsearchProvider>
);

render(<MetricEditor value={avg} />, { 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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -152,10 +152,6 @@ export const SettingsEditor = ({ metric, previousMetrics }: Props) => {
</>
)}

{isMetricAggregationWithInlineScript(metric) && (
<SettingField label="Script" metric={metric} settingName="script" placeholder="_value * 1" />
)}

{isMetricAggregationWithMissingSupport(metric) && (
<SettingField
label="Missing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
BaseMetricAggregation,
MetricAggregationWithField,
MetricAggregationWithMissingSupport,
MetricAggregationWithInlineScript,
PipelineMetricAggregation,
MetricAggregationWithSettings,
} from '../../../types';
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit abd7860

Please sign in to comment.