mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* Performance: Standardize lodash imports to use destructured members Changes lodash imports of the form `import x from 'lodash/x'` to `import { x } from 'lodash'` to reduce bundle size. * Remove unnecessary _ import from Graph component * Enforce lodash import style * Fix remaining lodash imports
61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import React, { PureComponent } from 'react';
|
|
import { pick } from 'lodash';
|
|
import { ExploreQueryFieldProps, ExploreMode } from '@grafana/data';
|
|
import { Segment } from '@grafana/ui';
|
|
import { CloudWatchJsonData, CloudWatchQuery } from '../types';
|
|
import { CloudWatchDatasource } from '../datasource';
|
|
import { QueryInlineField } from './';
|
|
import { MetricsQueryEditor } from './MetricsQueryEditor';
|
|
import LogsQueryEditor from './LogsQueryEditor';
|
|
|
|
export type Props = ExploreQueryFieldProps<CloudWatchDatasource, CloudWatchQuery, CloudWatchJsonData>;
|
|
|
|
const apiModes = {
|
|
Metrics: { label: 'CloudWatch Metrics', value: 'Metrics' },
|
|
Logs: { label: 'CloudWatch Logs', value: 'Logs' },
|
|
};
|
|
|
|
export class PanelQueryEditor extends PureComponent<Props> {
|
|
render() {
|
|
const { query } = this.props;
|
|
const apiMode = query.queryMode ?? 'Metrics';
|
|
|
|
return (
|
|
<>
|
|
<QueryInlineField label="Query Mode">
|
|
<Segment
|
|
value={apiModes[apiMode]}
|
|
options={Object.values(apiModes)}
|
|
onChange={({ value }) => {
|
|
const newMode = (value as 'Metrics' | 'Logs') ?? 'Metrics';
|
|
if (newMode !== apiModes[apiMode].value) {
|
|
const commonProps = pick(
|
|
query,
|
|
'id',
|
|
'region',
|
|
'namespace',
|
|
'refId',
|
|
'hide',
|
|
'key',
|
|
'queryType',
|
|
'datasource'
|
|
);
|
|
|
|
this.props.onChange({
|
|
...commonProps,
|
|
queryMode: newMode,
|
|
} as CloudWatchQuery);
|
|
}
|
|
}}
|
|
/>
|
|
</QueryInlineField>
|
|
{apiMode === ExploreMode.Logs ? (
|
|
<LogsQueryEditor {...this.props} allowCustomValue />
|
|
) : (
|
|
<MetricsQueryEditor {...this.props} />
|
|
)}
|
|
</>
|
|
);
|
|
}
|
|
}
|