Saved Queries: Hide save button when user is not an editor (#112585)

This commit is contained in:
Ezequiel Victorero
2025-10-20 12:26:49 -03:00
committed by GitHub
parent 8c9624ba5f
commit 02dd1303c9
2 changed files with 3 additions and 3 deletions
@@ -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(
<QueryLibraryContextProviderMock queryLibraryEnabled={true}>
<RichHistoryAddToLibrary query={{ refId: 'A' }} />
@@ -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(
<QueryLibraryContextProviderMock queryLibraryEnabled={true}>
<RichHistoryAddToLibrary query={{ refId: 'A' }} />
@@ -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;
}