mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DashboardScene: Viewer role only support (#76748)
* Allow starring DashboardScene
* Add feature toggle to enable dashbaord scene for viewers
* Basics for proxying viewers to a dashboard scene
* Removed isHomeDashboard flag
* Don't use proxy for rendering dashboard page
* Revert "Don't use proxy for rendering dashboard page"
This reverts commit 95836bdb2c.
* Pre-fetch dashboard prior page rendering
* Depend only on dashboard permissions
* Update default home dashboard to proper model...
* Fix breadcrumbs
* Types update
* Dashboards page proxy tests
* Fix missing controls
* URLs generation
* DashboardScenePageStateManager caching test
* Tests updates
* Fix wrong import
* Test update
* Gen
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import * as H from 'history';
|
||||
import { Unsubscribable } from 'rxjs';
|
||||
|
||||
import { CoreApp, DataQueryRequest, NavModelItem, UrlQueryMap } from '@grafana/data';
|
||||
import { locationService } from '@grafana/runtime';
|
||||
import { CoreApp, DataQueryRequest, NavIndex, NavModelItem, UrlQueryMap } from '@grafana/data';
|
||||
import { config, locationService } from '@grafana/runtime';
|
||||
import {
|
||||
getUrlSyncManager,
|
||||
SceneFlexLayout,
|
||||
@@ -14,6 +14,8 @@ import {
|
||||
SceneObjectStateChangedEvent,
|
||||
sceneUtils,
|
||||
} from '@grafana/scenes';
|
||||
import { getNavModel } from 'app/core/selectors/navModel';
|
||||
import { newBrowseDashboardsEnabled } from 'app/features/browse-dashboards/featureFlag';
|
||||
import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv';
|
||||
import { DashboardMeta } from 'app/types';
|
||||
|
||||
@@ -155,16 +157,45 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> {
|
||||
this.setState({ overlay: new SaveDashboardDrawer({ dashboardRef: this.getRef() }) });
|
||||
};
|
||||
|
||||
public getPageNav(location: H.Location) {
|
||||
public getPageNav(location: H.Location, navIndex: NavIndex) {
|
||||
const { meta } = this.state;
|
||||
|
||||
let pageNav: NavModelItem = {
|
||||
text: this.state.title,
|
||||
url: getDashboardUrl({
|
||||
uid: this.state.uid,
|
||||
currentQueryParams: location.search,
|
||||
updateQuery: { viewPanel: null, inspect: null },
|
||||
useExperimentalURL: Boolean(config.featureToggles.dashboardSceneForViewers && meta.canEdit),
|
||||
}),
|
||||
};
|
||||
|
||||
const { folderTitle, folderUid } = meta;
|
||||
|
||||
if (folderUid) {
|
||||
if (newBrowseDashboardsEnabled()) {
|
||||
const folderNavModel = getNavModel(navIndex, `folder-dashboards-${folderUid}`).main;
|
||||
// If the folder hasn't loaded (maybe user doesn't have permission on it?) then
|
||||
// don't show the "page not found" breadcrumb
|
||||
if (folderNavModel.id !== 'not-found') {
|
||||
pageNav = {
|
||||
...pageNav,
|
||||
parentItem: folderNavModel,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
if (folderTitle) {
|
||||
pageNav = {
|
||||
...pageNav,
|
||||
parentItem: {
|
||||
text: folderTitle,
|
||||
url: `/dashboards/f/${meta.folderUid}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.state.viewPanelKey) {
|
||||
pageNav = {
|
||||
text: 'View panel',
|
||||
@@ -216,6 +247,25 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> {
|
||||
this.setState({ overlay: undefined });
|
||||
}
|
||||
|
||||
public async onStarDashboard() {
|
||||
const { meta, uid } = this.state;
|
||||
if (!uid) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const result = await getDashboardSrv().starDashboard(uid, Boolean(meta.isStarred));
|
||||
|
||||
this.setState({
|
||||
meta: {
|
||||
...meta,
|
||||
isStarred: result,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Failed to star dashboard', err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the SceneQueryRunner to privide contextural parameters (tracking) props for the request
|
||||
*/
|
||||
@@ -230,6 +280,8 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> {
|
||||
}
|
||||
|
||||
canEditDashboard() {
|
||||
return Boolean(this.state.meta.canEdit || this.state.meta.canMakeEditable);
|
||||
const { meta } = this.state;
|
||||
|
||||
return Boolean(meta.canEdit || meta.canMakeEditable);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user