mirror of
https://github.com/grafana/grafana.git
synced 2025-08-26 11:51:00 +08:00
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>
This commit is contained in:
@ -1,32 +1,37 @@
|
||||
import React from 'react';
|
||||
import { Input } from '@grafana/ui';
|
||||
import { SelectableValue } from '@grafana/data';
|
||||
import { SegmentAsync } from '@grafana/ui';
|
||||
import StackdriverDatasource from '../datasource';
|
||||
|
||||
export interface Props {
|
||||
datasource: StackdriverDatasource;
|
||||
}
|
||||
|
||||
interface State {
|
||||
onChange: (projectName: string) => void;
|
||||
templateVariableOptions: Array<SelectableValue<string>>;
|
||||
projectName: string;
|
||||
}
|
||||
|
||||
export class Project extends React.Component<Props, State> {
|
||||
state: State = {
|
||||
projectName: 'Loading project...',
|
||||
};
|
||||
|
||||
async componentDidMount() {
|
||||
const projectName = await this.props.datasource.getDefaultProject();
|
||||
this.setState({ projectName });
|
||||
}
|
||||
|
||||
render() {
|
||||
const { projectName } = this.state;
|
||||
return (
|
||||
<div className="gf-form">
|
||||
<span className="gf-form-label width-9 query-keyword">Project</span>
|
||||
<Input className="gf-form-input width-15" disabled type="text" value={projectName} />
|
||||
export function Project({ projectName, datasource, onChange, templateVariableOptions }: Props) {
|
||||
return (
|
||||
<div className="gf-form-inline">
|
||||
<span className="gf-form-label width-9 query-keyword">Project</span>
|
||||
<SegmentAsync
|
||||
allowCustomValue
|
||||
onChange={({ value }) => onChange(value!)}
|
||||
loadOptions={() =>
|
||||
datasource.getProjects().then(projects => [
|
||||
{
|
||||
label: 'Template Variables',
|
||||
options: templateVariableOptions,
|
||||
},
|
||||
...projects,
|
||||
])
|
||||
}
|
||||
value={projectName}
|
||||
placeholder="Select Project"
|
||||
/>
|
||||
<div className="gf-form gf-form--grow">
|
||||
<div className="gf-form-label gf-form-label--grow" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user