mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DashboardScenePageStateManager: Do not initialise dashboard meta after fetch (#80875)
This commit is contained in:
parent
85d633f1b9
commit
361c49233d
@ -7,7 +7,7 @@ import { dashboardLoaderSrv } from 'app/features/dashboard/services/DashboardLoa
|
|||||||
import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv';
|
import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv';
|
||||||
import { buildNavModel } from 'app/features/folders/state/navModel';
|
import { buildNavModel } from 'app/features/folders/state/navModel';
|
||||||
import { store } from 'app/store/store';
|
import { store } from 'app/store/store';
|
||||||
import { DashboardDTO, DashboardMeta, DashboardRoutes } from 'app/types';
|
import { DashboardDTO, DashboardRoutes } from 'app/types';
|
||||||
|
|
||||||
import { PanelEditor } from '../panel-edit/PanelEditor';
|
import { PanelEditor } from '../panel-edit/PanelEditor';
|
||||||
import { DashboardScene } from '../scene/DashboardScene';
|
import { DashboardScene } from '../scene/DashboardScene';
|
||||||
@ -63,11 +63,8 @@ export class DashboardScenePageStateManager extends StateManagerBase<DashboardSc
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rsp) {
|
if (rsp) {
|
||||||
// Fill in meta fields
|
if (rsp.meta.url) {
|
||||||
const dashboard = this.initDashboardMeta(rsp);
|
const dashboardUrl = locationUtil.stripBaseFromUrl(rsp.meta.url);
|
||||||
|
|
||||||
if (dashboard.meta.url) {
|
|
||||||
const dashboardUrl = locationUtil.stripBaseFromUrl(dashboard.meta.url);
|
|
||||||
const currentPath = locationService.getLocation().pathname;
|
const currentPath = locationService.getLocation().pathname;
|
||||||
if (dashboardUrl !== currentPath) {
|
if (dashboardUrl !== currentPath) {
|
||||||
// Spread current location to persist search params used for navigation
|
// Spread current location to persist search params used for navigation
|
||||||
@ -80,9 +77,9 @@ export class DashboardScenePageStateManager extends StateManagerBase<DashboardSc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Populate nav model in global store according to the folder
|
// Populate nav model in global store according to the folder
|
||||||
await this.initNavModel(dashboard);
|
await this.initNavModel(rsp);
|
||||||
|
|
||||||
this.dashboardCache.set(uid, { dashboard, ts: Date.now() });
|
this.dashboardCache.set(uid, { dashboard: rsp, ts: Date.now() });
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Ignore cancelled errors
|
// Ignore cancelled errors
|
||||||
@ -142,13 +139,6 @@ export class DashboardScenePageStateManager extends StateManagerBase<DashboardSc
|
|||||||
return Date.now() - entry.ts > DASHBOARD_CACHE_TTL;
|
return Date.now() - entry.ts > DASHBOARD_CACHE_TTL;
|
||||||
}
|
}
|
||||||
|
|
||||||
private initDashboardMeta(dashboard: DashboardDTO): DashboardDTO {
|
|
||||||
return {
|
|
||||||
...dashboard,
|
|
||||||
meta: initDashboardMeta(dashboard.meta, Boolean(dashboard.dashboard?.editable)),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private async initNavModel(dashboard: DashboardDTO) {
|
private async initNavModel(dashboard: DashboardDTO) {
|
||||||
// only the folder API has information about ancestors
|
// only the folder API has information about ancestors
|
||||||
// get parent folder (if it exists) and put it in the store
|
// get parent folder (if it exists) and put it in the store
|
||||||
@ -182,25 +172,3 @@ export function getDashboardScenePageStateManager(): DashboardScenePageStateMana
|
|||||||
|
|
||||||
return stateManager;
|
return stateManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
function initDashboardMeta(source: DashboardMeta, isEditable: boolean) {
|
|
||||||
const result = source ? { ...source } : {};
|
|
||||||
|
|
||||||
result.canShare = source.canShare !== false;
|
|
||||||
result.canSave = source.canSave !== false;
|
|
||||||
result.canStar = source.canStar !== false;
|
|
||||||
result.canEdit = source.canEdit !== false;
|
|
||||||
result.canDelete = source.canDelete !== false;
|
|
||||||
|
|
||||||
result.showSettings = source.canEdit;
|
|
||||||
result.canMakeEditable = source.canSave && !isEditable;
|
|
||||||
result.hasUnsavedFolderChange = false;
|
|
||||||
|
|
||||||
if (!isEditable) {
|
|
||||||
result.canEdit = false;
|
|
||||||
result.canDelete = false;
|
|
||||||
result.canSave = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
@ -34,10 +34,10 @@ export class DashboardSceneUrlSync implements SceneObjectUrlSyncHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateFromUrl(values: SceneObjectUrlValues): void {
|
updateFromUrl(values: SceneObjectUrlValues): void {
|
||||||
const { inspectPanelKey, viewPanelScene, meta, isEditing, editPanel } = this._scene.state;
|
const { inspectPanelKey, viewPanelScene, isEditing, editPanel } = this._scene.state;
|
||||||
const update: Partial<DashboardSceneState> = {};
|
const update: Partial<DashboardSceneState> = {};
|
||||||
|
|
||||||
if (typeof values.editview === 'string' && meta.canEdit) {
|
if (typeof values.editview === 'string' && this._scene.canEditDashboard()) {
|
||||||
update.editview = createDashboardEditViewFor(values.editview);
|
update.editview = createDashboardEditViewFor(values.editview);
|
||||||
|
|
||||||
// If we are not in editing (for example after full page reload)
|
// If we are not in editing (for example after full page reload)
|
||||||
|
@ -49,7 +49,11 @@ function DashboardPageProxy(props: DashboardPageProxyProps) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dashboard.value && !dashboard.value.meta.canEdit && isScenesSupportedRoute) {
|
if (
|
||||||
|
dashboard.value &&
|
||||||
|
!(dashboard.value.meta.canEdit || dashboard.value.meta.canMakeEditable) &&
|
||||||
|
isScenesSupportedRoute
|
||||||
|
) {
|
||||||
return <DashboardScenePage {...props} />;
|
return <DashboardScenePage {...props} />;
|
||||||
} else {
|
} else {
|
||||||
return <DashboardPage {...props} />;
|
return <DashboardPage {...props} />;
|
||||||
|
Loading…
Reference in New Issue
Block a user