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
3 changed files with 33 additions and 19 deletions

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}