grafana/public/app/features/expressions/ExpressionQueryEditor.tsx
Hugo Häggmark 09bb890092
WIP Chore: reduce strict errors (#40462)
* Chore: reduce strict error in ngReact

* Chore: reduce strict errors for ShareModal

* Chore: reduce strict errors in VersioHistory

* Chore: reduce strict error in ExpressionDatasource

* Chore: reduce strict error in DashboardWatcher

* Chore: reduce strict error in PluginPage

* Chore: reduce strict errors for guard

* Chore: update threshold

* Chore: reduce strict errors in Graph

* Chore: reduce threshold

* Apply suggestions from code review

Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>

* Chore: reduce strict errors in TimeSeries

* Chore: reduce threshold

* Chore: reduce strict errors in polyfill

* Chore: reduce threshold

* Chore: update after PR comments

* Update public/app/features/plugins/PluginPage.tsx

Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>

* Update public/app/features/plugins/PluginPage.tsx

Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>

* Chore: changes after PR comments

Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>
2021-10-15 08:57:55 +02:00

60 lines
2.1 KiB
TypeScript

import React, { PureComponent } from 'react';
import { DataSourceApi, QueryEditorProps, SelectableValue } from '@grafana/data';
import { InlineField, Select } from '@grafana/ui';
import { Resample } from './components/Resample';
import { Reduce } from './components/Reduce';
import { Math } from './components/Math';
import { ClassicConditions } from './components/ClassicConditions';
import { getDefaults } from './utils/expressionTypes';
import { ExpressionQuery, ExpressionQueryType, gelTypes } from './types';
type Props = QueryEditorProps<DataSourceApi<ExpressionQuery>, ExpressionQuery>;
const labelWidth = 14;
export class ExpressionQueryEditor extends PureComponent<Props> {
onSelectExpressionType = (item: SelectableValue<ExpressionQueryType>) => {
const { query, onChange } = this.props;
onChange(getDefaults({ ...query, type: item.value! }));
};
renderExpressionType() {
const { onChange, query, queries } = this.props;
const refIds = queries!.filter((q) => query.refId !== q.refId).map((q) => ({ value: q.refId, label: q.refId }));
switch (query.type) {
case ExpressionQueryType.math:
return <Math onChange={onChange} query={query} labelWidth={labelWidth} />;
case ExpressionQueryType.reduce:
return <Reduce refIds={refIds} onChange={onChange} labelWidth={labelWidth} query={query} />;
case ExpressionQueryType.resample:
return <Resample query={query} labelWidth={labelWidth} onChange={onChange} refIds={refIds} />;
case ExpressionQueryType.classic:
return <ClassicConditions onChange={onChange} query={query} refIds={refIds} />;
}
}
render() {
const { query } = this.props;
const selected = gelTypes.find((o) => o.value === query.type);
return (
<div>
<InlineField label="Operation" labelWidth={labelWidth}>
<Select
menuShouldPortal
options={gelTypes}
value={selected}
onChange={this.onSelectExpressionType}
width={25}
/>
</InlineField>
{this.renderExpressionType()}
</div>
);
}
}