({
const Overview = () => {
useNavigationHook(ALL_ROUTER_TYPES.OVERVIEW);
+ const { database } = useContext(databaseContext);
const classes = useStyles();
const theme = useTheme();
const { t: overviewTrans } = useTranslation('overview');
@@ -46,7 +47,7 @@ const Overview = () => {
totalData: 0,
});
const [loading, setLoading] = useState(false);
- const { collections, setCollections } = useContext(webSokcetContext);
+ const { collections, setCollections } = useContext(webSocketContext);
const { openSnackBar } = useContext(rootContext);
const fetchData = useCallback(async () => {
@@ -66,7 +67,7 @@ const Overview = () => {
setStatistics(res);
setCollections(collections);
setLoading(false);
- }, [setCollections]);
+ }, [setCollections, database]);
useEffect(() => {
fetchData();
diff --git a/client/src/pages/search/VectorSearch.tsx b/client/src/pages/search/VectorSearch.tsx
index 2f5c1efe..c56d156c 100644
--- a/client/src/pages/search/VectorSearch.tsx
+++ b/client/src/pages/search/VectorSearch.tsx
@@ -1,24 +1,26 @@
+import { useCallback, useEffect, useMemo, useState, useContext } from 'react';
import { TextField, Typography, Button } from '@material-ui/core';
import { useTranslation } from 'react-i18next';
-import { useNavigationHook } from '@/hooks/Navigation';
+import { useLocation } from 'react-router-dom';
import { ALL_ROUTER_TYPES } from '@/router/Types';
+import { useNavigationHook } from '@/hooks/Navigation';
+import { useSearchResult } from '@/hooks/Result';
+import { usePaginationHook } from '@/hooks/Pagination';
+import { useTimeTravelHook } from '@/hooks/TimeTravel';
+import { databaseContext } from '@/context/Database';
import CustomSelector from '@/components/customSelector/CustomSelector';
-import { useCallback, useEffect, useMemo, useState } from 'react';
-import SearchParams from './SearchParams';
-import { DEFAULT_METRIC_VALUE_MAP } from '../../consts/Milvus';
-import { FieldOption, SearchResultView, VectorSearchParam } from './Types';
+import { ColDefinitionsType } from '@/components/grid/Types';
import AttuGrid from '@/components/grid/Grid';
import EmptyCard from '@/components/cards/EmptyCard';
import icons from '@/components/icons/Icons';
-import { usePaginationHook } from '@/hooks/Pagination';
import CustomButton from '@/components/customButton/CustomButton';
import SimpleMenu from '@/components/menu/SimpleMenu';
-import { TOP_K_OPTIONS } from './Constants';
import { Option } from '@/components/customSelector/Types';
+import Filter from '@/components/advancedSearch';
+import { Field } from '@/components/advancedSearch/Types';
+import { CustomDatePicker } from '@/components/customDatePicker/CustomDatePicker';
import { CollectionHttp } from '@/http/Collection';
-import { CollectionData, DataTypeEnum } from '../collections/Types';
import { IndexHttp } from '@/http/Index';
-import { getVectorSearchStyles } from './Styles';
import { parseValue } from '@/utils/Insert';
import {
classifyFields,
@@ -27,21 +29,21 @@ import {
getNonVectorFieldsForFilter,
getVectorFieldOptions,
} from '@/utils/search';
-import { ColDefinitionsType } from '@/components/grid/Types';
-import Filter from '@/components/advancedSearch';
-import { Field } from '@/components/advancedSearch/Types';
-import { useLocation } from 'react-router-dom';
import { parseLocationSearch } from '@/utils/Format';
import { cloneObj, generateVector } from '@/utils/Common';
-import { CustomDatePicker } from '@/components/customDatePicker/CustomDatePicker';
-import { useTimeTravelHook } from '@/hooks/TimeTravel';
import { LOADING_STATE } from '@/consts/Milvus';
+import { DEFAULT_METRIC_VALUE_MAP } from '@/consts/Milvus';
import { getLabelDisplayedRows } from './Utils';
-import { useSearchResult } from '@/hooks/Result';
+import SearchParams from './SearchParams';
+import { getVectorSearchStyles } from './Styles';
+import { CollectionData, DataTypeEnum } from '../collections/Types';
+import { TOP_K_OPTIONS } from './Constants';
+import { FieldOption, SearchResultView, VectorSearchParam } from './Types';
const VectorSearch = () => {
useNavigationHook(ALL_ROUTER_TYPES.SEARCH);
const location = useLocation();
+ const { database } = useContext(databaseContext);
// i18n
const { t: searchTrans } = useTranslation('search');
@@ -237,7 +239,7 @@ const VectorSearch = () => {
const fetchCollections = useCallback(async () => {
const collections = await CollectionHttp.getCollections();
setCollections(collections.filter(c => c._status === LOADING_STATE.LOADED));
- }, []);
+ }, [database]);
const fetchFieldsWithIndex = useCallback(
async (collectionName: string, collections: CollectionData[]) => {
@@ -260,13 +262,18 @@ const VectorSearch = () => {
const filterFields = getNonVectorFieldsForFilter(nonVectorFields);
setFilterFields(filterFields);
},
- []
+ [collections]
);
useEffect(() => {
fetchCollections();
}, [fetchCollections]);
+ // clear selection if database is changed
+ useEffect(() => {
+ setSelectedCollection('');
+ }, [database]);
+
// get field options with index when selected collection changed
useEffect(() => {
if (selectedCollection !== '') {
diff --git a/client/src/pages/system/SystemView.tsx b/client/src/pages/system/SystemView.tsx
index afd4cf40..c51732a2 100644
--- a/client/src/pages/system/SystemView.tsx
+++ b/client/src/pages/system/SystemView.tsx
@@ -16,7 +16,7 @@ import { parseJson } from '@/utils/Metric';
const getStyles = makeStyles((theme: Theme) => ({
root: {
fontFamily: 'Roboto',
- margin: '14px 40px',
+ margin: '12px 32px',
position: 'relative',
height: 'fit-content',
display: 'flex',
diff --git a/client/src/pages/user/Users.tsx b/client/src/pages/user/Users.tsx
index 109d8422..2fb2222b 100644
--- a/client/src/pages/user/Users.tsx
+++ b/client/src/pages/user/Users.tsx
@@ -1,5 +1,5 @@
import { useMemo } from 'react';
-import { useNavigate, useLocation, useParams } from 'react-router-dom';
+import { useNavigate, useLocation } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { makeStyles, Theme } from '@material-ui/core';
import { useNavigationHook } from '@/hooks/Navigation';
diff --git a/client/src/router/Types.ts b/client/src/router/Types.ts
index f3a413eb..5c4a0436 100644
--- a/client/src/router/Types.ts
+++ b/client/src/router/Types.ts
@@ -18,4 +18,5 @@ export enum ALL_ROUTER_TYPES {
export type NavInfo = {
navTitle: string;
backPath: string;
+ showDatabaseSelector: boolean;
};
diff --git a/server/src/milvus/dto.ts b/server/src/milvus/dto.ts
index 6e943014..84b54bd3 100644
--- a/server/src/milvus/dto.ts
+++ b/server/src/milvus/dto.ts
@@ -10,6 +10,11 @@ export class CheckMilvusDto {
readonly address: string;
}
+export class UseDatabaseDto {
+ @IsString()
+ readonly database: string;
+}
+
export class FlushDto {
@IsArray()
@ArrayMinSize(1, { message: "At least need one collection name." })
diff --git a/server/src/milvus/milvus.controller.ts b/server/src/milvus/milvus.controller.ts
index fae87c2d..16330f9c 100644
--- a/server/src/milvus/milvus.controller.ts
+++ b/server/src/milvus/milvus.controller.ts
@@ -1,7 +1,7 @@
import { NextFunction, Request, Response, Router } from 'express';
import { dtoValidationMiddleware } from '../middlewares/validation';
import { MilvusService } from './milvus.service';
-import { ConnectMilvusDto, FlushDto } from './dto';
+import { ConnectMilvusDto, FlushDto, UseDatabaseDto } from './dto';
import { INSIGHT_CACHE } from '../utils/Const';
import packageJson from '../../package.json';
@@ -25,6 +25,11 @@ export class MilvusController {
dtoValidationMiddleware(ConnectMilvusDto),
this.connectMilvus.bind(this)
);
+ this.router.post(
+ '/usedb',
+ dtoValidationMiddleware(UseDatabaseDto),
+ this.useDatabase.bind(this)
+ );
this.router.post('/disconnect', this.closeConnection.bind(this));
this.router.get('/check', this.checkConnect.bind(this));
this.router.put(
@@ -95,6 +100,17 @@ export class MilvusController {
res.send(data);
}
+ async useDatabase(req: Request, res: Response, next: NextFunction) {
+ const { database } = req.body;
+
+ try {
+ const result = await this.milvusService.useDatabase(database);
+ res.send(result);
+ } catch (error) {
+ next(error);
+ }
+ }
+
closeConnection(req: Request, res: Response, next: NextFunction) {
const result = this.milvusService.closeConnection();
res.send({ result });
diff --git a/server/src/milvus/milvus.service.ts b/server/src/milvus/milvus.service.ts
index 2387860e..fef6b88e 100644
--- a/server/src/milvus/milvus.service.ts
+++ b/server/src/milvus/milvus.service.ts
@@ -101,4 +101,11 @@ export class MilvusService {
const res = MilvusService.activeMilvusClient.closeConnection();
return res;
}
+
+ async useDatabase(db: string) {
+ const res = await MilvusService.activeMilvusClient.use({
+ db_name: db,
+ });
+ return res;
+ }
}