mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
TeamPicker: Add optional initial value support (#76353)
* TeamPicker: Add optional initial value support * Rename value to teamId
This commit is contained in:
parent
5a2a3ab596
commit
87d697e4fe
@ -9,10 +9,12 @@ import { Team } from 'app/types';
|
|||||||
export interface Props {
|
export interface Props {
|
||||||
onSelected: (team: SelectableValue<Team>) => void;
|
onSelected: (team: SelectableValue<Team>) => void;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
teamId?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface State {
|
export interface State {
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
|
value?: SelectableValue<Team>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TeamPicker extends Component<Props, State> {
|
export class TeamPicker extends Component<Props, State> {
|
||||||
@ -29,6 +31,25 @@ export class TeamPicker extends Component<Props, State> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount(): void {
|
||||||
|
const { teamId } = this.props;
|
||||||
|
if (!teamId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
getBackendSrv()
|
||||||
|
.get(`/api/teams/${teamId}`)
|
||||||
|
.then((team: Team) => {
|
||||||
|
this.setState({
|
||||||
|
value: {
|
||||||
|
value: team,
|
||||||
|
label: team.name,
|
||||||
|
imgUrl: team.avatarUrl,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
search(query?: string) {
|
search(query?: string) {
|
||||||
this.setState({ isLoading: true });
|
this.setState({ isLoading: true });
|
||||||
|
|
||||||
@ -54,13 +75,14 @@ export class TeamPicker extends Component<Props, State> {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { onSelected, className } = this.props;
|
const { onSelected, className } = this.props;
|
||||||
const { isLoading } = this.state;
|
const { isLoading, value } = this.state;
|
||||||
return (
|
return (
|
||||||
<div className="user-picker" data-testid="teamPicker">
|
<div className="user-picker" data-testid="teamPicker">
|
||||||
<AsyncSelect
|
<AsyncSelect
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
defaultOptions={true}
|
defaultOptions={true}
|
||||||
loadOptions={this.debouncedSearch}
|
loadOptions={this.debouncedSearch}
|
||||||
|
value={value}
|
||||||
onChange={onSelected}
|
onChange={onSelected}
|
||||||
className={className}
|
className={className}
|
||||||
placeholder="Select a team"
|
placeholder="Select a team"
|
||||||
|
Loading…
Reference in New Issue
Block a user