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,19 +92,20 @@ 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(() => {
await backendSrv.request(request);
const newIsStarred = !isStarred;
if (this.dashboard?.id === dashboardId) {
if (this.dashboard?.uid === dashboardUid) {
this.dashboard.meta.isStarred = newIsStarred;
}
@ -115,7 +116,6 @@ export class DashboardSrv {
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);