Elasticsearch: Fix script fields in query editor (#31681)

* Elasticsearch: Fix script fields in query editor

* properly name bucke_script deries
This commit is contained in:
Giordano Ricci
2021-03-05 12:48:45 +00:00
committed by GitHub
parent 54f281d6ed
commit 64a8514e47
7 changed files with 74 additions and 27 deletions

View File

@@ -4,8 +4,9 @@ import { useDispatch } from '../../../../hooks/useStatelessReducer';
import { changeMetricSetting } from '../state/actions';
import { ChangeMetricSettingAction } from '../state/types';
import { SettingKeyOf } from '../../../types';
import { MetricAggregationWithSettings } from '../aggregations';
import { MetricAggregationWithInlineScript, MetricAggregationWithSettings } from '../aggregations';
import { uniqueId } from 'lodash';
import { getScriptValue } from 'app/plugins/datasource/elasticsearch/utils';
interface Props<T extends MetricAggregationWithSettings, K extends SettingKeyOf<T>> {
label: string;
@@ -26,13 +27,19 @@ export function SettingField<T extends MetricAggregationWithSettings, K extends
const [id] = useState(uniqueId(`es-field-id-`));
const settings = metric.settings;
let defaultValue = settings?.[settingName as keyof typeof settings] || '';
if (settingName === 'script') {
defaultValue = getScriptValue(metric as MetricAggregationWithInlineScript);
}
return (
<InlineField label={label} labelWidth={16} tooltip={tooltip}>
<Input
id={id}
placeholder={placeholder}
onBlur={(e) => dispatch(changeMetricSetting(metric, settingName, e.target.value as any))}
defaultValue={settings?.[settingName as keyof typeof settings]}
defaultValue={defaultValue}
/>
</InlineField>
);

View File

@@ -43,9 +43,10 @@ export interface MetricAggregationWithMissingSupport extends BaseMetricAggregati
};
}
type InlineScript = string | { inline?: string };
export interface MetricAggregationWithInlineScript extends BaseMetricAggregation {
settings?: {
script?: string;
script?: InlineScript;
};
}
@@ -59,7 +60,7 @@ export interface Average
MetricAggregationWithInlineScript {
type: 'avg';
settings?: {
script?: string;
script?: InlineScript;
missing?: string;
};
}
@@ -67,7 +68,7 @@ export interface Average
export interface Sum extends MetricAggregationWithField, MetricAggregationWithInlineScript {
type: 'sum';
settings?: {
script?: string;
script?: InlineScript;
missing?: string;
};
}
@@ -75,7 +76,7 @@ export interface Sum extends MetricAggregationWithField, MetricAggregationWithIn
export interface Max extends MetricAggregationWithField, MetricAggregationWithInlineScript {
type: 'max';
settings?: {
script?: string;
script?: InlineScript;
missing?: string;
};
}
@@ -83,7 +84,7 @@ export interface Max extends MetricAggregationWithField, MetricAggregationWithIn
export interface Min extends MetricAggregationWithField, MetricAggregationWithInlineScript {
type: 'min';
settings?: {
script?: string;
script?: InlineScript;
missing?: string;
};
}
@@ -105,7 +106,7 @@ export interface ExtendedStat {
export interface ExtendedStats extends MetricAggregationWithField, MetricAggregationWithInlineScript {
type: 'extended_stats';
settings?: {
script?: string;
script?: InlineScript;
missing?: string;
sigma?: string;
};
@@ -118,7 +119,7 @@ export interface Percentiles extends MetricAggregationWithField, MetricAggregati
type: 'percentiles';
settings?: {
percents?: string[];
script?: string;
script?: InlineScript;
missing?: string;
};
}
@@ -238,7 +239,7 @@ export interface MovingFunction extends BasePipelineMetricAggregation {
type: 'moving_fn';
settings?: {
window?: string;
script?: string;
script?: InlineScript;
shift?: string;
};
}
@@ -267,7 +268,7 @@ export interface CumulativeSum extends BasePipelineMetricAggregation {
export interface BucketScript extends PipelineMetricAggregationWithMultipleBucketPaths {
type: 'bucket_script';
settings?: {
script?: string;
script?: InlineScript;
};
}