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:
Levente Balogh 2023-01-11 11:40:21 +01:00 committed by GitHub
parent fc47e0d35e
commit 6b2394eff1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 19 deletions

View File

@ -569,6 +569,19 @@ func (s *ServiceImpl) buildDataConnectionsNavLink(c *models.ReqContext) *navtree
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) {
// Your connections
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 {
// Connections (main)
navLink = &navtree.NavLink{

View File

@ -41,13 +41,14 @@ describe('Connections', () => {
(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();
expect(await screen.findByRole('link', { name: 'Your connections' })).toBeVisible();
expect(await screen.findByText('Manage your existing connections')).toBeVisible();
// Data sources group
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();
});

View File

@ -1,9 +1,10 @@
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 { contextSrv } from 'app/core/core';
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 {
@ -17,6 +18,7 @@ import {
export default function Connections() {
const navIndex = useSelector((state: StoreState) => state.navIndex);
const isConnectDataPageOverriden = Boolean(navIndex['standalone-plugin-page-/connections/connect-data']);
const canAdminPlugins = contextSrv.hasPermission(AccessControlAction.PluginsInstall);
return (
<DataSourcesRoutesContext.Provider
@ -28,7 +30,17 @@ export default function Connections() {
}}
>
<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
exact
path={ROUTES.YourConnections}