DashboardScenePageStateManager: Do not initialise dashboard meta after fetch (#80875)

This commit is contained in:
Dominik Prokop 2024-01-19 08:46:10 -08:00 committed by GitHub
parent 85d633f1b9
commit 361c49233d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 40 deletions

View File

@ -7,7 +7,7 @@ import { dashboardLoaderSrv } from 'app/features/dashboard/services/DashboardLoa
import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv';
import { buildNavModel } from 'app/features/folders/state/navModel';
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 { DashboardScene } from '../scene/DashboardScene';
@ -63,11 +63,8 @@ export class DashboardScenePageStateManager extends StateManagerBase<DashboardSc
}
if (rsp) {
// Fill in meta fields
const dashboard = this.initDashboardMeta(rsp);
if (dashboard.meta.url) {
const dashboardUrl = locationUtil.stripBaseFromUrl(dashboard.meta.url);
if (rsp.meta.url) {
const dashboardUrl = locationUtil.stripBaseFromUrl(rsp.meta.url);
const currentPath = locationService.getLocation().pathname;
if (dashboardUrl !== currentPath) {
// 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
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) {
// Ignore cancelled errors
@ -142,13 +139,6 @@ export class DashboardScenePageStateManager extends StateManagerBase<DashboardSc
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) {
// only the folder API has information about ancestors
// get parent folder (if it exists) and put it in the store
@ -182,25 +172,3 @@ export function getDashboardScenePageStateManager(): DashboardScenePageStateMana
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;
}

View File

@ -34,10 +34,10 @@ export class DashboardSceneUrlSync implements SceneObjectUrlSyncHandler {
}
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> = {};
if (typeof values.editview === 'string' && meta.canEdit) {
if (typeof values.editview === 'string' && this._scene.canEditDashboard()) {
update.editview = createDashboardEditViewFor(values.editview);
// If we are not in editing (for example after full page reload)

View File

@ -49,7 +49,11 @@ function DashboardPageProxy(props: DashboardPageProxyProps) {
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} />;
} else {
return <DashboardPage {...props} />;