From abe2777a1fdb6418802102fbb1b6aca7ae4d8e66 Mon Sep 17 00:00:00 2001 From: joshhunt Date: Wed, 8 Feb 2023 18:34:11 +0000 Subject: [PATCH] Dashboards: Star dashboards by UID --- .../dashboard/components/DashNav/DashNav.tsx | 2 +- .../dashboard/services/DashboardSrv.ts | 26 +++++++++---------- .../app/plugins/panel/dashlist/DashList.tsx | 3 +-- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/public/app/features/dashboard/components/DashNav/DashNav.tsx b/public/app/features/dashboard/components/DashNav/DashNav.tsx index 87b2dfbdf28..f7100b0d2ee 100644 --- a/public/app/features/dashboard/components/DashNav/DashNav.tsx +++ b/public/app/features/dashboard/components/DashNav/DashNav.tsx @@ -130,7 +130,7 @@ export const DashNav = React.memo((props) => { const dashboardSrv = getDashboardSrv(); const { dashboard, setStarred } = props; - dashboardSrv.starDashboard(dashboard.id, Boolean(dashboard.meta.isStarred)).then((newState) => { + dashboardSrv.starDashboard(dashboard.uid, Boolean(dashboard.meta.isStarred)).then((newState) => { setStarred({ id: dashboard.uid, title: dashboard.title, url: dashboard.meta.url ?? '', isStarred: newState }); dashboard.meta.isStarred = newState; forceUpdate(); diff --git a/public/app/features/dashboard/services/DashboardSrv.ts b/public/app/features/dashboard/services/DashboardSrv.ts index 41f7ca91703..933af914346 100644 --- a/public/app/features/dashboard/services/DashboardSrv.ts +++ b/public/app/features/dashboard/services/DashboardSrv.ts @@ -92,30 +92,30 @@ export class DashboardSrv { ); } - starDashboard(dashboardId: string, isStarred: boolean) { + async starDashboard(dashboardUid: string, isStarred: boolean) { const backendSrv = getBackendSrv(); const request = { showSuccessAlert: false, - url: '/api/user/stars/dashboard/' + dashboardId, + url: '/api/user/stars/dashboard/uid/' + dashboardUid, method: isStarred ? 'DELETE' : 'POST', }; - return backendSrv.request(request).then(() => { - const newIsStarred = !isStarred; + await backendSrv.request(request); - if (this.dashboard?.id === dashboardId) { - this.dashboard.meta.isStarred = newIsStarred; - } + const newIsStarred = !isStarred; - const message = newIsStarred - ? t('notifications.starred-dashboard', 'Dashboard starred') - : t('notifications.unstarred-dashboard', 'Dashboard unstarred'); + if (this.dashboard?.uid === dashboardUid) { + this.dashboard.meta.isStarred = newIsStarred; + } - appEvents.emit(AppEvents.alertSuccess, [message]); + const message = newIsStarred + ? t('notifications.starred-dashboard', 'Dashboard starred') + : t('notifications.unstarred-dashboard', 'Dashboard unstarred'); - return newIsStarred; - }); + appEvents.emit(AppEvents.alertSuccess, [message]); + + return newIsStarred; } } diff --git a/public/app/plugins/panel/dashlist/DashList.tsx b/public/app/plugins/panel/dashlist/DashList.tsx index d03431ee639..6c9515667c9 100644 --- a/public/app/plugins/panel/dashlist/DashList.tsx +++ b/public/app/plugins/panel/dashlist/DashList.tsx @@ -103,8 +103,7 @@ export function DashList(props: PanelProps) { e.preventDefault(); e.stopPropagation(); - // FIXME: Do not use dash ID. Use UID to star a dashboard once the backend allows it - const isStarred = await getDashboardSrv().starDashboard(dash.id!.toString(), dash.isStarred); + const isStarred = await getDashboardSrv().starDashboard(dash.uid, dash.isStarred); const updatedDashboards = new Map(dashboards); updatedDashboards.set(dash?.uid ?? '', { ...dash, isStarred }); setDashboards(updatedDashboards);