From 87d697e4fe2a687e926a54fad7043013de00aea9 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Mon, 16 Oct 2023 17:02:12 +0200 Subject: [PATCH] TeamPicker: Add optional initial value support (#76353) * TeamPicker: Add optional initial value support * Rename value to teamId --- .../app/core/components/Select/TeamPicker.tsx | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/public/app/core/components/Select/TeamPicker.tsx b/public/app/core/components/Select/TeamPicker.tsx index b2a2acbb2c1..345c0e55012 100644 --- a/public/app/core/components/Select/TeamPicker.tsx +++ b/public/app/core/components/Select/TeamPicker.tsx @@ -9,10 +9,12 @@ import { Team } from 'app/types'; export interface Props { onSelected: (team: SelectableValue) => void; className?: string; + teamId?: number; } export interface State { isLoading: boolean; + value?: SelectableValue; } export class TeamPicker extends Component { @@ -29,6 +31,25 @@ export class TeamPicker extends Component { }); } + 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) { this.setState({ isLoading: true }); @@ -54,13 +75,14 @@ export class TeamPicker extends Component { render() { const { onSelected, className } = this.props; - const { isLoading } = this.state; + const { isLoading, value } = this.state; return (