Browse Source

change overview page to ws data

Gitea 3 years ago
parent
commit
3688fb2640
1 changed files with 22 additions and 5 deletions
  1. 22 5
      client/src/pages/overview/Overview.tsx

+ 22 - 5
client/src/pages/overview/Overview.tsx

@@ -3,13 +3,17 @@ import { useCallback, useContext, useEffect, useMemo, useState } from 'react';
 import { useTranslation } from 'react-i18next';
 import { useTranslation } from 'react-i18next';
 import EmptyCard from '../../components/cards/EmptyCard';
 import EmptyCard from '../../components/cards/EmptyCard';
 import icons from '../../components/icons/Icons';
 import icons from '../../components/icons/Icons';
+import { WS_EVENTS, WS_EVENTS_TYPE } from '../../consts/Http';
 import { LOADING_STATE } from '../../consts/Milvus';
 import { LOADING_STATE } from '../../consts/Milvus';
 import { rootContext } from '../../context/Root';
 import { rootContext } from '../../context/Root';
+import { webSokcetContext } from '../../context/WebSocket';
 import { useLoadAndReleaseDialogHook } from '../../hooks/Dialog';
 import { useLoadAndReleaseDialogHook } from '../../hooks/Dialog';
 import { useNavigationHook } from '../../hooks/Navigation';
 import { useNavigationHook } from '../../hooks/Navigation';
 import { CollectionHttp } from '../../http/Collection';
 import { CollectionHttp } from '../../http/Collection';
+import { MilvusHttp } from '../../http/Milvus';
 import { ALL_ROUTER_TYPES } from '../../router/Types';
 import { ALL_ROUTER_TYPES } from '../../router/Types';
 import { formatNumber } from '../../utils/Common';
 import { formatNumber } from '../../utils/Common';
+import { checkLoading, checkIndexBuilding } from '../../utils/Validation';
 import { CollectionData } from '../collections/Types';
 import { CollectionData } from '../collections/Types';
 import CollectionCard from './collectionCard/CollectionCard';
 import CollectionCard from './collectionCard/CollectionCard';
 import StatisticsCard from './statisticsCard/StatisticsCard';
 import StatisticsCard from './statisticsCard/StatisticsCard';
@@ -44,25 +48,38 @@ const Overview = () => {
   });
   });
   const [loading, setLoading] = useState(false);
   const [loading, setLoading] = useState(false);
 
 
-  const [loadCollections, setLoadCollections] = useState<CollectionHttp[]>([]);
+  const { collections, setCollections } = useContext(webSokcetContext);
+
   const { openSnackBar } = useContext(rootContext);
   const { openSnackBar } = useContext(rootContext);
 
 
   const fetchData = useCallback(async () => {
   const fetchData = useCallback(async () => {
     setLoading(true);
     setLoading(true);
     const res = await CollectionHttp.getStatistics();
     const res = await CollectionHttp.getStatistics();
     const collections = await CollectionHttp.getCollections();
     const collections = await CollectionHttp.getCollections();
-    const loadCollections = collections.filter(
-      c => c._status !== LOADING_STATE.UNLOADED
+    const hasLoadingOrBuildingCollection = collections.some(
+      v => checkLoading(v) || checkIndexBuilding(v)
     );
     );
+    // if some collection is building index or loading, start pulling data
+    if (hasLoadingOrBuildingCollection) {
+      MilvusHttp.triggerCron({
+        name: WS_EVENTS.COLLECTION,
+        type: WS_EVENTS_TYPE.START,
+      });
+    }
     setStatistics(res);
     setStatistics(res);
-    setLoadCollections(loadCollections);
+    setCollections(collections);
     setLoading(false);
     setLoading(false);
-  }, []);
+  }, [setCollections]);
 
 
   useEffect(() => {
   useEffect(() => {
     fetchData();
     fetchData();
   }, [fetchData]);
   }, [fetchData]);
 
 
+  const loadCollections = useMemo(
+    () => collections.filter(c => c._status !== LOADING_STATE.UNLOADED),
+    [collections]
+  );
+
   const fetchRelease = async (data: CollectionData) => {
   const fetchRelease = async (data: CollectionData) => {
     const name = data._name;
     const name = data._name;
     const res = await CollectionHttp.releaseCollection(name);
     const res = await CollectionHttp.releaseCollection(name);