Chore: remove strict errors for cloud-monitoring (#40620)
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
import { SelectableValue } from '@grafana/data';
|
import { SelectableValue } from '@grafana/data';
|
||||||
import { SELECT_WIDTH } from '../constants';
|
import { SELECT_WIDTH } from '../constants';
|
||||||
import { CustomMetaData, MetricQuery } from '../types';
|
import { CustomMetaData, MetricQuery, SLOQuery } from '../types';
|
||||||
import { AlignmentFunction, AlignmentPeriod, AlignmentPeriodLabel, QueryEditorField, QueryEditorRow } from '.';
|
import { AlignmentFunction, AlignmentPeriod, AlignmentPeriodLabel, QueryEditorField, QueryEditorRow } from '.';
|
||||||
import CloudMonitoringDatasource from '../datasource';
|
import CloudMonitoringDatasource from '../datasource';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
onChange: (query: MetricQuery) => void;
|
onChange: (query: MetricQuery | SLOQuery) => void;
|
||||||
query: MetricQuery;
|
query: MetricQuery;
|
||||||
templateVariableOptions: Array<SelectableValue<string>>;
|
templateVariableOptions: Array<SelectableValue<string>>;
|
||||||
customMetaData: CustomMetaData;
|
customMetaData: CustomMetaData;
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
import React, { FC, useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { SelectableValue } from '@grafana/data';
|
import { SelectableValue } from '@grafana/data';
|
||||||
import { Select } from '@grafana/ui';
|
import { Select } from '@grafana/ui';
|
||||||
import { ALIGNMENT_PERIODS } from '../constants';
|
import { ALIGNMENT_PERIODS } from '../constants';
|
||||||
import { BaseQuery } from '../types';
|
import { MetricQuery, SLOQuery } from '../types';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props<TQuery> {
|
||||||
onChange: (query: BaseQuery) => void;
|
onChange(query: TQuery): void;
|
||||||
query: BaseQuery;
|
query: TQuery;
|
||||||
templateVariableOptions: Array<SelectableValue<string>>;
|
templateVariableOptions: Array<SelectableValue<string>>;
|
||||||
selectWidth?: number;
|
selectWidth?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AlignmentPeriod: FC<Props> = ({ templateVariableOptions, onChange, query, selectWidth }) => {
|
export function AlignmentPeriod<TQuery extends MetricQuery | SLOQuery>({
|
||||||
|
templateVariableOptions,
|
||||||
|
onChange,
|
||||||
|
query,
|
||||||
|
selectWidth,
|
||||||
|
}: Props<TQuery>) {
|
||||||
const options = useMemo(
|
const options = useMemo(
|
||||||
() =>
|
() =>
|
||||||
ALIGNMENT_PERIODS.map((ap) => ({
|
ALIGNMENT_PERIODS.map((ap) => ({
|
||||||
@@ -42,4 +47,4 @@ export const AlignmentPeriod: FC<Props> = ({ templateVariableOptions, onChange,
|
|||||||
placeholder="Select Alignment"
|
placeholder="Select Alignment"
|
||||||
></Select>
|
></Select>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
AlignmentTypes,
|
AlignmentTypes,
|
||||||
CustomMetaData,
|
CustomMetaData,
|
||||||
ValueTypes,
|
ValueTypes,
|
||||||
|
SLOQuery,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import { getAlignmentPickerData } from '../functions';
|
import { getAlignmentPickerData } from '../functions';
|
||||||
import CloudMonitoringDatasource from '../datasource';
|
import CloudMonitoringDatasource from '../datasource';
|
||||||
@@ -71,7 +72,7 @@ function Editor({
|
|||||||
}, [datasource, groupBys, metricType, projectName, refId]);
|
}, [datasource, groupBys, metricType, projectName, refId]);
|
||||||
|
|
||||||
const onChange = useCallback(
|
const onChange = useCallback(
|
||||||
(metricQuery: MetricQuery) => {
|
(metricQuery: MetricQuery | SLOQuery) => {
|
||||||
onQueryChange({ ...query, ...metricQuery });
|
onQueryChange({ ...query, ...metricQuery });
|
||||||
onRunQuery();
|
onRunQuery();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export class QueryEditor extends PureComponent<Props> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onQueryChange(prop: string, value: any) {
|
onQueryChange(prop: string, value: MetricQuery | SLOQuery) {
|
||||||
this.props.onChange({ ...this.props.query, [prop]: value });
|
this.props.onChange({ ...this.props.query, [prop]: value });
|
||||||
this.props.onRunQuery();
|
this.props.onRunQuery();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,25 @@ export interface Props {
|
|||||||
templateVariableOptions: Array<SelectableValue<string>>;
|
templateVariableOptions: Array<SelectableValue<string>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function asQueryType(input: Array<SelectableValue<string>>) {
|
||||||
|
const res: Array<SelectableValue<QueryType>> = [];
|
||||||
|
input.forEach((v) => {
|
||||||
|
if (v.value === QueryType.METRICS) {
|
||||||
|
res.push({ ...v, value: QueryType.METRICS });
|
||||||
|
}
|
||||||
|
if (v.value === QueryType.SLO) {
|
||||||
|
res.push({ ...v, value: QueryType.SLO });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
export const QueryTypeSelector: FunctionComponent<Props> = ({ onChange, value, templateVariableOptions }) => {
|
export const QueryTypeSelector: FunctionComponent<Props> = ({ onChange, value, templateVariableOptions }) => {
|
||||||
return (
|
return (
|
||||||
<div className="gf-form-inline">
|
<div className="gf-form-inline">
|
||||||
<label className="gf-form-label query-keyword width-9">Query Type</label>
|
<label className="gf-form-label query-keyword width-9">Query Type</label>
|
||||||
<Segment
|
<Segment
|
||||||
value={[...QUERY_TYPES, ...templateVariableOptions].find((qt) => qt.value === value)}
|
value={[...QUERY_TYPES, ...asQueryType(templateVariableOptions)].find((qt) => qt.value === value)}
|
||||||
options={[
|
options={[
|
||||||
...QUERY_TYPES,
|
...QUERY_TYPES,
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-2
@@ -1,14 +1,14 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { SelectableValue } from '@grafana/data';
|
import { SelectableValue } from '@grafana/data';
|
||||||
import { Metrics, LabelFilter, GroupBy, Preprocessor, Alignment } from '.';
|
import { Metrics, LabelFilter, GroupBy, Preprocessor, Alignment } from '.';
|
||||||
import { MetricQuery, MetricDescriptor, CustomMetaData } from '../types';
|
import { MetricQuery, MetricDescriptor, CustomMetaData, SLOQuery } from '../types';
|
||||||
import CloudMonitoringDatasource from '../datasource';
|
import CloudMonitoringDatasource from '../datasource';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
customMetaData: CustomMetaData;
|
customMetaData: CustomMetaData;
|
||||||
variableOptionGroup: SelectableValue<string>;
|
variableOptionGroup: SelectableValue<string>;
|
||||||
onMetricTypeChange: (query: MetricDescriptor) => void;
|
onMetricTypeChange: (query: MetricDescriptor) => void;
|
||||||
onChange: (query: MetricQuery) => void;
|
onChange: (query: MetricQuery | SLOQuery) => void;
|
||||||
query: MetricQuery;
|
query: MetricQuery;
|
||||||
datasource: CloudMonitoringDatasource;
|
datasource: CloudMonitoringDatasource;
|
||||||
labels: any;
|
labels: any;
|
||||||
|
|||||||
Reference in New Issue
Block a user