Dashboards: Star dashboards by UID

This commit is contained in:
joshhunt 2023-02-08 18:34:11 +00:00
parent ac9639daf8
commit abe2777a1f
No known key found for this signature in database
GPG Key ID: F767869890CBA3F6
3 changed files with 15 additions and 16 deletions

View File

@ -130,7 +130,7 @@ export const DashNav = React.memo<Props>((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();

View File

@ -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;
}
}

View File

@ -103,8 +103,7 @@ export function DashList(props: PanelProps<PanelOptions>) {
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);