Files
grafana/public/app/plugins/datasource/stackdriver/components/Aggregations.tsx
Erik Sundell 934a8f08ae Stackdriver: Project selector (#22447)
* clean PR #17366

* udpate vendor

* [WIP] Implement projects management for stackdriver

* [WIP] Implement projects management for stackdriver

* [WIP] Implement projects management for stackdriver

* Implement projects management for stackdriver

* [WIP][Tests] Fix errors

* clean anonymous struct

* remove await

* don't store project list

* Add default project on query editor

* gofmt

* Fix tests

* Move test data source to backend

* Use segment instead of dropdown. remove ensure default project since it's not being used anymore.

* Fix broken annotation editor

* Load gceDefaultAccount only once when in the config page

* Reset error message on auth type change

* Add metric find query for projects

* Remove debug code

* Fix broken tests

* Fix typings

* Fix lint error

* Slightly different approach - now having a distiction between config page default project, and project that is selectable from the dropdown in the query editor.

* Fix broken tests

* Attempt to fix strict ts errors

* Prevent state from being set multiple times

* Remove noOptionsMessage since it seems to be obosolete in react select

* One more attempt to solve ts strict error

* Interpolate project template variable. Make sure its loaded correctly when opening variable query editor first time

* Implicit any fix

* fix: typescript strict null check fixes

* Return empty array in case project endpoint fails

* Rename project to projectName to prevent clashing with legacy query prop

* Fix broken test

* fix: Stackdriver - template replace on filter label

should have a regex format as that escapes the dots
in the label name which is not valid.

Co-authored-by: Labesse Kévin <kevin@labesse.me>
Co-authored-by: Elias Cédric Laouiti <elias@abtasty.com>
Co-authored-by: Daniel Lee <dan.limerick@gmail.com>
2020-03-02 09:31:09 -05:00

100 lines
2.8 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';
import { MetricDescriptor } from '../types';
export interface Props {
onChange: (metricDescriptor: MetricDescriptor[]) => 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)}
</>
);
}
}