mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* Select: Don't portal by default * Select: Portal all the Selects * Fix indendentation in this comment * Select: Remove @example docs until formatting is correct * Docs: Add some documentation for the Select changes * Update docs/sources/whatsnew/whats-new-in-v8-1.md Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update docs/sources/whatsnew/whats-new-in-v8-1.md Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update packages/grafana-ui/src/components/Select/types.ts Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update public/app/core/components/TransformersUI/configFromQuery/ConfigFromQueryTransformerEditor.tsx Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update public/app/core/components/TransformersUI/configFromQuery/ConfigFromQueryTransformerEditor.tsx Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update public/app/core/components/TransformersUI/configFromQuery/ConfigFromQueryTransformerEditor.tsx Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update public/app/core/components/TransformersUI/prepareTimeSeries/PrepareTimeSeriesEditor.tsx Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Docs: Variants instead of varients * Update public/app/core/components/TransformersUI/configFromQuery/ConfigFromQueryTransformerEditor.tsx Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com>
73 lines
1.8 KiB
TypeScript
73 lines
1.8 KiB
TypeScript
import React, { Component } from 'react';
|
|
import { debounce, isNil } from 'lodash';
|
|
import { AsyncSelect } from '@grafana/ui';
|
|
import { SelectableValue } from '@grafana/data';
|
|
import { getBackendSrv } from '@grafana/runtime';
|
|
import { Team } from 'app/types';
|
|
|
|
export interface Props {
|
|
onSelected: (team: SelectableValue<Team>) => void;
|
|
className?: string;
|
|
}
|
|
|
|
export interface State {
|
|
isLoading: boolean;
|
|
}
|
|
|
|
export class TeamPicker extends Component<Props, State> {
|
|
debouncedSearch: any;
|
|
|
|
constructor(props: Props) {
|
|
super(props);
|
|
this.state = { isLoading: false };
|
|
this.search = this.search.bind(this);
|
|
|
|
this.debouncedSearch = debounce(this.search, 300, {
|
|
leading: true,
|
|
trailing: true,
|
|
});
|
|
}
|
|
|
|
search(query?: string) {
|
|
this.setState({ isLoading: true });
|
|
|
|
if (isNil(query)) {
|
|
query = '';
|
|
}
|
|
|
|
return getBackendSrv()
|
|
.get(`/api/teams/search?perpage=100&page=1&query=${query}`)
|
|
.then((result: { teams: Team[] }) => {
|
|
const teams: Array<SelectableValue<Team>> = result.teams.map((team) => {
|
|
return {
|
|
value: team,
|
|
label: team.name,
|
|
imgUrl: team.avatarUrl,
|
|
};
|
|
});
|
|
|
|
this.setState({ isLoading: false });
|
|
return teams;
|
|
});
|
|
}
|
|
|
|
render() {
|
|
const { onSelected, className } = this.props;
|
|
const { isLoading } = this.state;
|
|
return (
|
|
<div className="user-picker" data-testid="teamPicker">
|
|
<AsyncSelect
|
|
menuShouldPortal
|
|
isLoading={isLoading}
|
|
defaultOptions={true}
|
|
loadOptions={this.debouncedSearch}
|
|
onChange={onSelected}
|
|
className={className}
|
|
placeholder="Select a team"
|
|
noOptionsMessage="No teams found"
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
}
|