Skip to content

Commit

Permalink
- support create index on collections page
Browse files Browse the repository at this point in the history
- code refactor

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
  • Loading branch information
shanghaikid committed Dec 7, 2023
1 parent ae4c482 commit 4727d5d
Show file tree
Hide file tree
Showing 73 changed files with 866 additions and 812 deletions.
6 changes: 3 additions & 3 deletions client/src/components/customSelector/Types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { FormControlClassKey, SelectProps } from '@material-ui/core';
import { ClassNameMap } from '@material-ui/core/styles/withStyles';

export interface Option {
label: string;
value: string | number;
export interface Option<T = string, U = string | number> {
label: T;
value: U;
}

export interface GroupOption {
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import AccountCircleIcon from '@material-ui/icons/AccountCircle';
import { useNavigate } from 'react-router-dom';
import { navContext, dataContext, authContext } from '@/context';
import { MilvusHttp } from '@/http';
import { MilvusService } from '@/http';
import { MILVUS_ADDRESS, LOGIN_USERNAME } from '@/consts';
import CustomSelector from '@/components/customSelector/CustomSelector';
import icons from '../icons/Icons';
Expand Down Expand Up @@ -90,15 +90,15 @@ const Header: FC<HeaderType> = props => {
setAddress('');
setUsername('');
setIsAuth(false);
await MilvusHttp.closeConnection();
await MilvusService.closeConnection();
window.localStorage.removeItem(MILVUS_ADDRESS);
window.localStorage.removeItem(LOGIN_USERNAME);
// make sure we clear state in all pages
// navigate(0);
};

const useDatabase = async (database: string) => {
await MilvusHttp.useDatabase({ database });
await MilvusService.useDatabase({ database });
};

const dbOptions = databases.map(d => ({ value: d, label: d }));
Expand Down
15 changes: 10 additions & 5 deletions client/src/components/status/Types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { LOADING_STATE } from '@/consts';
import { FieldHttp } from '@/http';

// export enum StatusEnum {
// 'unloaded',
// 'loaded',
// 'error',
// }
export type StatusType = {
status: LOADING_STATE;
percentage?: string;
};

export type StatusActionType = {
status: LOADING_STATE;
percentage?: string;
action?: Function;
field: FieldHttp;
collectionName: string;
onIndexCreate: Function;
};

// @todo need rename
export enum ChildrenStatusType {
CREATING = 'creating',
Expand Down
4 changes: 2 additions & 2 deletions client/src/context/Auth.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createContext, useEffect, useState } from 'react';
import { MILVUS_ADDRESS, LOGIN_USERNAME } from '@/consts';
import { MilvusHttp } from '@/http';
import { MilvusService } from '@/http';
import { AuthContextType } from './Types';

export const authContext = createContext<AuthContextType>({
Expand Down Expand Up @@ -33,7 +33,7 @@ export const AuthProvider = (props: { children: React.ReactNode }) => {
if (!milvusAddress) {
return;
}
const res = await MilvusHttp.check(milvusAddress);
const res = await MilvusService.check(milvusAddress);
setAddress(res.connected ? milvusAddress : '');
res.connected && setIsAuth(true);
if (!res.connected) {
Expand Down
10 changes: 5 additions & 5 deletions client/src/context/Data.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext, useEffect, useState, useContext } from 'react';
import { DatabaseHttp, UserHttp, MilvusHttp } from '@/http';
import { Database, User, MilvusService } from '@/http';
import { parseJson, getNode, getSystemConfigs } from '@/utils';
import { MILVUS_NODE_TYPE } from '@/consts';
import { authContext } from '@/context';
Expand All @@ -24,10 +24,10 @@ export const DataProvider = (props: { children: React.ReactNode }) => {
try {
// fetch all data
const [databases, metrics, users, roles] = await Promise.all([
DatabaseHttp.getDatabases(),
MilvusHttp.getMetrics(),
UserHttp.getUsers(),
UserHttp.getRoles(),
Database.getDatabases(),
MilvusService.getMetrics(),
User.getUsers(),
User.getRoles(),
]);

// parse data
Expand Down
4 changes: 2 additions & 2 deletions client/src/context/Prometheus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
WITH_PROMETHEUS,
} from '@/consts';
import { formatPrometheusAddress } from '@/utils';
import { PrometheusHttp } from '@/http';
import { PrometheusService } from '@/http';

export const prometheusContext = createContext<PrometheusContextType>({
withPrometheus: false,
Expand Down Expand Up @@ -59,7 +59,7 @@ export const PrometheusProvider = (props: { children: React.ReactNode }) => {
if (withPrometheus) {
const prometheusAddressformat =
formatPrometheusAddress(prometheusAddress);
PrometheusHttp.setPrometheus({
PrometheusService.setPrometheus({
prometheusAddress: prometheusAddressformat,
prometheusInstance,
prometheusNamespace,
Expand Down
4 changes: 2 additions & 2 deletions client/src/context/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from './Types';
import CustomSnackBar from '@/components/customSnackBar/CustomSnackBar';
import CustomDialog from '@/components/customDialog/CustomDialog';
import { MilvusHttp } from '@/http';
import { MilvusService } from '@/http';
import { theme } from '../styles/theme';

const DefaultDialogConfigs: DialogType = {
Expand Down Expand Up @@ -115,7 +115,7 @@ export const RootProvider = (props: { children: React.ReactNode }) => {
useEffect(() => {
if (isAuth) {
const fetchVersion = async () => {
const res = await MilvusHttp.getVersion();
const res = await MilvusService.getVersion();
setVersionInfo(res);
};
fetchVersion();
Expand Down
6 changes: 3 additions & 3 deletions client/src/context/Types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Dispatch, ReactElement, SetStateAction } from 'react';
import { CollectionView } from '@/pages/collections/Types';
import { Collection } from '@/http';
import { NavInfo } from '@/router/Types';

export type RootContextType = {
Expand Down Expand Up @@ -90,6 +90,6 @@ export type NavContextType = {
};

export type WebSocketType = {
collections: CollectionView[];
setCollections: (data: CollectionView[]) => void;
collections: Collection[];
setCollections: (data: Collection[]) => void;
};
13 changes: 6 additions & 7 deletions client/src/context/WebSocket.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { createContext, useContext, useEffect, useState, useRef } from 'react';
import { io, Socket } from 'socket.io-client';
import { authContext } from '@/context';
import { url, CollectionHttp, MilvusHttp } from '@/http';
import { CollectionView } from '@/pages/collections/Types';
import { url, Collection, MilvusService } from '@/http';
import { checkIndexBuilding, checkLoading } from '@/utils';
import { WebSocketType } from './Types';
import { WS_EVENTS, WS_EVENTS_TYPE } from '@server/utils/Const';
Expand All @@ -15,13 +14,13 @@ export const webSocketContext = createContext<WebSocketType>({
const { Provider } = webSocketContext;

export const WebSocketProvider = (props: { children: React.ReactNode }) => {
const [collections, setCollections] = useState<CollectionView[]>([]);
const [collections, setCollections] = useState<Collection[]>([]);
const { isAuth } = useContext(authContext);
const socket = useRef<Socket | null>(null);

useEffect(() => {
if (isAuth) {
socket.current = io(url);
socket.current = io(url as string);

socket.current.on('connect', function () {
console.log('--- ws connected ---');
Expand All @@ -34,8 +33,8 @@ export const WebSocketProvider = (props: { children: React.ReactNode }) => {
* After all collections are not loading or building index, tell server stop pulling data.
*/
socket.current.on(WS_EVENTS.COLLECTION, (data: any) => {
const collections: CollectionHttp[] = data.map(
(v: any) => new CollectionHttp(v)
const collections: Collection[] = data.map(
(v: any) => new Collection(v)
);

const hasLoadingOrBuildingCollection = collections.some(
Expand All @@ -46,7 +45,7 @@ export const WebSocketProvider = (props: { children: React.ReactNode }) => {
// If no collection is building index or loading collection
// stop server cron job
if (!hasLoadingOrBuildingCollection) {
MilvusHttp.triggerCron({
MilvusService.triggerCron({
name: WS_EVENTS.COLLECTION,
type: WS_EVENTS_TYPE.STOP,
});
Expand Down
14 changes: 7 additions & 7 deletions client/src/http/BaseModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class BaseModel {
);
}

static async search(data: findParamsType) {
static async search<T>(data: findParamsType) {
const { method = 'get', params = {}, path = '', timeout } = data;
const httpConfig = {
method,
Expand All @@ -50,26 +50,26 @@ export default class BaseModel {
} as any;
if (timeout) httpConfig.timeout = timeout;
const res = await http(httpConfig);
return new this(res.data.data || {});
return new this(res.data.data || {}) as T;
}

/**
* Create instance in database
*/
static async create(options: updateParamsType) {
static async create<T>(options: updateParamsType) {
const { path, data } = options;
const res = await http.post(path, data);
return new this(res.data.data || {});
return new this(res.data.data || {}) as T;
}

static async update(options: updateParamsType) {
static async update<T>(options: updateParamsType) {
const { path, data } = options;
const res = await http.put(path, data);

return new this(res.data.data || {});
return new this(res.data.data || {}) as T;
}

static async delete(options: updateParamsType) {
static async delete<T>(options: updateParamsType) {
const { path, data } = options;

const res = await http.delete(path, { data: data });
Expand Down
Loading

0 comments on commit 4727d5d

Please sign in to comment.