2023-08-21 15:58:02 +02:00
|
|
|
import { Redirect, Route, Switch, useLocation } from 'react-router-dom';
|
2022-11-10 11:14:23 +01:00
|
|
|
|
|
|
|
|
import { DataSourcesRoutesContext } from 'app/features/datasources/state';
|
2023-01-18 15:34:23 +01:00
|
|
|
import { StoreState, useSelector } from 'app/types';
|
2022-11-10 11:14:23 +01:00
|
|
|
|
|
|
|
|
import { ROUTES } from './constants';
|
|
|
|
|
import {
|
2023-05-02 10:51:59 +02:00
|
|
|
AddNewConnectionPage,
|
2023-01-23 13:25:42 +01:00
|
|
|
DataSourceDashboardsPage,
|
2022-11-10 11:14:23 +01:00
|
|
|
DataSourceDetailsPage,
|
|
|
|
|
DataSourcesListPage,
|
|
|
|
|
EditDataSourcePage,
|
|
|
|
|
NewDataSourcePage,
|
|
|
|
|
} from './pages';
|
|
|
|
|
|
2023-08-21 15:58:02 +02:00
|
|
|
function RedirectToAddNewConnection() {
|
|
|
|
|
const { search } = useLocation();
|
|
|
|
|
return (
|
|
|
|
|
<Redirect
|
|
|
|
|
to={{
|
|
|
|
|
pathname: ROUTES.AddNewConnection,
|
|
|
|
|
search,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-10 11:14:23 +01:00
|
|
|
export default function Connections() {
|
|
|
|
|
const navIndex = useSelector((state: StoreState) => state.navIndex);
|
2023-05-02 10:51:59 +02:00
|
|
|
const isAddNewConnectionPageOverridden = Boolean(navIndex['standalone-plugin-page-/connections/add-new-connection']);
|
2023-03-01 08:23:08 +01:00
|
|
|
|
2022-11-10 11:14:23 +01:00
|
|
|
return (
|
|
|
|
|
<DataSourcesRoutesContext.Provider
|
|
|
|
|
value={{
|
|
|
|
|
New: ROUTES.DataSourcesNew,
|
|
|
|
|
List: ROUTES.DataSources,
|
|
|
|
|
Edit: ROUTES.DataSourcesEdit,
|
|
|
|
|
Dashboards: ROUTES.DataSourcesDashboards,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Switch>
|
2023-05-02 10:51:59 +02:00
|
|
|
{/* Redirect to "Add new connection" by default */}
|
|
|
|
|
<Route exact sensitive path={ROUTES.Base} component={() => <Redirect to={ROUTES.AddNewConnection} />} />
|
2023-02-03 09:00:30 +01:00
|
|
|
<Route exact sensitive path={ROUTES.DataSources} component={DataSourcesListPage} />
|
|
|
|
|
<Route exact sensitive path={ROUTES.DataSourcesNew} component={NewDataSourcePage} />
|
2023-05-04 12:37:14 +02:00
|
|
|
<Route exact sensitive path={ROUTES.DataSourcesDetails} component={DataSourceDetailsPage} />
|
2023-02-03 09:00:30 +01:00
|
|
|
<Route exact sensitive path={ROUTES.DataSourcesEdit} component={EditDataSourcePage} />
|
|
|
|
|
<Route exact sensitive path={ROUTES.DataSourcesDashboards} component={DataSourceDashboardsPage} />
|
2022-11-10 11:14:23 +01:00
|
|
|
|
2023-05-02 10:51:59 +02:00
|
|
|
{/* "Add new connection" page - we don't register a route in case a plugin already registers a standalone page for it */}
|
|
|
|
|
{!isAddNewConnectionPageOverridden && (
|
|
|
|
|
<Route exact sensitive path={ROUTES.AddNewConnection} component={AddNewConnectionPage} />
|
|
|
|
|
)}
|
2023-02-03 09:00:30 +01:00
|
|
|
|
2023-08-21 15:58:02 +02:00
|
|
|
{/* Redirect from earlier routes to updated routes */}
|
|
|
|
|
<Route exact path={ROUTES.ConnectDataOutdated} component={RedirectToAddNewConnection} />
|
|
|
|
|
<Redirect from={`${ROUTES.Base}/your-connections/:page`} to={`${ROUTES.Base}/:page`} />
|
|
|
|
|
<Redirect from={ROUTES.YourConnectionsOutdated} to={ROUTES.DataSources} />
|
|
|
|
|
|
2023-02-03 09:00:30 +01:00
|
|
|
{/* Not found */}
|
|
|
|
|
<Route component={() => <Redirect to="/notfound" />} />
|
2022-11-10 11:14:23 +01:00
|
|
|
</Switch>
|
|
|
|
|
</DataSourcesRoutesContext.Provider>
|
|
|
|
|
);
|
|
|
|
|
}
|