mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 04:59:15 -06:00
Dashboards: Star dashboards by UID
This commit is contained in:
parent
ac9639daf8
commit
abe2777a1f
@ -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();
|
||||
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user