From 6899f23a22d15b9025e6dc81736d5facc8958868 Mon Sep 17 00:00:00 2001 From: Giordano Ricci Date: Fri, 22 Apr 2022 09:03:24 +0100 Subject: [PATCH] Explore: prevent direct access to explore if disabled via feature toggle (#47714) * Explore: prevent explore route to be registered if explore is disabled * add feature toggle page --- .../features/explore/FeatureTogglePage.tsx | 30 +++++++++++++++++++ public/app/routes/routes.tsx | 6 +++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 public/app/features/explore/FeatureTogglePage.tsx diff --git a/public/app/features/explore/FeatureTogglePage.tsx b/public/app/features/explore/FeatureTogglePage.tsx new file mode 100644 index 00000000000..71ad80801c6 --- /dev/null +++ b/public/app/features/explore/FeatureTogglePage.tsx @@ -0,0 +1,30 @@ +import React from 'react'; +import Page from 'app/core/components/Page/Page'; +import { css } from '@emotion/css'; +import { useStyles2 } from '@grafana/ui'; +import { GrafanaTheme2 } from '@grafana/data'; + +export default function FeatureTogglePage() { + const styles = useStyles2( + (theme: GrafanaTheme2) => + css` + margin-top: ${theme.spacing(2)}; + ` + ); + + return ( + + +

Explore is disabled

+ To enable Explore, enable it in the Grafana config: +
+
+            {`[explore]
+enable = true
+`}
+          
+
+
+
+ ); +} diff --git a/public/app/routes/routes.tsx b/public/app/routes/routes.tsx index b2e353f71b4..9186b51d2d6 100644 --- a/public/app/routes/routes.tsx +++ b/public/app/routes/routes.tsx @@ -161,7 +161,11 @@ export function getAppRoutes(): RouteDescriptor[] { () => (config.viewersCanEdit ? [] : ['Editor', 'Admin']), [AccessControlAction.DataSourcesExplore] ), - component: SafeDynamicImport(() => import(/* webpackChunkName: "explore" */ 'app/features/explore/Wrapper')), + component: SafeDynamicImport(() => + config.exploreEnabled + ? import(/* webpackChunkName: "explore" */ 'app/features/explore/Wrapper') + : import(/* webpackChunkName: "explore-feature-toggle-page" */ 'app/features/explore/FeatureTogglePage') + ), }, { path: '/a/:pluginId/',