浏览代码

Implemented null casing.

Added null casing to the SidebarLink to check if the properties that are going
to be added to the search params actually exists and we're not trying to access
empty objects.
jnfrati 4 年之前
父节点
当前提交
1d90119569
共有 1 个文件被更改,包括 10 次插入 和 3 次删除
  1. 10 3
      dashboard/src/main/home/sidebar/SidebarLink.tsx

+ 10 - 3
dashboard/src/main/home/sidebar/SidebarLink.tsx

@@ -18,20 +18,27 @@ const SidebarLink: React.FC<{ path: string } & Omit<NavLinkProps, "to">> = ({
    */
    */
   const withQueryParams = (path: string) => (location: any) => {
   const withQueryParams = (path: string) => (location: any) => {
     let pathNamespace = params.namespace;
     let pathNamespace = params.namespace;
-    let search = `?cluster=${currentCluster.name}&project_id=${currentProject.id}`;
+    const search = new URLSearchParams();
+    if (currentCluster?.name) {
+      search.append("cluster", currentCluster.name);
+    }
+
+    if (currentProject?.id) {
+      search.append("project_id", String(currentProject.id));
+    }
 
 
     if (!pathNamespace) {
     if (!pathNamespace) {
       pathNamespace = getQueryParam("namespace");
       pathNamespace = getQueryParam("namespace");
     }
     }
 
 
     if (pathNamespace) {
     if (pathNamespace) {
-      search = search.concat(`&namespace=${pathNamespace}`);
+      search.append("namespace", pathNamespace);
     }
     }
 
 
     return {
     return {
       ...location,
       ...location,
       pathname: path,
       pathname: path,
-      search,
+      search: search.toString(),
     };
     };
   };
   };