mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Connections: Make "Connect data" a section title (#61144)
* Wip * Fix: change tests to cater for the new scenario * feat(Connections): redirect to "Your connections / Datasources" if cannot admin plugins
This commit is contained in:
parent
fc47e0d35e
commit
6b2394eff1
@ -569,6 +569,19 @@ func (s *ServiceImpl) buildDataConnectionsNavLink(c *models.ReqContext) *navtree
|
|||||||
|
|
||||||
baseUrl := s.cfg.AppSubURL + "/connections"
|
baseUrl := s.cfg.AppSubURL + "/connections"
|
||||||
|
|
||||||
|
// Connect data
|
||||||
|
// FIXME: while we don't have a permissions for listing plugins the legacy check has to stay as a default
|
||||||
|
if plugins.ReqCanAdminPlugins(s.cfg)(c) || hasAccess(plugins.ReqCanAdminPlugins(s.cfg), plugins.AdminAccessEvaluator) {
|
||||||
|
children = append(children, &navtree.NavLink{
|
||||||
|
Id: "connections-connect-data",
|
||||||
|
Text: "Connect data",
|
||||||
|
SubTitle: "Browse and create new connections",
|
||||||
|
IsSection: true,
|
||||||
|
Url: s.cfg.AppSubURL + "/connections/connect-data",
|
||||||
|
Children: []*navtree.NavLink{},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if hasAccess(ac.ReqOrgAdmin, datasources.ConfigurationPageAccess) {
|
if hasAccess(ac.ReqOrgAdmin, datasources.ConfigurationPageAccess) {
|
||||||
// Your connections
|
// Your connections
|
||||||
children = append(children, &navtree.NavLink{
|
children = append(children, &navtree.NavLink{
|
||||||
@ -586,18 +599,6 @@ func (s *ServiceImpl) buildDataConnectionsNavLink(c *models.ReqContext) *navtree
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect data
|
|
||||||
// FIXME: while we don't have a permissions for listing plugins the legacy check has to stay as a default
|
|
||||||
if plugins.ReqCanAdminPlugins(s.cfg)(c) || hasAccess(plugins.ReqCanAdminPlugins(s.cfg), plugins.AdminAccessEvaluator) {
|
|
||||||
children = append(children, &navtree.NavLink{
|
|
||||||
Id: "connections-connect-data",
|
|
||||||
Text: "Connect data",
|
|
||||||
SubTitle: "Browse and create new connections",
|
|
||||||
Url: s.cfg.AppSubURL + "/connections/connect-data",
|
|
||||||
Children: []*navtree.NavLink{},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(children) > 0 {
|
if len(children) > 0 {
|
||||||
// Connections (main)
|
// Connections (main)
|
||||||
navLink = &navtree.NavLink{
|
navLink = &navtree.NavLink{
|
||||||
|
@ -41,13 +41,14 @@ describe('Connections', () => {
|
|||||||
(contextSrv.hasPermission as jest.Mock) = jest.fn().mockReturnValue(true);
|
(contextSrv.hasPermission as jest.Mock) = jest.fn().mockReturnValue(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('shows a landing page by default', async () => {
|
test('shows the "Connect data" page by default', async () => {
|
||||||
renderPage();
|
renderPage();
|
||||||
|
|
||||||
expect(await screen.findByRole('link', { name: 'Your connections' })).toBeVisible();
|
// Data sources group
|
||||||
expect(await screen.findByText('Manage your existing connections')).toBeVisible();
|
expect(await screen.findByText('Data sources')).toBeVisible();
|
||||||
|
|
||||||
expect(await screen.findByRole('link', { name: 'Connect data' })).toBeVisible();
|
// Heading
|
||||||
|
expect(await screen.findByText('Connect data')).toBeVisible();
|
||||||
expect(await screen.findByText('Browse and create new connections')).toBeVisible();
|
expect(await screen.findByText('Browse and create new connections')).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { Route, Switch } from 'react-router-dom';
|
import { Redirect, Route, Switch } from 'react-router-dom';
|
||||||
|
|
||||||
import { NavLandingPage } from 'app/core/components/AppChrome/NavLandingPage';
|
import { NavLandingPage } from 'app/core/components/AppChrome/NavLandingPage';
|
||||||
|
import { contextSrv } from 'app/core/core';
|
||||||
import { DataSourcesRoutesContext } from 'app/features/datasources/state';
|
import { DataSourcesRoutesContext } from 'app/features/datasources/state';
|
||||||
import { StoreState, useSelector } from 'app/types';
|
import { AccessControlAction, StoreState, useSelector } from 'app/types';
|
||||||
|
|
||||||
import { ROUTES } from './constants';
|
import { ROUTES } from './constants';
|
||||||
import {
|
import {
|
||||||
@ -17,6 +18,7 @@ import {
|
|||||||
export default function Connections() {
|
export default function Connections() {
|
||||||
const navIndex = useSelector((state: StoreState) => state.navIndex);
|
const navIndex = useSelector((state: StoreState) => state.navIndex);
|
||||||
const isConnectDataPageOverriden = Boolean(navIndex['standalone-plugin-page-/connections/connect-data']);
|
const isConnectDataPageOverriden = Boolean(navIndex['standalone-plugin-page-/connections/connect-data']);
|
||||||
|
const canAdminPlugins = contextSrv.hasPermission(AccessControlAction.PluginsInstall);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataSourcesRoutesContext.Provider
|
<DataSourcesRoutesContext.Provider
|
||||||
@ -28,7 +30,17 @@ export default function Connections() {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route exact path={ROUTES.Base} component={() => <NavLandingPage navId="connections" />} />
|
<Route
|
||||||
|
exact
|
||||||
|
path={ROUTES.Base}
|
||||||
|
component={() => {
|
||||||
|
if (canAdminPlugins) {
|
||||||
|
return <Redirect to={ROUTES.ConnectData} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Redirect to={ROUTES.DataSources} />;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<Route
|
<Route
|
||||||
exact
|
exact
|
||||||
path={ROUTES.YourConnections}
|
path={ROUTES.YourConnections}
|
||||||
|
Loading…
Reference in New Issue
Block a user