mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 04:04:00 -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,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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