|
|
|
|
@ -1,12 +1,11 @@ |
|
|
|
|
import { uniqueId } from 'lodash'; |
|
|
|
|
import React, { ComponentProps, useRef, useState } from 'react'; |
|
|
|
|
import React, { ComponentProps, useId, useRef, useState } from 'react'; |
|
|
|
|
|
|
|
|
|
import { InlineField, Input, InlineSwitch, Select } from '@grafana/ui'; |
|
|
|
|
|
|
|
|
|
import { useDispatch } from '../../../../hooks/useStatelessReducer'; |
|
|
|
|
import { extendedStats } from '../../../../queryDef'; |
|
|
|
|
import { MetricAggregation, ExtendedStat } from '../../../../types'; |
|
|
|
|
import { useQuery } from '../../ElasticsearchQueryContext'; |
|
|
|
|
import { SettingsEditorContainer } from '../../SettingsEditorContainer'; |
|
|
|
|
import { isMetricAggregationWithInlineScript, isMetricAggregationWithMissingSupport } from '../aggregations'; |
|
|
|
|
import { changeMetricMeta, changeMetricSetting } from '../state/actions'; |
|
|
|
|
@ -33,7 +32,10 @@ export const SettingsEditor = ({ metric, previousMetrics }: Props) => { |
|
|
|
|
|
|
|
|
|
const dispatch = useDispatch(); |
|
|
|
|
const description = useDescription(metric); |
|
|
|
|
const query = useQuery(); |
|
|
|
|
|
|
|
|
|
const sizeFieldId = useId(); |
|
|
|
|
const unitFieldId = useId(); |
|
|
|
|
const modeFieldId = useId(); |
|
|
|
|
|
|
|
|
|
const rateAggUnitOptions = [ |
|
|
|
|
{ value: 'second', label: 'Second' }, |
|
|
|
|
@ -76,9 +78,9 @@ export const SettingsEditor = ({ metric, previousMetrics }: Props) => { |
|
|
|
|
)} |
|
|
|
|
|
|
|
|
|
{(metric.type === 'raw_data' || metric.type === 'raw_document') && ( |
|
|
|
|
<InlineField label="Size" {...inlineFieldProps}> |
|
|
|
|
<InlineField label="Size" {...inlineFieldProps} htmlFor={sizeFieldId}> |
|
|
|
|
<Input |
|
|
|
|
id={`ES-query-${query.refId}_metric-${metric.id}-size`} |
|
|
|
|
id={sizeFieldId} |
|
|
|
|
onBlur={(e) => dispatch(changeMetricSetting({ metric, settingName: 'size', newValue: e.target.value }))} |
|
|
|
|
defaultValue={metric.settings?.size ?? metricAggregationConfig['raw_data'].defaults.settings?.size} |
|
|
|
|
/> |
|
|
|
|
@ -133,18 +135,18 @@ export const SettingsEditor = ({ metric, previousMetrics }: Props) => { |
|
|
|
|
|
|
|
|
|
{metric.type === 'rate' && ( |
|
|
|
|
<> |
|
|
|
|
<InlineField label="Unit" {...inlineFieldProps} data-testid="unit-select"> |
|
|
|
|
<InlineField label="Unit" {...inlineFieldProps} data-testid="unit-select" htmlFor={unitFieldId}> |
|
|
|
|
<Select |
|
|
|
|
id={`ES-query-${query.refId}_metric-${metric.id}-unit`} |
|
|
|
|
id={unitFieldId} |
|
|
|
|
onChange={(e) => dispatch(changeMetricSetting({ metric, settingName: 'unit', newValue: e.value }))} |
|
|
|
|
options={rateAggUnitOptions} |
|
|
|
|
value={metric.settings?.unit} |
|
|
|
|
/> |
|
|
|
|
</InlineField> |
|
|
|
|
|
|
|
|
|
<InlineField label="Mode" {...inlineFieldProps} data-testid="mode-select"> |
|
|
|
|
<InlineField label="Mode" {...inlineFieldProps} data-testid="mode-select" htmlFor={modeFieldId}> |
|
|
|
|
<Select |
|
|
|
|
id={`ES-query-${query.refId}_metric-${metric.id}-mode`} |
|
|
|
|
id={modeFieldId} |
|
|
|
|
onChange={(e) => dispatch(changeMetricSetting({ metric, settingName: 'mode', newValue: e.value }))} |
|
|
|
|
options={rateAggModeOptions} |
|
|
|
|
value={metric.settings?.unit} |
|
|
|
|
|