|
@@ -8,14 +8,13 @@ import {
|
|
IndexManageParam,
|
|
IndexManageParam,
|
|
ParamPair,
|
|
ParamPair,
|
|
} from './Types';
|
|
} from './Types';
|
|
-import StatusIcon from '../../components/status/StatusIcon';
|
|
|
|
-import { ChildrenStatusType } from '../../components/status/Types';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { makeStyles, Theme } from '@material-ui/core';
|
|
import { makeStyles, Theme } from '@material-ui/core';
|
|
import icons from '../../components/icons/Icons';
|
|
import icons from '../../components/icons/Icons';
|
|
import { rootContext } from '../../context/Root';
|
|
import { rootContext } from '../../context/Root';
|
|
import CreateIndex from './Create';
|
|
import CreateIndex from './Create';
|
|
import DeleteTemplate from '../../components/customDialog/DeleteDialogTemplate';
|
|
import DeleteTemplate from '../../components/customDialog/DeleteDialogTemplate';
|
|
|
|
+import CustomLinearProgress from '../../components/customProgress/CustomLinearProgress';
|
|
|
|
|
|
const useStyles = makeStyles((theme: Theme) => ({
|
|
const useStyles = makeStyles((theme: Theme) => ({
|
|
item: {
|
|
item: {
|
|
@@ -62,20 +61,24 @@ const useStyles = makeStyles((theme: Theme) => ({
|
|
},
|
|
},
|
|
}));
|
|
}));
|
|
|
|
|
|
|
|
+let timer: NodeJS.Timeout | null = null;
|
|
|
|
+
|
|
const IndexTypeElement: FC<{
|
|
const IndexTypeElement: FC<{
|
|
data: FieldView;
|
|
data: FieldView;
|
|
collectionName: string;
|
|
collectionName: string;
|
|
cb: (collectionName: string) => void;
|
|
cb: (collectionName: string) => void;
|
|
}> = ({ data, collectionName, cb }) => {
|
|
}> = ({ data, collectionName, cb }) => {
|
|
const classes = useStyles();
|
|
const classes = useStyles();
|
|
-
|
|
|
|
- const [status, setStatus] = useState<string>('');
|
|
|
|
|
|
+ // set in progress as defalut status
|
|
|
|
+ const [status, setStatus] = useState<string>(IndexState.InProgress);
|
|
|
|
|
|
const { t: indexTrans } = useTranslation('index');
|
|
const { t: indexTrans } = useTranslation('index');
|
|
const { t: btnTrans } = useTranslation('btn');
|
|
const { t: btnTrans } = useTranslation('btn');
|
|
const { t: dialogTrans } = useTranslation('dialog');
|
|
const { t: dialogTrans } = useTranslation('dialog');
|
|
const { t: successTrans } = useTranslation('success');
|
|
const { t: successTrans } = useTranslation('success');
|
|
|
|
|
|
|
|
+ const [createProgress, setCreateProgress] = useState<number>(0);
|
|
|
|
+
|
|
const { setDialog, handleCloseDialog, openSnackBar } =
|
|
const { setDialog, handleCloseDialog, openSnackBar } =
|
|
useContext(rootContext);
|
|
useContext(rootContext);
|
|
|
|
|
|
@@ -84,7 +87,7 @@ const IndexTypeElement: FC<{
|
|
|
|
|
|
const fetchStatus = useCallback(async () => {
|
|
const fetchStatus = useCallback(async () => {
|
|
if (data._indexType !== '') {
|
|
if (data._indexType !== '') {
|
|
- const status = await IndexHttp.getIndexStatus(
|
|
|
|
|
|
+ const { state: status } = await IndexHttp.getIndexStatus(
|
|
collectionName,
|
|
collectionName,
|
|
data._fieldName
|
|
data._fieldName
|
|
);
|
|
);
|
|
@@ -96,6 +99,40 @@ const IndexTypeElement: FC<{
|
|
fetchStatus();
|
|
fetchStatus();
|
|
}, [fetchStatus]);
|
|
}, [fetchStatus]);
|
|
|
|
|
|
|
|
+ const fetchProgress = useCallback(() => {
|
|
|
|
+ if (timer) {
|
|
|
|
+ clearTimeout(timer);
|
|
|
|
+ }
|
|
|
|
+ if (data._indexType !== '' && status === IndexState.InProgress) {
|
|
|
|
+ timer = setTimeout(async () => {
|
|
|
|
+ const res = await IndexHttp.getIndexBuildProgress(
|
|
|
|
+ collectionName,
|
|
|
|
+ data._fieldName
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ const { indexed_rows, total_rows } = res;
|
|
|
|
+ const percent = Number(indexed_rows) / Number(total_rows);
|
|
|
|
+ const value = Math.floor(percent * 100);
|
|
|
|
+ setCreateProgress(value);
|
|
|
|
+
|
|
|
|
+ if (value !== 100) {
|
|
|
|
+ fetchProgress();
|
|
|
|
+ } else {
|
|
|
|
+ timer && clearTimeout(timer);
|
|
|
|
+ // reset build progress
|
|
|
|
+ setCreateProgress(0);
|
|
|
|
+ // change index create status
|
|
|
|
+ setStatus(IndexState.Finished);
|
|
|
|
+ }
|
|
|
|
+ }, 500);
|
|
|
|
+ }
|
|
|
|
+ }, [collectionName, data._fieldName, status, data._indexType]);
|
|
|
|
+
|
|
|
|
+ // get index build progress
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ fetchProgress();
|
|
|
|
+ }, [fetchProgress]);
|
|
|
|
+
|
|
const requestCreateIndex = async (params: ParamPair[]) => {
|
|
const requestCreateIndex = async (params: ParamPair[]) => {
|
|
const indexCreateParam: IndexCreateParam = {
|
|
const indexCreateParam: IndexCreateParam = {
|
|
collection_name: collectionName,
|
|
collection_name: collectionName,
|
|
@@ -179,7 +216,10 @@ const IndexTypeElement: FC<{
|
|
}
|
|
}
|
|
default: {
|
|
default: {
|
|
return status === IndexState.InProgress ? (
|
|
return status === IndexState.InProgress ? (
|
|
- <StatusIcon type={ChildrenStatusType.CREATING} />
|
|
|
|
|
|
+ <CustomLinearProgress
|
|
|
|
+ value={createProgress}
|
|
|
|
+ tooltip={indexTrans('creating')}
|
|
|
|
+ />
|
|
) : (
|
|
) : (
|
|
<Chip
|
|
<Chip
|
|
label={data._indexType}
|
|
label={data._indexType}
|