SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
feat(dashboard-v2): enforce read-only behavior when a dashboard is locked (#12017)
Ashwin Bhatkal465620fbbb39
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/DashboardActions/DashboardActions.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/DashboardActions/DashboardActions.tsxindex c1761609d8..bea4446199 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/DashboardActions/DashboardActions.tsx+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/DashboardActions/DashboardActions.tsx@@ -1,4 +1,4 @@-import { useCallback, useMemo, useState } from 'react';+import { type ReactNode, useCallback, useMemo, useState } from 'react';import { FullScreenHandle } from 'react-full-screen';import { generatePath } from 'react-router-dom';import {@@ -29,12 +29,15 @@ import APIError from 'types/api/error';import { USER_ROLES } from 'types/roles';import ConfirmDeleteDialog from '../../components/ConfirmDeleteDialog/ConfirmDeleteDialog';+import DisabledControlTooltip from '../../components/DisabledControlTooltip/DisabledControlTooltip';+import DisabledMenuItemLabel from '../../components/DisabledMenuItemLabel/DisabledMenuItemLabel';import DashboardSettings from '../../DashboardSettings';import { useAddSection } from '../../PanelsAndSectionsLayout/Section/hooks/useAddSection';import SectionTitleModal from '../../PanelsAndSectionsLayout/Section/SectionTitleModal';import JsonEditorDrawer from '../JsonEditorDrawer/JsonEditorDrawer';import SettingsDrawer from '../SettingsDrawer';import styles from './DashboardActions.module.scss';+import { DASHBOARD_LOCKED_REASON } from '../../hooks/useDashboardEditGuard';import { useDashboardStore } from '../../store/useDashboardStore';interface DashboardActionsProps {@@ -58,7 +61,8 @@ function DashboardActions({onLockToggle,onOpenRename,}: DashboardActionsProps): JSX.Element {- const canEdit = useDashboardStore((s) => s.isEditable);+ const canEditDashboard = useDashboardStore((s) => s.canEditDashboard);+ const isLocked = useDashboardStore((s) => s.isLocked);const { user } = useAppContext();const { safeNavigate } = useSafeNavigate();const { showErrorModal } = useErrorModal();@@ -111,23 +115,38 @@ function DashboardActions({});}, [deleteDashboardMutation]);+ // Shown only to edit-permitted users, so the only disabled reason is the lock.+ const editLabel = useCallback(+ (text: string): ReactNode =>+ isLocked ? (+ <DisabledMenuItemLabel reason={DASHBOARD_LOCKED_REASON}>+ {text}+ </DisabledMenuItemLabel>+ ) : (+ text+ ),+ [isLocked],+ );+const menuItems = useMemo<MenuItem[]>(() => {const dashboardGroup: MenuItem[] = [];- if (canEdit) {+ if (canEditDashboard) {dashboardGroup.push({key: 'rename',- label: 'Rename',+ label: editLabel('Rename'),icon: <PenLine size={14} />,+ disabled: isLocked,onClick: onOpenRename,});+ // Clone creates a new dashboard, so it's not lock-gated.+ dashboardGroup.push({+ key: 'clone',+ label: 'Clone dashboard',+ icon: <Copy size={14} />,+ disabled: isCloning,+ onClick: (): void => void handleClone(),+ });}- dashboardGroup.push({- key: 'clone',- label: 'Clone dashboard',- icon: <Copy size={14} />,- disabled: isCloning,- onClick: (): void => void handleClone(),- });if (isAuthor || user.role === USER_ROLES.ADMIN) {dashboardGroup.push({key: 'lock',@@ -144,16 +163,6 @@ function DashboardActions({onClick: handle.enter,});- const layoutGroup: MenuItem[] = [];- if (canEdit) {- layoutGroup.push({- key: 'new-section',- label: 'New section',- icon: <SquareStack size={14} />,- onClick: (): void => setIsNewSectionOpen(true),- });- }-const items: MenuItem[] = [{type: 'group',@@ -162,27 +171,39 @@ function DashboardActions({children: dashboardGroup,},];- if (layoutGroup.length > 0) {+ // Omit the whole Layout group (header included) in view mode.+ if (canEditDashboard) {items.push({type: 'group',key: 'group-layout',label: 'Layout',- children: layoutGroup,+ children: [+ {+ key: 'new-section',+ label: editLabel('New section'),+ icon: <SquareStack size={14} />,+ disabled: isLocked,+ onClick: (): void => setIsNewSectionOpen(true),+ },+ ],});+ items.push(+ { type: 'divider', key: 'divider-danger' },+ {+ key: 'delete',+ label: editLabel('Delete dashboard'),+ icon: <Trash2 size={14} />,+ danger: true,+ disabled: isLocked,+ onClick: (): void => setIsDeleteOpen(true),+ },+ );}- items.push(- { type: 'divider', key: 'divider-danger' },- {- key: 'delete',- label: 'Delete dashboard',- icon: <Trash2 size={14} />,- danger: true,- onClick: (): void => setIsDeleteOpen(true),- },- );return items;}, [- canEdit,+ editLabel,+ canEditDashboard,+ isLocked,isCloning,isAuthor,user.role,@@ -207,18 +228,24 @@ function DashboardActions({Actions</Button></DropdownMenuSimple>- {canEdit && (+ {canEditDashboard && (<>- <Button- variant="solid"- color="secondary"- prefix={<Configure size="md" />}- testId="show-drawer"- onClick={(): void => setIsSettingsDrawerOpen(true)}- size="md"+ <DisabledControlTooltip+ reason={DASHBOARD_LOCKED_REASON}+ disabled={isLocked}>- Configure- </Button>+ <Button+ variant="solid"+ color="secondary"+ prefix={<Configure size="md" />}+ testId="show-drawer"+ disabled={isLocked}+ onClick={(): void => setIsSettingsDrawerOpen(true)}+ size="md"+ >+ Configure+ </Button>+ </DisabledControlTooltip><SettingsDrawerdrawerTitle="Dashboard Configuration"isOpen={isSettingsDrawerOpen}@@ -238,17 +265,23 @@ function DashboardActions({>JSON</Button>- {!isDashboardLocked && (- <Button- variant="solid"- color="primary"- onClick={onAddPanel}- prefix={<Plus size="md" />}- testId="add-panel-header"- size="md"+ {canEditDashboard && (+ <DisabledControlTooltip+ reason={DASHBOARD_LOCKED_REASON}+ disabled={isLocked}>- New Panel- </Button>+ <Button+ variant="solid"+ color="primary"+ onClick={onAddPanel}+ prefix={<Plus size="md" />}+ testId="add-panel-header"+ disabled={isLocked}+ size="md"+ >+ New Panel+ </Button>+ </DisabledControlTooltip>)}<JsonEditorDrawerdashboard={dashboard}diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/JsonEditorDrawer/JsonEditorDrawer.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/JsonEditorDrawer/JsonEditorDrawer.tsxindex daadb29478..0ac6881ec9 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/JsonEditorDrawer/JsonEditorDrawer.tsx+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/JsonEditorDrawer/JsonEditorDrawer.tsx@@ -14,6 +14,8 @@ import { defineJsonEditorTheme, JSON_EDITOR_THEME } from './editorTheme';import styles from './JsonEditorDrawer.module.scss';import JsonEditorToolbar from './JsonEditorToolbar';import { useJsonEditor } from './useJsonEditor';+import DisabledControlTooltip from '../../components/DisabledControlTooltip/DisabledControlTooltip';+import { useDashboardStore } from '../../store/useDashboardStore';interface JsonEditorDrawerProps {dashboard: DashboardtypesGettableDashboardV2DTO;@@ -28,6 +30,11 @@ function JsonEditorDrawer({}: JsonEditorDrawerProps): JSX.Element {const [, copyToClipboard] = useCopyToClipboard();+ const isEditable = useDashboardStore((s) => s.isEditable);+ const readOnlyReason = useDashboardStore((s) => s.editDisabledReason);+ // Inspect-only when not editable: Apply/Format/Reset disabled.+ const readOnly = !isEditable;+const {draft,setDraft,@@ -39,7 +46,7 @@ function JsonEditorDrawer({format,reset,apply,- } = useJsonEditor({ dashboard, isOpen, onApplied: onClose });+ } = useJsonEditor({ dashboard, isOpen, readOnly, onApplied: onClose });const onCopy = useCallback((): void => {copyToClipboard(draft);@@ -63,13 +70,15 @@ function JsonEditorDrawer({event.stopPropagation();if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {event.preventDefault();- void apply();+ if (!readOnly) {+ void apply();+ }}},- [apply],+ [apply, readOnly],);- const applyDisabled = !isDirty || !validity.valid || isSaving;+ const applyDisabled = readOnly || !isDirty || !validity.valid || isSaving;const validationText = validity.valid? `Valid JSON · ${validity.lineCount} lines`: `Line ${validity.errorLine ?? '?'} · ${validity.message ?? 'Invalid JSON'}`;@@ -150,16 +159,18 @@ function JsonEditorDrawer({>Cancel</Button>- <Button- variant="solid"- color="primary"- size="md"- testId="json-editor-apply"- disabled={applyDisabled}- onClick={(): void => void apply()}- >- Apply changes- </Button>+ <DisabledControlTooltip reason={readOnlyReason} disabled={readOnly}>+ <Button+ variant="solid"+ color="primary"+ size="md"+ testId="json-editor-apply"+ disabled={applyDisabled}+ onClick={readOnly ? undefined : (): void => void apply()}+ >+ Apply changes+ </Button>+ </DisabledControlTooltip></div></div>}@@ -168,6 +179,7 @@ function JsonEditorDrawer({<div className={styles.body} onKeyDown={onKeyDown}><JsonEditorToolbarisDirty={isDirty}+ readOnly={readOnly}onFormat={format}onCopy={onCopy}onDownload={onDownload}@@ -180,6 +192,7 @@ function JsonEditorDrawer({value={draft}onChange={(value): void => setDraft(value ?? '')}options={{+ readOnly,scrollbar: { alwaysConsumeMouseWheel: false },minimap: { enabled: false },fontSize: 13,diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/JsonEditorDrawer/JsonEditorToolbar.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/JsonEditorDrawer/JsonEditorToolbar.tsxindex df4fdd8584..97c5d38339 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/JsonEditorDrawer/JsonEditorToolbar.tsx+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/JsonEditorDrawer/JsonEditorToolbar.tsx@@ -5,6 +5,8 @@ import styles from './JsonEditorToolbar.module.scss';interface JsonEditorToolbarProps {isDirty: boolean;+ /** Locked/no-permission — Format and Reset (draft mutators) are disabled. */+ readOnly?: boolean;onFormat: () => void;onCopy: () => void;onDownload: () => void;@@ -13,6 +15,7 @@ interface JsonEditorToolbarProps {function JsonEditorToolbar({isDirty,+ readOnly = false,onFormat,onCopy,onDownload,@@ -26,6 +29,7 @@ function JsonEditorToolbar({size="sm"prefix={<AlignLeft size={14} />}testId="json-editor-format"+ disabled={readOnly}onClick={onFormat}>Format@@ -57,7 +61,7 @@ function JsonEditorToolbar({size="sm"prefix={<RotateCcw size={14} />}testId="json-editor-reset"- disabled={!isDirty}+ disabled={readOnly || !isDirty}onClick={onReset}>Resetdiff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/JsonEditorDrawer/__tests__/JsonEditorDrawer.test.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/JsonEditorDrawer/__tests__/JsonEditorDrawer.test.tsxindex 1fa96d2671..18aa8a1e91 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/JsonEditorDrawer/__tests__/JsonEditorDrawer.test.tsx+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/JsonEditorDrawer/__tests__/JsonEditorDrawer.test.tsx@@ -7,6 +7,13 @@ import { useJsonEditor } from '../useJsonEditor';jest.mock('../useJsonEditor', () => ({ useJsonEditor: jest.fn() }));+// Editable by default so the drawer renders in its editable (non-read-only) mode.+jest.mock('../../../store/useDashboardStore', () => ({+ useDashboardStore: (+ selector: (s: { isEditable: boolean; editDisabledReason: string }) => unknown,+ ): unknown => selector({ isEditable: true, editDisabledReason: '' }),+}));+jest.mock('@monaco-editor/react', () => ({__esModule: true,default: ({diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/JsonEditorDrawer/useJsonEditor.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/JsonEditorDrawer/useJsonEditor.tsindex d9f6da27b5..65573d2347 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/JsonEditorDrawer/useJsonEditor.ts+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/JsonEditorDrawer/useJsonEditor.ts@@ -23,6 +23,8 @@ export interface JsonValidity {interface Params {dashboard: DashboardtypesGettableDashboardV2DTO;isOpen: boolean;+ /** Locked/no-permission — `apply` is a no-op so edits can never be saved. */+ readOnly?: boolean;onApplied: () => void;}@@ -77,6 +79,7 @@ function errorLineFromMessage(export function useJsonEditor({dashboard,isOpen,+ readOnly = false,onApplied,}: Params): Result {const dashboardId = useDashboardStore((s) => s.dashboardId);@@ -147,7 +150,7 @@ export function useJsonEditor({}, [appliedText]);const apply = useCallback(async (): Promise<void> => {- if (!validity.valid || !isDirty) {+ if (readOnly || !validity.valid || !isDirty) {return;}try {@@ -173,6 +176,7 @@ export function useJsonEditor({validity.valid,isDirty,draft,+ readOnly,refetch,onApplied,showErrorModal,diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/index.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/index.tsxindex 657ba8dd2c..bdb5a860e7 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/index.tsx+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/index.tsx@@ -1,14 +1,17 @@import { useCallback, useEffect, useMemo, useState } from 'react';+import { useQueryClient } from 'react-query';import { FullScreenHandle } from 'react-full-screen';import { toast } from '@signozhq/ui/sonner';import logEvent from 'api/common/logEvent';import {+ getGetDashboardV2QueryKey,lockDashboardV2,unlockDashboardV2,} from 'api/generated/services/dashboard';import type {DashboardtypesGettableDashboardV2DTO,DashboardtypesJSONPatchOperationDTO,+ GetDashboardV2200,} from 'api/generated/services/sigNoz.schemas';import { Base64Icons } from 'container/DashboardContainer/DashboardSettings/General/utils';import DateTimeSelectionV2 from 'container/TopNav/DateTimeSelectionV2';@@ -32,13 +35,13 @@ import styles from './DashboardPageToolbar.module.scss';interface DashboardPageToolbarProps {dashboard: DashboardtypesGettableDashboardV2DTO;handle: FullScreenHandle;- refetch: () => void;}function DashboardPageToolbar(props: DashboardPageToolbarProps): JSX.Element {- const { dashboard, handle, refetch } = props;+ const { dashboard, handle } = props;const id = dashboard.id;+ const queryClient = useQueryClient();// Session-local lock state: the toggle appears once locked and persists for the page.const [isDashboardLocked, setIsDashboardLocked] = useState(!!dashboard.locked);@@ -101,12 +104,21 @@ function DashboardPageToolbar(props: DashboardPageToolbarProps): JSX.Element {await unlockDashboardV2({ id });toast.success('Dashboard unlocked');}- refetch();+ // Patch just the `locked` flag in the cache — a full refetch would reload+ // every panel's chart data for a metadata-only change.+ const key = getGetDashboardV2QueryKey({ id });+ const cached = queryClient.getQueryData<GetDashboardV2200>(key);+ if (cached) {+ queryClient.setQueryData<GetDashboardV2200>(key, {+ ...cached,+ data: { ...cached.data, locked: next },+ });+ }} catch (error) {setIsDashboardLocked(!next);showErrorModal(error as APIError);}- }, [id, isDashboardLocked, refetch, showErrorModal]);+ }, [id, isDashboardLocked, queryClient, showErrorModal]);const onNameSave = useCallback(async (next: string): Promise<void> => {diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/Header/Header.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/Header/Header.tsxindex 927906d354..c897598736 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/Header/Header.tsx+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/Header/Header.tsx@@ -6,12 +6,16 @@ import { Divider } from '@signozhq/ui/divider';import { Typography } from '@signozhq/ui/typography';import { useConfirmableAction } from 'hooks/useConfirmableAction';+import DisabledControlTooltip from '../../components/DisabledControlTooltip/DisabledControlTooltip';import styles from './Header.module.scss';interface HeaderProps {isDirty: boolean;isSaving: boolean;showSwitchToView?: boolean;+ /** Locked/no-permission dashboard — Save is disabled with a reason. */+ readOnly?: boolean;+ readOnlyReason?: string;onSave: () => void;onSwitchToView?: () => void;onClose: () => void;@@ -21,6 +25,8 @@ function Header({isDirty,isSaving,showSwitchToView = false,+ readOnly = false,+ readOnlyReason,onSave,onSwitchToView,onClose,@@ -63,16 +69,18 @@ function Header({Switch to View Mode</Button>)}- <Button- variant="solid"- color="primary"- data-testid="panel-editor-v2-save"- disabled={!isDirty || isSaving}- loading={isSaving}- onClick={onSave}- >- Save changes- </Button>+ <DisabledControlTooltip reason={readOnlyReason ?? ''} disabled={readOnly}>+ <Button+ variant="solid"+ color="primary"+ data-testid="panel-editor-v2-save"+ disabled={readOnly || !isDirty || isSaving}+ loading={!readOnly && isSaving}+ onClick={readOnly ? undefined : onSave}+ >+ Save changes+ </Button>+ </DisabledControlTooltip></div><DialogWrapperdiff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/__tests__/PanelEditorContainer.test.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/__tests__/PanelEditorContainer.test.tsxindex f48283fe31..941378ce73 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/__tests__/PanelEditorContainer.test.tsx+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/__tests__/PanelEditorContainer.test.tsx@@ -159,6 +159,8 @@ function makePanel(const baseProps = {dashboardId: 'dash-1',panelId: 'panel-1',+ isEditable: true,+ editDisabledReason: '',onClose: jest.fn(),onSaved: jest.fn(),};diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/index.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/index.tsxindex 15fe10b055..901ba8cf74 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/index.tsx+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelEditor/index.tsx@@ -43,6 +43,10 @@ interface PanelEditorContainerProps {isNew?: boolean;/** Target section for a new panel; falls back to the last/new section. */layoutIndex?: number;+ /** The dashboard can be edited (unlocked + permission); gates Save. */+ isEditable: boolean;+ /** Why Save is disabled (locked / no permission); '' when editable. */+ editDisabledReason: string;/** Leave the editor (navigate back to the dashboard) without saving. */onClose: () => void;/** Called after a successful save — navigates back to the dashboard. */@@ -60,6 +64,8 @@ function PanelEditorContainer({panel,isNew = false,layoutIndex,+ isEditable,+ editDisabledReason,onClose,onSaved,}: PanelEditorContainerProps): JSX.Element {@@ -198,6 +204,9 @@ function PanelEditorContainer({});const onSave = useCallback(async (): Promise<void> => {+ if (!isEditable) {+ return;+ }try {// Bake the live query into the spec so unstaged edits are saved too.await save(buildSaveSpec(draft.spec));@@ -206,7 +215,7 @@ function PanelEditorContainer({} catch {toast.error('Failed to save panel');}- }, [save, buildSaveSpec, draft.spec, onSaved]);+ }, [isEditable, save, buildSaveSpec, draft.spec, onSaved]);return (<div className={styles.page} data-testid="panel-editor-v2">@@ -214,6 +223,8 @@ function PanelEditorContainer({isDirty={isDirty}isSaving={isSaving}showSwitchToView={!isNew}+ readOnly={!isEditable}+ readOnlyReason={editDisabledReason}onSave={onSave}onSwitchToView={onSwitchToView}onClose={onClose}diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelActionsMenu/__tests__/usePanelActionItems.test.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelActionsMenu/__tests__/usePanelActionItems.test.tsxindex 960373f9bc..1781376de0 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelActionsMenu/__tests__/usePanelActionItems.test.tsx+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelActionsMenu/__tests__/usePanelActionItems.test.tsx@@ -7,6 +7,15 @@ import type { DashboardSection } from '../../../../utils';import { useDashboardStore } from '../../../../store/useDashboardStore';import { usePanelActionItems } from '../usePanelActionItems';+/** Keys of the disabled items, in order. */+function disabledKeys(+ result: ReturnType<typeof usePanelActionItems>,+): unknown[] {+ return result.items+ .filter((item) => 'disabled' in item && item.disabled)+ .map((item) => ('key' in item ? item.key : undefined));+}+const mockOpenEditor = jest.fn();jest.mock('pages/DashboardPageV2/DashboardContainer/hooks/useOpenPanelEditor',@@ -115,7 +124,7 @@ describe('usePanelActionItems', () => {beforeEach(() => {jest.clearAllMocks();mockRole = 'ADMIN';- useDashboardStore.setState({ isEditable: true });+ useDashboardStore.setState({ canEditDashboard: true, isLocked: false });});it('ADMIN on an editable dashboard with a known kind gets the full V1-parity set, divider-separated', () => {@@ -162,18 +171,42 @@ describe('usePanelActionItems', () => {]);});- it('read-only dashboard keeps the non-mutating actions (View, Download, Create Alerts)', () => {- useDashboardStore.setState({ isEditable: false });+ it('no edit permission (view mode) hides the edit actions entirely', () => {+ useDashboardStore.setState({ canEditDashboard: false });+ const { result } = renderHook(() =>+ usePanelActionItems({ ...baseArgs, panelActions: undefined }),+ );+ expect(itemKeys(result.current)).toStrictEqual([+ 'view-panel',+ 'divider',+ 'download',+ 'create-alert',+ ]);+ });++ it('locked (edit mode) keeps the edit actions visible but disabled', () => {+ useDashboardStore.setState({ canEditDashboard: true, isLocked: true });+ // A locked dashboard mounts panels without layout context (no panelActions).const { result } = renderHook(() =>usePanelActionItems({ ...baseArgs, panelActions: undefined }),);- // View, the Download submenu (PNG/SVG) and Create Alerts are all- // non-mutating, so they survive on a read-only dashboard (V1 parity).expect(itemKeys(result.current)).toStrictEqual(['view-panel',+ 'edit-panel',+ 'clone-panel','divider','download','create-alert',+ 'divider',+ 'move',+ 'divider',+ 'delete-panel',+ ]);+ expect(disabledKeys(result.current)).toStrictEqual([+ 'edit-panel',+ 'clone-panel',+ 'move',+ 'delete-panel',]);});diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelActionsMenu/usePanelActionItems.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelActionsMenu/usePanelActionItems.tsxindex e4247e8585..566c034d58 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelActionsMenu/usePanelActionItems.tsx+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelActionsMenu/usePanelActionItems.tsx@@ -1,5 +1,12 @@-import { useCallback, useMemo } from 'react';-import { Bell, Copy, Fullscreen, PenLine, Trash2 } from '@signozhq/icons';+import { type ReactNode, useCallback, useMemo } from 'react';+import {+ Bell,+ Copy,+ FolderInput,+ Fullscreen,+ PenLine,+ Trash2,+} from '@signozhq/icons';import type { MenuItem } from '@signozhq/ui/dropdown-menu';import type { DashboardtypesPanelDTO } from 'api/generated/services/sigNoz.schemas';import useComponentPermission from 'hooks/useComponentPermission';@@ -23,6 +30,8 @@ import { useMovePanelToSection } from '../hooks/useMovePanelToSection';import { useViewPanel } from '../hooks/useViewPanel';import { buildMoveItems } from '../utils/buildMoveItems';import { PANEL_ACTION_META } from './panelActionMeta';+import DisabledMenuItemLabel from '../../../components/DisabledMenuItemLabel/DisabledMenuItemLabel';+import { DASHBOARD_LOCKED_REASON } from '../../../hooks/useDashboardEditGuard';// Stable fallback so renders without layout context don't churn the mutation// hooks' deps (a fresh [] each render would re-create their callbacks).@@ -67,7 +76,8 @@ export function usePanelActionItems({],user.role,);- const isEditable = useDashboardStore((s) => s.isEditable);+ const canEditDashboard = useDashboardStore((s) => s.canEditDashboard);+ const isLocked = useDashboardStore((s) => s.isLocked);const openPanelEditor = useOpenPanelEditor();const createAlert = useCreateAlertFromPanel();const { openView } = useViewPanel();@@ -102,6 +112,18 @@ export function usePanelActionItems({const { request: requestDelete } = deleteConfirm;const items = useMemo<MenuItem[]>(() => {+ // Edit actions are shown only to edit-permitted users; the lock is their only+ // disabled state, surfaced as a hover tooltip on the row.+ const canEdit = canEditDashboard;+ const label = (text: string): ReactNode =>+ isLocked ? (+ <DisabledMenuItemLabel reason={DASHBOARD_LOCKED_REASON}>+ {text}+ </DisabledMenuItemLabel>+ ) : (+ text+ );+const panelGroup: MenuItem[] = [];if (panelCapabilities.view) {panelGroup.push({@@ -111,26 +133,30 @@ export function usePanelActionItems({onClick: (): void => openView(panelId),});}- if (isEditable && canEditWidget && panelCapabilities.edit) {+ if (canEdit && canEditWidget && panelCapabilities.edit) {panelGroup.push({key: 'edit-panel',- label: 'Edit panel',+ label: label('Edit panel'),icon: <PenLine size={14} />,+ disabled: isLocked,onClick: (): void => openPanelEditor(panelId),});}- // Clone needs the section context to place the copy, so — unlike Edit —- // it requires panelActions.- if (isEditable && canEditWidget && panelActions && panelCapabilities.clone) {+ if (canEdit && canEditWidget && panelCapabilities.clone) {+ // Needs section context to place the copy; disabled without it.panelGroup.push({key: 'clone-panel',- label: 'Clone',+ label: label('Clone'),icon: <Copy size={14} />,- onClick: (): void =>- void clonePanel({- panelId,- layoutIndex: panelActions.currentLayoutIndex,- }),+ disabled: isLocked || !panelActions,+ onClick: (): void => {+ if (panelActions) {+ void clonePanel({+ panelId,+ layoutIndex: panelActions.currentLayoutIndex,+ });+ }+ },});}@@ -140,7 +166,7 @@ export function usePanelActionItems({}// Create Alerts opens a new tab and never mutates the dashboard, so —- // unlike edit/clone — it isn't gated on `isEditable` (V1 parity).+ // unlike edit/clone — it isn't gated on editability (V1 parity).if (panelCapabilities.createAlert) {dataGroup.push({key: 'create-alert',@@ -150,24 +176,35 @@ export function usePanelActionItems({});}- const moveGroup: MenuItem[] =- canMove && panelActions- ? buildMoveItems({- sections,- currentLayoutIndex: panelActions.currentLayoutIndex,- panelId,- movePanel,- })- : [];+ let moveGroup: MenuItem[] = [];+ if (canEdit && canMove) {+ moveGroup =+ !isLocked && panelActions+ ? buildMoveItems({+ sections,+ currentLayoutIndex: panelActions.currentLayoutIndex,+ panelId,+ movePanel,+ })+ : [+ {+ key: 'move',+ label: label('Move to section'),+ icon: <FolderInput size={14} />,+ disabled: true,+ },+ ];+ }const deleteGroup: MenuItem[] =- canDelete && panelActions+ canEdit && canDelete? [{key: 'delete-panel',danger: true,icon: <Trash2 size={14} />,- label: 'Delete panel',+ label: label('Delete panel'),+ disabled: isLocked || !panelActions,onClick: (): void => requestDelete(),},]@@ -179,7 +216,8 @@ export function usePanelActionItems({index === 0 ? group : [{ type: 'divider' as const }, ...group],);}, [- isEditable,+ canEditDashboard,+ isLocked,canEditWidget,canMove,canDelete,diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Section/Section/Section.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Section/Section/Section.tsxindex 7e5c71e19c..1021e7af20 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Section/Section/Section.tsx+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Section/Section/Section.tsx@@ -5,6 +5,8 @@ import { Button } from '@signozhq/ui/button';import { useIntersectionObserver } from 'hooks/useIntersectionObserver';import ConfirmDeleteDialog from '../../../components/ConfirmDeleteDialog/ConfirmDeleteDialog';+import DisabledControlTooltip from '../../../components/DisabledControlTooltip/DisabledControlTooltip';+import { DASHBOARD_LOCKED_REASON } from '../../../hooks/useDashboardEditGuard';import { useCreatePanel } from '../../../hooks/useCreatePanel';import type { DashboardSection } from '../../../utils';import PanelTypeSelectionModal from '../../Panel/PanelTypeSelectionModal/PanelTypeSelectionModal';@@ -28,7 +30,8 @@ interface SectionProps {}function Section({ section, sections, dragHandle }: SectionProps): JSX.Element {- const isEditable = useDashboardStore((s) => s.isEditable);+ const canEditDashboard = useDashboardStore((s) => s.canEditDashboard);+ const isLocked = useDashboardStore((s) => s.isLocked);const {isPickerOpen,openPicker,@@ -104,8 +107,9 @@ function Section({ section, sections, dragHandle }: SectionProps): JSX.Element {onToggle={toggle}repeatVariable={section.repeatVariable}dragHandle={dragHandle}+ disabledReason={isLocked ? DASHBOARD_LOCKED_REASON : ''}actions={- isEditable+ canEditDashboard? {onRename: (): void => setIsRenaming(true),onAddPanel: (): void => openPicker(section.layoutIndex),@@ -119,17 +123,25 @@ function Section({ section, sections, dragHandle }: SectionProps): JSX.Element {grid) : (<div className={styles.emptySection}>- {isEditable && (- <Button- type="button"- variant="dashed"- color="secondary"- prefix={<Plus size="md" />}- onClick={(): void => openPicker(section.layoutIndex)}- testId={`section-add-panel-${section.id}`}+ {canEditDashboard && (+ <DisabledControlTooltip+ reason={DASHBOARD_LOCKED_REASON}+ disabled={isLocked}>- New Panel- </Button>+ <Button+ type="button"+ variant="dashed"+ color="secondary"+ prefix={<Plus size="md" />}+ disabled={isLocked}+ onClick={+ isLocked ? undefined : (): void => openPicker(section.layoutIndex)+ }+ testId={`section-add-panel-${section.id}`}+ >+ New Panel+ </Button>+ </DisabledControlTooltip>)}</div>))}diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Section/SectionActionsMenu/SectionActionsMenu.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Section/SectionActionsMenu/SectionActionsMenu.tsxindex 684430c422..144256e32d 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Section/SectionActionsMenu/SectionActionsMenu.tsx+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Section/SectionActionsMenu/SectionActionsMenu.tsx@@ -1,13 +1,16 @@-import { useMemo } from 'react';+import { type ReactNode, useMemo } from 'react';import { EllipsisVertical, PenLine, Plus, Trash2 } from '@signozhq/icons';import { Button } from '@signozhq/ui/button';import { DropdownMenuSimple } from '@signozhq/ui/dropdown-menu';import type { MenuItem } from '@signozhq/ui/dropdown-menu';+import DisabledMenuItemLabel from '../../../components/DisabledMenuItemLabel/DisabledMenuItemLabel';import styles from './SectionActionsMenu.module.scss';interface SectionActionsMenuProps {sectionId: string;+ /** Non-empty when edits are unavailable — items render disabled with this reason. */+ disabledReason?: string;onAddPanel?: () => void;onRename?: () => void;onDeleteSection?: () => void;@@ -15,17 +18,28 @@ interface SectionActionsMenuProps {function SectionActionsMenu({sectionId,+ disabledReason = '',onAddPanel,onRename,onDeleteSection,}: SectionActionsMenuProps): JSX.Element {const items = useMemo<MenuItem[]>(() => {+ const disabled = !!disabledReason;+ const label = (text: string): ReactNode =>+ disabled ? (+ <DisabledMenuItemLabel reason={disabledReason}>+ {text}+ </DisabledMenuItemLabel>+ ) : (+ text+ );const result: MenuItem[] = [];if (onAddPanel) {result.push({key: 'add-panel',icon: <Plus size={14} />,- label: 'Add panel',+ label: label('Add panel'),+ disabled,onClick: onAddPanel,});}@@ -33,7 +47,8 @@ function SectionActionsMenu({result.push({key: 'rename',icon: <PenLine size={14} />,- label: 'Rename section',+ label: label('Rename section'),+ disabled,onClick: onRename,});}@@ -44,13 +59,14 @@ function SectionActionsMenu({key: 'delete-section',danger: true,icon: <Trash2 size={14} />,- label: 'Delete section',+ label: label('Delete section'),+ disabled,onClick: onDeleteSection,},);}return result;- }, [onAddPanel, onRename, onDeleteSection]);+ }, [disabledReason, onAddPanel, onRename, onDeleteSection]);return (<DropdownMenuSimple menu={{ items }}>diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Section/SectionHeader/SectionHeader.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Section/SectionHeader/SectionHeader.tsxindex 460aef9dc6..543d88be2b 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Section/SectionHeader/SectionHeader.tsx+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Section/SectionHeader/SectionHeader.tsx@@ -29,8 +29,10 @@ interface SectionHeaderProps {repeatVariable?: string;/** Provided by SortableSection in sectioned mode; absent for untitled/free-flow. */dragHandle?: SectionDragHandle;- /** Present only in editable mode; absent (read-only) when locked/no-permission. */+ /** Present for edit-permitted users; absent (no menu) in view mode. */actions?: SectionHeaderActions;+ /** Non-empty when locked — actions render disabled with this reason. */+ disabledReason?: string;}function SectionHeader({@@ -41,6 +43,7 @@ function SectionHeader({repeatVariable,dragHandle,actions,+ disabledReason = '',}: SectionHeaderProps): JSX.Element {return (<div className={cx(styles.header, { [styles.headerOpen]: open })}>@@ -79,6 +82,7 @@ function SectionHeader({{actions ? (<SectionActionsMenusectionId={sectionId}+ disabledReason={disabledReason}onAddPanel={actions.onAddPanel}onRename={actions.onRename}onDeleteSection={actions.onDeleteSection}diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/components/DisabledControlTooltip/DisabledControlTooltip.module.scss b/frontend/src/pages/DashboardPageV2/DashboardContainer/components/DisabledControlTooltip/DisabledControlTooltip.module.scssnew file mode 100644index 0000000000..2a72edc7bd--- /dev/null+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/components/DisabledControlTooltip/DisabledControlTooltip.module.scss@@ -0,0 +1,9 @@+.trigger {+ display: inline-flex;+}++.aboveOverlay {+ // Lift the tooltip above the dropdown menu (z 50) and the antd Drawer (z 1000)+ // so it is never clipped behind them. The tooltip content reads this variable.+ --tooltip-z-index: 1100;+}diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/components/DisabledControlTooltip/DisabledControlTooltip.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/components/DisabledControlTooltip/DisabledControlTooltip.tsxnew file mode 100644index 0000000000..2a72fa8941--- /dev/null+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/components/DisabledControlTooltip/DisabledControlTooltip.tsx@@ -0,0 +1,33 @@+import type { ReactNode } from 'react';+import { TooltipSimple } from '@signozhq/ui/tooltip';++import styles from './DisabledControlTooltip.module.scss';++interface DisabledControlTooltipProps {+ reason: string;+ disabled: boolean;+ children: ReactNode;+}++// A disabled button swallows hover, so the wrapping span is the tooltip trigger.+function DisabledControlTooltip({+ reason,+ disabled,+ children,+}: DisabledControlTooltipProps): JSX.Element {+ if (!disabled) {+ return <>{children}</>;+ }+ return (+ <TooltipSimple+ title={reason}+ arrow+ disableHoverableContent+ tooltipContentProps={{ className: styles.aboveOverlay }}+ >+ <span className={styles.trigger}>{children}</span>+ </TooltipSimple>+ );+}++export default DisabledControlTooltip;diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/components/DisabledMenuItemLabel/DisabledMenuItemLabel.module.scss b/frontend/src/pages/DashboardPageV2/DashboardContainer/components/DisabledMenuItemLabel/DisabledMenuItemLabel.module.scssnew file mode 100644index 0000000000..1c665285cf--- /dev/null+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/components/DisabledMenuItemLabel/DisabledMenuItemLabel.module.scss@@ -0,0 +1,10 @@+.label {+ // Re-enable pointer events so the tooltip fires while the disabled row+ // (pointer-events: none) suppresses selection.+ pointer-events: auto;+}++.aboveOverlay {+ // Lift the tooltip above the dropdown menu (z 50) and the antd Drawer (z 1000).+ --tooltip-z-index: 1100;+}diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/components/DisabledMenuItemLabel/DisabledMenuItemLabel.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/components/DisabledMenuItemLabel/DisabledMenuItemLabel.tsxnew file mode 100644index 0000000000..9563da41d0--- /dev/null+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/components/DisabledMenuItemLabel/DisabledMenuItemLabel.tsx@@ -0,0 +1,28 @@+import type { ReactNode } from 'react';+import { TooltipSimple } from '@signozhq/ui/tooltip';++import styles from './DisabledMenuItemLabel.module.scss';++interface DisabledMenuItemLabelProps {+ reason: string;+ children: ReactNode;+}++// A disabled row has pointer-events: none, so the label re-enables them to catch hover.+function DisabledMenuItemLabel({+ reason,+ children,+}: DisabledMenuItemLabelProps): JSX.Element {+ return (+ <TooltipSimple+ title={reason}+ arrow+ disableHoverableContent+ tooltipContentProps={{ className: styles.aboveOverlay }}+ >+ <span className={styles.label}>{children}</span>+ </TooltipSimple>+ );+}++export default DisabledMenuItemLabel;diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/components/LockedIndicator/LockedIndicator.module.scss b/frontend/src/pages/DashboardPageV2/DashboardContainer/components/LockedIndicator/LockedIndicator.module.scssnew file mode 100644index 0000000000..2280df5bd0--- /dev/null+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/components/LockedIndicator/LockedIndicator.module.scss@@ -0,0 +1,34 @@+.footer {+ display: flex;+ flex-direction: column;+ position: fixed;+ bottom: 0;+ left: 0;+ width: 100%;+ z-index: 100;+ pointer-events: none;+}++.lockedText {+ align-self: flex-end;+ display: inline-flex;+ align-items: center;+ gap: 4px;+ padding: 4px 6px;+ border-radius: 4px 0 0 0;+ background: var(--bg-sakura-500);+ color: var(--l1-foreground);+ backdrop-filter: blur(6px);+ font-family: 'Space Mono';+ font-size: 12px;+ font-weight: 500;+ line-height: 16px;+ letter-spacing: 0.48px;+ text-transform: uppercase;+}++.lockedBar {+ width: 100%;+ height: 6px;+ background: var(--bg-sakura-500);+}diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/components/LockedIndicator/LockedIndicator.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/components/LockedIndicator/LockedIndicator.tsxnew file mode 100644index 0000000000..ae73150696--- /dev/null+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/components/LockedIndicator/LockedIndicator.tsx@@ -0,0 +1,17 @@+import { LockKeyhole } from '@signozhq/icons';++import styles from './LockedIndicator.module.scss';++function LockedIndicator(): JSX.Element {+ return (+ <div className={styles.footer}>+ <div className={styles.lockedText} data-testid="dashboard-locked-indicator">+ <LockKeyhole size={14} />+ Locked+ </div>+ <div className={styles.lockedBar} />+ </div>+ );+}++export default LockedIndicator;diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/__tests__/useOptimisticPatch.test.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/__tests__/useOptimisticPatch.test.tsindex fbf224152e..2e0a31f699 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/__tests__/useOptimisticPatch.test.ts+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/__tests__/useOptimisticPatch.test.ts@@ -21,8 +21,8 @@ jest.mock('api/generated/services/dashboard', () => ({jest.mock('../../store/useDashboardStore', () => ({useDashboardStore: jest.fn(- (selector: (s: { dashboardId: string }) => unknown) =>- selector({ dashboardId: 'dash-1' }),+ (selector: (s: { dashboardId: string; isEditable: boolean }) => unknown) =>+ selector({ dashboardId: 'dash-1', isEditable: true }),),}));diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/useDashboardEditGuard.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/useDashboardEditGuard.tsnew file mode 100644index 0000000000..f441531419--- /dev/null+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/useDashboardEditGuard.ts@@ -0,0 +1,48 @@+import type { DashboardtypesGettableDashboardV2DTO } from 'api/generated/services/sigNoz.schemas';+import useComponentPermission from 'hooks/useComponentPermission';+import { useAppContext } from 'providers/App/App';++import {+ DASHBOARD_LOCKED_REASON,+ DASHBOARD_NO_EDIT_PERMISSION_REASON,+} from '../store/slices/editContextSlice';++// Re-exported from the (dependency-light) slice so leaf modules / tests can import+// the reason strings without pulling this hook's provider chain.+export {+ DASHBOARD_LOCKED_REASON,+ DASHBOARD_NO_EDIT_PERMISSION_REASON,+} from '../store/slices/editContextSlice';++export interface DashboardEditGuard {+ isEditable: boolean;+ isLocked: boolean;+ canEditDashboard: boolean;+ editDisabledReason: string;+}++// Editability + reason, derived from the dashboard (used where the store is cold,+// e.g. the panel-editor route reached by direct URL).+export function useDashboardEditGuard(+ dashboard: DashboardtypesGettableDashboardV2DTO | undefined,+): DashboardEditGuard {+ const { user } = useAppContext();+ const [editDashboardPermission] = useComponentPermission(+ ['edit_dashboard'],+ user.role,+ );+ const canEditDashboard = !!editDashboardPermission;+ const isLocked = !!dashboard?.locked;+ let editDisabledReason = '';+ if (isLocked) {+ editDisabledReason = DASHBOARD_LOCKED_REASON;+ } else if (!canEditDashboard) {+ editDisabledReason = DASHBOARD_NO_EDIT_PERMISSION_REASON;+ }+ return {+ isEditable: canEditDashboard && !isLocked,+ isLocked,+ canEditDashboard,+ editDisabledReason,+ };+}diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/useOptimisticPatch.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/useOptimisticPatch.tsindex 36484288d7..739c5bbe80 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/useOptimisticPatch.ts+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/useOptimisticPatch.ts@@ -1,3 +1,4 @@+import { useCallback } from 'react';import { useMutation, useQueryClient } from 'react-query';import {getGetDashboardV2QueryKey,@@ -11,6 +12,7 @@ import type {import APIError from 'types/api/error';import { applyJsonPatch } from '../optimistic/applyJsonPatch';+import { DASHBOARD_LOCKED_REASON } from '../store/slices/editContextSlice';import { useDashboardStore } from '../store/useDashboardStore';/** Cached dashboard snapshot, kept for rollback on error. */@@ -35,6 +37,7 @@ export function useOptimisticPatch(dashboardIdOverride?: string,): UseOptimisticPatch {const storeDashboardId = useDashboardStore((s) => s.dashboardId);+ const storeIsEditable = useDashboardStore((s) => s.isEditable);const dashboardId = dashboardIdOverride ?? storeDashboardId;const queryClient = useQueryClient();const queryKey = getGetDashboardV2QueryKey({ id: dashboardId });@@ -69,8 +72,22 @@ export function useOptimisticPatch(},});+ // Defense-in-depth: block edits when the store is warm for this dashboard and it+ // isn't editable. Skipped when the store isn't seeded for this id (panel editor+ // via direct URL), where that surface gates its own save.+ const { mutateAsync } = mutation;+ const patchAsync = useCallback(+ (ops: DashboardtypesJSONPatchOperationDTO[]): Promise<unknown> => {+ if (storeDashboardId === dashboardId && !storeIsEditable) {+ return Promise.reject(new Error(DASHBOARD_LOCKED_REASON));+ }+ return mutateAsync(ops);+ },+ [storeDashboardId, dashboardId, storeIsEditable, mutateAsync],+ );+return {- patchAsync: mutation.mutateAsync,+ patchAsync,isPatching: mutation.isLoading,error: mutation.error ?? null,};diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/index.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/index.tsxindex eb9ea85f18..563d3c9759 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/index.tsx+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/index.tsx@@ -2,16 +2,16 @@ import { useEffect } from 'react';import { FullScreen, useFullScreenHandle } from 'react-full-screen';import type { DashboardtypesGettableDashboardV2DTO } from 'api/generated/services/sigNoz.schemas';-import useComponentPermission from 'hooks/useComponentPermission';-import { useAppContext } from 'providers/App/App';import DashboardPageToolbar from './DashboardPageToolbar';import PanelsAndSectionsLayout from './PanelsAndSectionsLayout';+import { useDashboardEditGuard } from './hooks/useDashboardEditGuard';import { useResolvedVariables } from './hooks/useResolvedVariables';import { useSyncVariablesForSuggestions } from './hooks/useSyncVariablesForSuggestions';import { useDashboardStore } from './store/useDashboardStore';import styles from './DashboardContainer.module.scss';import DashboardPageHeader from './components/DashboardPageHeader/DashboardPageHeader';+import LockedIndicator from './components/LockedIndicator/LockedIndicator';import { Base64Icons } from './DashboardSettings/Overview/utils';interface DashboardContainerProps {@@ -33,18 +33,15 @@ function DashboardContainer({const fullScreenHandle = useFullScreenHandle();- const { user } = useAppContext();- const [editDashboardPermission] = useComponentPermission(- ['edit_dashboard'],- user.role,- );+ const { isLocked, canEditDashboard } = useDashboardEditGuard(dashboard);// Seed during render (not an effect) so the first Panel render already sees the id —// useDashboardFetchRequired throws on a missing id. setEditContext self-guards.const setEditContext = useDashboardStore((s) => s.setEditContext);setEditContext({dashboardId: dashboard.id,- isEditable: !dashboard.locked && editDashboardPermission,+ isLocked,+ canEditDashboard,refetch,});@@ -60,12 +57,9 @@ function DashboardContainer({<FullScreen handle={fullScreenHandle}><div className={styles.container}><DashboardPageHeader title={name} image={image} />- <DashboardPageToolbar- dashboard={dashboard}- handle={fullScreenHandle}- refetch={refetch}- />+ <DashboardPageToolbar dashboard={dashboard} handle={fullScreenHandle} /><PanelsAndSectionsLayout layouts={spec.layouts} panels={spec.panels} />+ {isLocked && <LockedIndicator />}</div></FullScreen>);diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/store/slices/editContextSlice.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/store/slices/editContextSlice.tsindex 00bd885a1e..981035be33 100644--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/store/slices/editContextSlice.ts+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/store/slices/editContextSlice.ts@@ -2,19 +2,24 @@ import type { StateCreator } from 'zustand';import type { DashboardStore } from '../useDashboardStore';-/**- * Edit context shared across the V2 dashboard tree — the dashboard id, whether- * the user can edit, and the react-query refetch. Set once by DashboardContainer- * so hooks/components read it from the store instead of receiving it as props- * through every layer. Not persisted.- */+export const DASHBOARD_LOCKED_REASON = 'This dashboard is locked';+export const DASHBOARD_NO_EDIT_PERMISSION_REASON =+ 'You don’t have permission to edit this dashboard';++// Edit context shared across the V2 dashboard tree, set once by DashboardContainer.export interface EditContextSlice {dashboardId: string;+ // canEditDashboard && !isLocked.isEditable: boolean;+ isLocked: boolean;+ canEditDashboard: boolean;+ // Locked / no-permission reason for tooltips; '' when editable.+ editDisabledReason: string;refetch: () => void;setEditContext: (ctx: {dashboardId: string;- isEditable: boolean;+ isLocked: boolean;+ canEditDashboard: boolean;refetch: () => void;}) => void;}@@ -27,20 +32,35 @@ export const createEditContextSlice: StateCreator<> = (set, get) => ({dashboardId: '',isEditable: false,+ isLocked: false,+ canEditDashboard: false,+ editDisabledReason: '',refetch: (): void => undefined,// Idempotent (no-op when unchanged) so it's safe to call during render.setEditContext: (ctx): void => {- const { dashboardId, isEditable, refetch } = get();+ const isEditable = ctx.canEditDashboard && !ctx.isLocked;+ let editDisabledReason = '';+ if (ctx.isLocked) {+ editDisabledReason = DASHBOARD_LOCKED_REASON;+ } else if (!ctx.canEditDashboard) {+ editDisabledReason = DASHBOARD_NO_EDIT_PERMISSION_REASON;+ }+ const prev = get();if (- dashboardId === ctx.dashboardId &&- isEditable === ctx.isEditable &&- refetch === ctx.refetch+ prev.dashboardId === ctx.dashboardId &&+ prev.isEditable === isEditable &&+ prev.isLocked === ctx.isLocked &&+ prev.canEditDashboard === ctx.canEditDashboard &&+ prev.refetch === ctx.refetch) {return;}set({dashboardId: ctx.dashboardId,- isEditable: ctx.isEditable,+ isEditable,+ isLocked: ctx.isLocked,+ canEditDashboard: ctx.canEditDashboard,+ editDisabledReason,refetch: ctx.refetch,});},diff --git a/frontend/src/pages/DashboardPageV2/PanelEditorPage/PanelEditorPage.tsx b/frontend/src/pages/DashboardPageV2/PanelEditorPage/PanelEditorPage.tsxindex 57df7c1aec..25ebdbb042 100644--- a/frontend/src/pages/DashboardPageV2/PanelEditorPage/PanelEditorPage.tsx+++ b/frontend/src/pages/DashboardPageV2/PanelEditorPage/PanelEditorPage.tsx@@ -12,6 +12,7 @@ import ROUTES from 'constants/routes';import { useSafeNavigate } from 'hooks/useSafeNavigate';import { useDashboardFetch } from '../DashboardContainer/hooks/useDashboardFetch';+import { useDashboardEditGuard } from '../DashboardContainer/hooks/useDashboardEditGuard';import { getPanelDefinition } from '../DashboardContainer/Panels/registry';import { buildPluginSpec } from '../DashboardContainer/Panels/utils/buildPluginSpec';import { buildDefaultQueries } from '../DashboardContainer/Panels/utils/buildDefaultQueries';@@ -43,6 +44,9 @@ function PanelEditorPage(): JSX.Element {const { dashboard, isLoading, isError, error } =useDashboardFetch(dashboardId);+ // Derived here (not from the store) because the editor route doesn't mount+ // DashboardContainer, so the store's edit context may be cold on a direct URL.+ const { isEditable, editDisabledReason } = useDashboardEditGuard(dashboard);// Feed variables to the query builder autocomplete inside the editor.useSyncVariablesForSuggestions(dashboard);@@ -114,6 +118,8 @@ function PanelEditorPage(): JSX.Element {panel={panel}isNew={!!newKind}layoutIndex={layoutIndex}+ isEditable={isEditable}+ editDisabledReason={editDisabledReason}onClose={backToDashboard}onSaved={backToDashboard}/>