DashboardScene: Restrict dashboard in read only state (#87316)

---------

Co-authored-by: Ivan Ortega Alba <ivanortegaalba@gmail.com>
This commit is contained in:
Sergej-Vlasov 2024-05-03 18:33:49 +03:00 committed by GitHub
parent 6a696a976b
commit 6433053479
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 14 deletions

View File

@ -51,9 +51,13 @@ export class DashboardSceneUrlSync implements SceneObjectUrlSyncHandler {
// If we are not in editing (for example after full page reload)
if (!isEditing) {
// Not sure what is best to do here.
// The reason for the timeout is for this change to happen after the url sync has completed
setTimeout(() => this._scene.onEnterEditMode());
if (this._scene.state.editable) {
// Not sure what is best to do here.
// The reason for the timeout is for this change to happen after the url sync has completed
setTimeout(() => this._scene.onEnterEditMode());
} else {
update.editview = undefined;
}
}
} else if (values.hasOwnProperty('editview')) {
update.editview = undefined;

View File

@ -55,6 +55,7 @@ export function ToolbarActions({ dashboard }: Props) {
meta,
editview,
editPanel,
editable,
hasCopiedPanel: copiedPanel,
} = dashboard.useState();
const { isPlaying } = playlistSrv.useState();
@ -328,7 +329,7 @@ export function ToolbarActions({ dashboard }: Props) {
toolbarActions.push({
group: 'main-buttons',
condition: !isEditing && dashboard.canEditDashboard() && !isViewingPanel && !isPlaying,
condition: !isEditing && dashboard.canEditDashboard() && !isViewingPanel && !isPlaying && editable,
render: () => (
<Button
onClick={() => {
@ -346,6 +347,27 @@ export function ToolbarActions({ dashboard }: Props) {
),
});
toolbarActions.push({
group: 'main-buttons',
condition: !isEditing && dashboard.canEditDashboard() && !isViewingPanel && !isPlaying && !editable,
render: () => (
<Button
onClick={() => {
dashboard.onEnterEditMode();
dashboard.setState({ editable: true, meta: { ...meta, canEdit: true } });
}}
tooltip="This dashboard was marked as read only"
key="edit"
className={styles.buttonWithExtraMargin}
variant="secondary"
size="sm"
data-testid={selectors.components.NavToolbar.editDashboard.editButton}
>
Make editable
</Button>
),
});
toolbarActions.push({
group: 'new-share-dashboard-button',
condition: config.featureToggles.newDashboardSharingComponent && showShareButton,

View File

@ -66,12 +66,12 @@ export function panelMenuBehavior(menu: VizPanelMenu, isRepeat = false) {
});
}
if (dashboard.canEditDashboard() && !isRepeat && !isEditingPanel) {
if (dashboard.canEditDashboard() && dashboard.state.editable && !isRepeat && !isEditingPanel) {
// We could check isEditing here but I kind of think this should always be in the menu,
// and going into panel edit should make the dashboard go into edit mode is it's not already
items.push({
text: t('panel.header-menu.edit', `Edit`),
iconClassName: 'eye',
iconClassName: 'edit',
shortcut: 'e',
onClick: () => DashboardInteractions.panelMenuItemClicked('edit'),
href: getEditPanelUrl(getPanelIdForVizPanel(panel)),

View File

@ -64,14 +64,6 @@ export function useDashboardEditPageNav(dashboard: DashboardScene, currentEditVi
});
}
if (dashboard.state.meta.canMakeEditable) {
pageNav.children!.push({
text: t('dashboard-settings.general.title', 'General'),
url: locationUtil.getUrlForPartial(location, { editview: 'settings', editIndex: null }),
active: currentEditView === 'settings',
});
}
if (dashboard.state.id && dashboard.state.meta.canSave) {
pageNav.children!.push({
text: t('dashboard-settings.versions.title', 'Versions'),