From 02dd1303c90187e17a5e9d74c553feaeaaf8a249 Mon Sep 17 00:00:00 2001 From: Ezequiel Victorero Date: Mon, 20 Oct 2025 12:26:49 -0300 Subject: [PATCH] Saved Queries: Hide save button when user is not an editor (#112585) --- .../explore/RichHistory/RichHistoryAddToLibrary.test.tsx | 4 ++-- .../features/explore/RichHistory/RichHistoryAddToLibrary.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/public/app/features/explore/RichHistory/RichHistoryAddToLibrary.test.tsx b/public/app/features/explore/RichHistory/RichHistoryAddToLibrary.test.tsx index 486391fec2e..b23434fd2a6 100644 --- a/public/app/features/explore/RichHistory/RichHistoryAddToLibrary.test.tsx +++ b/public/app/features/explore/RichHistory/RichHistoryAddToLibrary.test.tsx @@ -1,7 +1,6 @@ import { screen } from '@testing-library/react'; import { render } from 'test/test-utils'; -import { OrgRole } from '@grafana/data'; import { contextSrv } from 'app/core/core'; import { QueryLibraryContextProviderMock } from '../QueryLibrary/mocks'; @@ -10,6 +9,7 @@ import { RichHistoryAddToLibrary } from './RichHistoryAddToLibrary'; describe('RichHistoryAddToLibrary', () => { it('should render button when save query is enabled', () => { + contextSrv.isEditor = true; render( @@ -28,7 +28,7 @@ describe('RichHistoryAddToLibrary', () => { expect(screen.queryByRole('button', { name: /Save query/i })).not.toBeInTheDocument(); }); it('should not render button when user has Viewer role', () => { - contextSrv.user.orgRole = OrgRole.Viewer; + contextSrv.isEditor = false; render( diff --git a/public/app/features/explore/RichHistory/RichHistoryAddToLibrary.tsx b/public/app/features/explore/RichHistory/RichHistoryAddToLibrary.tsx index c89764d4aae..1165e71ff42 100644 --- a/public/app/features/explore/RichHistory/RichHistoryAddToLibrary.tsx +++ b/public/app/features/explore/RichHistory/RichHistoryAddToLibrary.tsx @@ -31,7 +31,7 @@ export const RichHistoryAddToLibrary = ({ query }: Props) => { const buttonLabel = t('explore.rich-history-card.add-to-library', 'Save query'); - if (contextSrv.hasRole('Viewer')) { + if (!contextSrv.isEditor) { return null; }