Browse Source

change vector route param and fix menu active status

tumao 4 years ago
parent
commit
cf61ca6168

+ 7 - 1
client/src/components/menu/NavMenu.tsx

@@ -1,4 +1,4 @@
-import { useState, FC } from 'react';
+import { useState, FC, useEffect } from 'react';
 import { makeStyles, Theme, createStyles } from '@material-ui/core/styles';
 import { makeStyles, Theme, createStyles } from '@material-ui/core/styles';
 import List from '@material-ui/core/List';
 import List from '@material-ui/core/List';
 import ListItem from '@material-ui/core/ListItem';
 import ListItem from '@material-ui/core/ListItem';
@@ -97,6 +97,12 @@ const NavMenu: FC<NavMenuType> = props => {
     }));
     }));
   };
   };
 
 
+  useEffect(() => {
+    if (defaultActive) {
+      setActive(defaultActive);
+    }
+  }, [defaultActive]);
+
   const NestList = (props: { data: NavMenuItem[]; className?: string }) => {
   const NestList = (props: { data: NavMenuItem[]; className?: string }) => {
     const { className, data } = props;
     const { className, data } = props;
     return (
     return (

+ 1 - 1
client/src/pages/overview/collectionCard/CollectionCard.tsx

@@ -89,7 +89,7 @@ const CollectionCard: FC<CollectionCardProps> = ({
   };
   };
 
 
   const onVectorSearchClick = () => {
   const onVectorSearchClick = () => {
-    history.push(`/search/${name}`);
+    history.push({ pathname: '/search', search: `?collectionName=${name}` });
   };
   };
 
 
   return (
   return (

+ 7 - 7
client/src/pages/seach/VectorSearch.tsx

@@ -31,13 +31,12 @@ import {
 import { ColDefinitionsType } from '../../components/grid/Types';
 import { ColDefinitionsType } from '../../components/grid/Types';
 import Filter from '../../components/advancedSearch';
 import Filter from '../../components/advancedSearch';
 import { Field } from '../../components/advancedSearch/Types';
 import { Field } from '../../components/advancedSearch/Types';
-import { useParams } from 'react-router-dom';
+import { useLocation } from 'react-router-dom';
+import { parseLocationSearch } from '../../utils/Format';
 
 
 const VectorSearch = () => {
 const VectorSearch = () => {
   useNavigationHook(ALL_ROUTER_TYPES.SEARCH);
   useNavigationHook(ALL_ROUTER_TYPES.SEARCH);
-  const { collectionName = '' } = useParams<{
-    collectionName: string;
-  }>();
+  const location = useLocation();
 
 
   // i18n
   // i18n
   const { t: searchTrans } = useTranslation('search');
   const { t: searchTrans } = useTranslation('search');
@@ -191,12 +190,13 @@ const VectorSearch = () => {
     }
     }
   }, [selectedCollection, collections, fetchFieldsWithIndex]);
   }, [selectedCollection, collections, fetchFieldsWithIndex]);
 
 
-  // set collection value if is from overview page
+  // set default collection value if is from overview page
   useEffect(() => {
   useEffect(() => {
-    if (collectionName) {
+    if (location.search && collections.length > 0) {
+      const { collectionName } = parseLocationSearch(location.search);
       setSelectedCollection(collectionName);
       setSelectedCollection(collectionName);
     }
     }
-  }, [collectionName]);
+  }, [location, collections]);
 
 
   // icons
   // icons
   const VectorSearchIcon = icons.vectorSearch;
   const VectorSearchIcon = icons.vectorSearch;

+ 0 - 5
client/src/router/Config.ts

@@ -31,11 +31,6 @@ const RouterConfig: RouterConfigType[] = [
     component: VectorSearch,
     component: VectorSearch,
     auth: true,
     auth: true,
   },
   },
-  {
-    path: '/search/:collectionName',
-    component: VectorSearch,
-    auth: true,
-  },
 ];
 ];
 
 
 export default RouterConfig;
 export default RouterConfig;