fixed mutability issue in dashboard dropdowns

This commit is contained in:
Peter Holmberg 2018-11-13 18:23:00 +01:00
parent 1194ff282e
commit 03cf238fa7
2 changed files with 12 additions and 6 deletions

View File

@ -42,7 +42,10 @@ export class OrgPreferences extends PureComponent<Props> {
setOrganizationTheme,
} = this.props;
starredDashboards.unshift({ id: 0, title: 'Default', tags: [], type: '', uid: '', uri: '', url: '' });
const dashboards: DashboardSearchHit[] = [
{ id: 0, title: 'Default', tags: [], type: '', uid: '', uri: '', url: '' },
...starredDashboards,
];
return (
<form className="section gf-form-group" onSubmit={this.onSubmitForm}>
@ -66,11 +69,11 @@ export class OrgPreferences extends PureComponent<Props> {
Home Dashboard
</Label>
<SimplePicker
defaultValue={starredDashboards.find(dashboard => dashboard.id === preferences.homeDashboardId)}
defaultValue={dashboards.find(dashboard => dashboard.id === preferences.homeDashboardId)}
getOptionValue={i => i.id}
getOptionLabel={i => i.title}
onSelected={(dashboard: DashboardSearchHit) => setOrganizationHomeDashboard(dashboard.id)}
options={starredDashboards}
options={dashboards}
placeholder="Chose default dashboard"
width={20}
/>

View File

@ -31,7 +31,10 @@ export class TeamPreferences extends PureComponent<Props> {
render() {
const { preferences, starredDashboards, setTeamHomeDashboard, setTeamTimezone, setTeamTheme } = this.props;
starredDashboards.unshift({ id: 0, title: 'Default', tags: [], type: '', uid: '', uri: '', url: '' });
const dashboards: DashboardSearchHit[] = [
{ id: 0, title: 'Default', tags: [], type: '', uid: '', uri: '', url: '' },
...starredDashboards,
];
return (
<form className="section gf-form-group" onSubmit={this.onSubmitForm}>
@ -55,11 +58,11 @@ export class TeamPreferences extends PureComponent<Props> {
Home Dashboard
</Label>
<SimplePicker
defaultValue={starredDashboards.find(dashboard => dashboard.id === preferences.homeDashboardId)}
defaultValue={dashboards.find(dashboard => dashboard.id === preferences.homeDashboardId)}
getOptionValue={i => i.id}
getOptionLabel={i => i.title}
onSelected={(dashboard: DashboardSearchHit) => setTeamHomeDashboard(dashboard.id)}
options={starredDashboards}
options={dashboards}
placeholder="Chose default dashboard"
width={20}
/>