mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Rewrite angular segments for filter and group by in react * wip: refactoring * Update metric find queries * Remove old maps used to create labels - use one map for all types instead * Use value as label (again) for filters ang groupby * Remove old filter * Remove not used code * Fixes after pr feedback * Fix broken tests and add new metadata tests * Add index file to make imports cleaner * Cleanup. Remove old angular filter code * Fix broken tests * Use type switching instead of if statements * Use globals for regex * Updates after pr feedback * Make sure it's possible to filter using the same key multiple times * Replace metric select with segment component * Pass template vars as props * Refactor meta labels code * Reorder template variables * Fix broken tests * Reset metric value when changing service * Fix lint issue. * Make tests independant of element order * Include kubernetes.io in regex * Add instruction in help section
99 lines
2.7 KiB
TypeScript
99 lines
2.7 KiB
TypeScript
import React from 'react';
|
|
import _ from 'lodash';
|
|
|
|
import { SelectableValue } from '@grafana/data';
|
|
import { Segment } from '@grafana/ui';
|
|
import { getAggregationOptionsByMetric } from '../functions';
|
|
import { ValueTypes, MetricKind } from '../constants';
|
|
|
|
export interface Props {
|
|
onChange: (metricDescriptor: any) => void;
|
|
metricDescriptor: {
|
|
valueType: string;
|
|
metricKind: string;
|
|
};
|
|
crossSeriesReducer: string;
|
|
groupBys: string[];
|
|
children?: (renderProps: any) => JSX.Element;
|
|
templateVariableOptions: Array<SelectableValue<string>>;
|
|
}
|
|
|
|
export interface State {
|
|
aggOptions: any[];
|
|
displayAdvancedOptions: boolean;
|
|
}
|
|
|
|
export class Aggregations extends React.Component<Props, State> {
|
|
state: State = {
|
|
aggOptions: [],
|
|
displayAdvancedOptions: false,
|
|
};
|
|
|
|
componentDidMount() {
|
|
this.setAggOptions(this.props);
|
|
}
|
|
|
|
UNSAFE_componentWillReceiveProps(nextProps: Props) {
|
|
this.setAggOptions(nextProps);
|
|
}
|
|
|
|
setAggOptions({ metricDescriptor }: Props) {
|
|
let aggOptions: any[] = [];
|
|
if (metricDescriptor) {
|
|
aggOptions = getAggregationOptionsByMetric(
|
|
metricDescriptor.valueType as ValueTypes,
|
|
metricDescriptor.metricKind as MetricKind
|
|
).map(a => ({
|
|
...a,
|
|
label: a.text,
|
|
}));
|
|
}
|
|
this.setState({ aggOptions });
|
|
}
|
|
|
|
onToggleDisplayAdvanced = () => {
|
|
this.setState(state => ({
|
|
displayAdvancedOptions: !state.displayAdvancedOptions,
|
|
}));
|
|
};
|
|
|
|
render() {
|
|
const { displayAdvancedOptions, aggOptions } = this.state;
|
|
const { templateVariableOptions, onChange, crossSeriesReducer } = this.props;
|
|
|
|
return (
|
|
<>
|
|
<div className="gf-form-inline">
|
|
<label className="gf-form-label query-keyword width-9">Aggregation</label>
|
|
<Segment
|
|
onChange={({ value }) => onChange(value)}
|
|
value={[...aggOptions, ...templateVariableOptions].find(s => s.value === crossSeriesReducer)}
|
|
options={[
|
|
{
|
|
label: 'Template Variables',
|
|
options: templateVariableOptions,
|
|
},
|
|
{
|
|
label: 'Aggregations',
|
|
expanded: true,
|
|
options: aggOptions,
|
|
},
|
|
]}
|
|
placeholder="Select Reducer"
|
|
></Segment>
|
|
<div className="gf-form gf-form--grow">
|
|
<label className="gf-form-label gf-form-label--grow">
|
|
<a onClick={this.onToggleDisplayAdvanced}>
|
|
<>
|
|
<i className={`fa fa-caret-${displayAdvancedOptions ? 'down' : 'right'}`} /> Advanced Options
|
|
</>
|
|
</a>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
{this.props.children(this.state.displayAdvancedOptions)}
|
|
</>
|
|
);
|
|
}
|
|
}
|