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

Merge branch 'nafees/preview-apps-initial-cli' of https://github.com/porter-dev/porter into nafees/preview-apps-initial-cli

Alexander Belanger 4 лет назад
Родитель
Сommit
168220baf9

+ 12 - 2
dashboard/src/main/home/cluster-dashboard/dashboard/Dashboard.tsx

@@ -37,7 +37,10 @@ const tabOptions: {
 ];
 
 export const Dashboard: React.FunctionComponent = () => {
-  const [currentTab, setCurrentTab] = useState<TabEnum>("preview_environments");
+  const { currentProject } = useContext(Context);
+  const [currentTab, setCurrentTab] = useState<TabEnum>(() =>
+    currentProject.preview_envs_enabled ? "preview_environments" : "nodes"
+  );
   const [currentTabOptions, setCurrentTabOptions] = useState(tabOptions);
   const [isAuthorized] = useAuth();
   const location = useLocation();
@@ -46,7 +49,10 @@ export const Dashboard: React.FunctionComponent = () => {
   const renderTab = () => {
     switch (currentTab) {
       case "preview_environments":
-        return <EnvironmentList />;
+        if (currentProject.preview_envs_enabled) {
+          return <EnvironmentList />;
+        }
+        return <NodeList />;
       case "events":
         return <EventsTab />;
       case "settings":
@@ -64,6 +70,10 @@ export const Dashboard: React.FunctionComponent = () => {
   useEffect(() => {
     setCurrentTabOptions(
       tabOptions.filter((option) => {
+        if (option.value === "preview_environments") {
+          return currentProject.preview_envs_enabled;
+        }
+
         if (option.value === "settings") {
           return isAuthorized("cluster", "", ["get", "delete"]);
         }

+ 13 - 5
dashboard/src/main/home/cluster-dashboard/dashboard/Routes.tsx

@@ -1,20 +1,28 @@
-import React from "react";
-import { Route, Switch, useRouteMatch } from "react-router";
+import React, { useContext } from "react";
+import { Redirect, Route, Switch, useRouteMatch } from "react-router";
+import { Context } from "shared/Context";
 import { Dashboard } from "./Dashboard";
 import ExpandedNodeView from "./node-view/ExpandedNodeView";
 import EnvironmentDetail from "./preview-environments/EnvironmentDetail";
 
 export const Routes = () => {
   const { url } = useRouteMatch();
+  const { currentProject } = useContext(Context);
   return (
     <>
       <Switch>
         <Route path={`${url}/node-view/:nodeId`}>
           <ExpandedNodeView />
         </Route>
-        <Route path={`${url}/pr-env-detail/:namespace`}>
-          <EnvironmentDetail />
-        </Route>
+        <Route
+          path={`${url}/pr-env-detail/:namespace`}
+          render={() => {
+            if (currentProject.preview_envs_enabled) {
+              return <EnvironmentDetail />;
+            }
+            return <Redirect to={`${url}/`} />;
+          }}
+        ></Route>
         <Route path={`${url}/`}>
           <Dashboard />
         </Route>

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

@@ -217,6 +217,7 @@ export interface FileType {
 export interface ProjectType {
   id: number;
   name: string;
+  preview_envs_enabled: boolean;
   roles: {
     id: number;
     kind: string;