Preferences: Use search endpoint to get missing dashboard (#53540)

This commit is contained in:
Ivan Ortega Alba 2022-08-11 10:34:01 +02:00 committed by GitHub
parent 72367f99cf
commit 6423485061
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 20 deletions

View File

@ -3003,8 +3003,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/core/components/SharedPreferences/SharedPreferences.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Do not use any type assertions.", "1"]
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"public/app/core/components/TagFilter/TagBadge.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],

View File

@ -111,27 +111,13 @@ export class SharedPreferences extends PureComponent<Props, State> {
async componentDidMount() {
const prefs = await this.service.load();
const dashboards = (await backendSrv.search({ starred: true })) as DashboardSearchItem[];
const dashboards = await backendSrv.search({ starred: true });
if (prefs.homeDashboardUID && !dashboards.find((d) => d.uid === prefs.homeDashboardUID)) {
const missingDash = await backendSrv.getDashboardByUid(prefs.homeDashboardUID);
const missingDash = await backendSrv.search({ dashboardUIDs: prefs.homeDashboardUID });
if (missingDash?.dashboard) {
dashboards.push({
title: missingDash.dashboard.title,
tags: [],
type: DashboardSearchItemType.DashDB,
uid: missingDash.dashboard.uid,
uri: '', // uri is not part of dashboard metadata
url: missingDash.meta.url || '',
folderId: missingDash.meta.folderId,
folderTitle: missingDash.meta.folderTitle,
folderUid: missingDash.meta.folderUid,
folderUrl: missingDash.meta.folderUrl,
isStarred: missingDash.meta.isStarred || false,
slug: missingDash.meta.slug,
items: [],
});
if (missingDash.length > 0) {
dashboards.push(missingDash[0]);
}
}