mirror of
https://github.com/grafana/grafana.git
synced 2025-01-15 19:22:34 -06:00
Data sources: Hide the datasource redirection banner for users who can't interact with data sources (#92886)
* hide the datasource redirection banner for users who can't list data sources * readding explore evaluation * add a test
This commit is contained in:
parent
6548ea377d
commit
ba9f1da28e
@ -0,0 +1,23 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
|
||||
import { contextSrv } from '../../../../core/services/context_srv';
|
||||
|
||||
import { ConnectionsRedirectNotice } from './ConnectionsRedirectNotice';
|
||||
|
||||
const setup = (hasAccessToDS: boolean) => {
|
||||
jest.spyOn(contextSrv, 'hasPermission').mockReturnValue(hasAccessToDS);
|
||||
|
||||
render(<ConnectionsRedirectNotice />);
|
||||
};
|
||||
|
||||
describe('ConnectionsRedirectNotice', () => {
|
||||
it('should render component when has access to data sources', () => {
|
||||
setup(true);
|
||||
expect(screen.getByRole('link')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should not render component when has no access to data sources', () => {
|
||||
setup(false);
|
||||
expect(screen.queryByRole('link')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
@ -4,6 +4,8 @@ import { useState } from 'react';
|
||||
import { GrafanaTheme2 } from '@grafana/data';
|
||||
import { Alert, LinkButton, useStyles2 } from '@grafana/ui';
|
||||
|
||||
import { contextSrv } from '../../../../core/core';
|
||||
import { AccessControlAction } from '../../../../types';
|
||||
import { ROUTES } from '../../constants';
|
||||
|
||||
const getStyles = (theme: GrafanaTheme2) => ({
|
||||
@ -22,7 +24,10 @@ const getStyles = (theme: GrafanaTheme2) => ({
|
||||
|
||||
export function ConnectionsRedirectNotice() {
|
||||
const styles = useStyles2(getStyles);
|
||||
const [showNotice, setShowNotice] = useState(true);
|
||||
const canAccessDataSources =
|
||||
contextSrv.hasPermission(AccessControlAction.DataSourcesCreate) ||
|
||||
contextSrv.hasPermission(AccessControlAction.DataSourcesWrite);
|
||||
const [showNotice, setShowNotice] = useState(canAccessDataSources);
|
||||
|
||||
return showNotice ? (
|
||||
<Alert severity="info" title="" onRemove={() => setShowNotice(false)}>
|
||||
|
Loading…
Reference in New Issue
Block a user