Преглед изворни кода

routing for clusters with unspecified handling

jusrhee пре 5 година
родитељ
комит
bfc5c408d5

+ 5 - 3
dashboard/src/main/home/cluster-dashboard/ClusterDashboard.tsx

@@ -5,7 +5,7 @@ import monoweb from "assets/monoweb.png";
 
 
 import { Context } from "shared/Context";
 import { Context } from "shared/Context";
 import { ChartType, ClusterType, ProjectType } from "shared/types";
 import { ChartType, ClusterType, ProjectType } from "shared/types";
-import { PorterUrl, pushFiltered } from "shared/routing";
+import { PorterUrl, pushFiltered, pushQueryParams } from "shared/routing";
 
 
 import ChartList from "./chart/ChartList";
 import ChartList from "./chart/ChartList";
 import EnvGroupDashboard from "./env-groups/EnvGroupDashboard";
 import EnvGroupDashboard from "./env-groups/EnvGroupDashboard";
@@ -42,14 +42,16 @@ class ClusterDashboard extends Component<PropsType, StateType> {
   };
   };
 
 
   componentDidMount() {
   componentDidMount() {
+    let { currentCluster, currentProject } = this.context;
+    pushQueryParams(this.props, { cluster: currentCluster.name });
     api
     api
       .getPrometheusIsInstalled(
       .getPrometheusIsInstalled(
         "<token>",
         "<token>",
         {
         {
-          cluster_id: this.context.currentCluster.id,
+          cluster_id: currentCluster.id,
         },
         },
         {
         {
-          id: this.context.currentProject.id,
+          id: currentProject.id,
         }
         }
       )
       )
       .then((res) => {
       .then((res) => {

+ 17 - 3
dashboard/src/main/home/sidebar/ClusterSection.tsx

@@ -38,7 +38,7 @@ class ClusterSection extends Component<PropsType, StateType> {
   };
   };
 
 
   updateClusters = () => {
   updateClusters = () => {
-    let { user, currentProject, setCurrentCluster } = this.context;
+    let { user, currentProject, setCurrentCluster, currentCluster } = this.context;
 
 
     // TODO: query with selected filter once implemented
     // TODO: query with selected filter once implemented
     api
     api
@@ -55,11 +55,25 @@ class ClusterSection extends Component<PropsType, StateType> {
           let clusters = res.data;
           let clusters = res.data;
           clusters.sort((a: any, b: any) => a.id - b.id);
           clusters.sort((a: any, b: any) => a.id - b.id);
           if (clusters.length > 0) {
           if (clusters.length > 0) {
+
+            // Set cluster from URL if specified
+            let queryString = window.location.search;
+            let urlParams = new URLSearchParams(queryString);
+            let clusterName = urlParams.get("cluster");
+            let defaultCluster = null;
+            if (clusterName) {
+              clusters.forEach((cluster: ClusterType) => {
+                if (cluster.name === clusterName) {
+                  defaultCluster = cluster;
+                }
+              })
+            }
+
             this.setState({ clusters });
             this.setState({ clusters });
             let saved = JSON.parse(
             let saved = JSON.parse(
               localStorage.getItem(currentProject.id + "-cluster")
               localStorage.getItem(currentProject.id + "-cluster")
             );
             );
-            if (saved && saved !== "null") {
+            if (!defaultCluster && saved && saved !== "null") {
               // Ensures currentCluster isn't prematurely set (causes issues downstream)
               // Ensures currentCluster isn't prematurely set (causes issues downstream)
               let loaded = false;
               let loaded = false;
               for (let i = 0; i < clusters.length; i++) {
               for (let i = 0; i < clusters.length; i++) {
@@ -77,7 +91,7 @@ class ClusterSection extends Component<PropsType, StateType> {
                 setCurrentCluster(clusters[0]);
                 setCurrentCluster(clusters[0]);
               }
               }
             } else {
             } else {
-              setCurrentCluster(clusters[0]);
+              setCurrentCluster(defaultCluster || clusters[0]);
             }
             }
           } else if (
           } else if (
             this.props.currentView !== "provisioner" &&
             this.props.currentView !== "provisioner" &&