Просмотр исходного кода

Implement block if stacks is not enabled for the project

jnfrati 3 лет назад
Родитель
Сommit
19d552698c

+ 14 - 2
dashboard/src/main/home/cluster-dashboard/stacks/routes.tsx

@@ -1,11 +1,23 @@
-import React from "react";
-import { Route, Switch, useLocation, useRouteMatch } from "react-router";
+import React, { useContext } from "react";
+import {
+  Redirect,
+  Route,
+  Switch,
+  useLocation,
+  useRouteMatch,
+} from "react-router";
+import { Context } from "shared/Context";
 import Dashboard from "./Dashboard";
 import ExpandedStack from "./ExpandedStack";
 import LaunchRoutes from "./launch";
 
 const routes = () => {
   const { path } = useRouteMatch();
+  const { currentProject } = useContext(Context);
+
+  if (!currentProject?.stacks_enabled) {
+    return <Redirect to={`/`} />;
+  }
 
   return (
     <Switch>

+ 6 - 4
dashboard/src/main/home/sidebar/Sidebar.tsx

@@ -223,10 +223,12 @@ class Sidebar extends Component<PropsType, StateType> {
               </EllipsisTextWrapper>
             </NavButton>
           )}
-          <NavButton to="/stacks">
-            <Icon className="material-icons-outlined">lan</Icon>
-            Stacks
-          </NavButton>
+          {currentProject?.stacks_enabled ? (
+            <NavButton to="/stacks">
+              <Icon className="material-icons-outlined">lan</Icon>
+              Stacks
+            </NavButton>
+          ) : null}
         </>
       );
     }

+ 1 - 0
dashboard/src/shared/types.tsx

@@ -258,6 +258,7 @@ export interface ProjectType {
   enable_rds_databases: boolean;
   managed_infra_enabled: boolean;
   api_tokens_enabled: boolean;
+  stacks_enabled: boolean;
   roles: {
     id: number;
     kind: string;