|
@@ -1,205 +0,0 @@
|
|
-import {
|
|
|
|
- makeStyles,
|
|
|
|
- Theme,
|
|
|
|
- Typography,
|
|
|
|
- Divider,
|
|
|
|
- Card,
|
|
|
|
- CardContent,
|
|
|
|
-} from '@material-ui/core';
|
|
|
|
-import { FC, useContext, useEffect, useState } from 'react';
|
|
|
|
-import CustomButton from '@/components/customButton/CustomButton';
|
|
|
|
-import icons from '@/components/icons/Icons';
|
|
|
|
-import Status from '@/components/status/Status';
|
|
|
|
-import { useTranslation } from 'react-i18next';
|
|
|
|
-import CustomIconButton from '@/components/customButton/CustomIconButton';
|
|
|
|
-import { useNavigate, Link } from 'react-router-dom';
|
|
|
|
-import { LOADING_STATE } from '@/consts';
|
|
|
|
-import { rootContext, dataContext } from '@/context';
|
|
|
|
-import ReleaseCollectionDialog from '../../dialogs/ReleaseCollectionDialog';
|
|
|
|
-import { CollectionCardProps } from './Types';
|
|
|
|
-import { CollectionService } from '@/http';
|
|
|
|
-
|
|
|
|
-const useStyles = makeStyles((theme: Theme) => ({
|
|
|
|
- wrapper: {
|
|
|
|
- textAlign: 'end',
|
|
|
|
- '& .link': {
|
|
|
|
- display: 'flex',
|
|
|
|
- alignItems: 'center',
|
|
|
|
- margin: theme.spacing(2, 0),
|
|
|
|
- color: theme.palette.attuDark.main,
|
|
|
|
- wordBreak: 'break-all',
|
|
|
|
- textAlign: 'left',
|
|
|
|
- fontSize: '20px',
|
|
|
|
- lineHeight: '24px',
|
|
|
|
- fontWeight: 'bold',
|
|
|
|
- textDecoration: 'none',
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- loading: {
|
|
|
|
- background: '#F0F4F9',
|
|
|
|
- border: `1px dashed ${theme.palette.primary.main}`,
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- icon: {
|
|
|
|
- color: theme.palette.primary.main,
|
|
|
|
- marginLeft: theme.spacing(0.5),
|
|
|
|
- fontSize: '16px',
|
|
|
|
- },
|
|
|
|
- content: {
|
|
|
|
- margin: 0,
|
|
|
|
- padding: 0,
|
|
|
|
- '& > li': {
|
|
|
|
- display: 'flex',
|
|
|
|
- alignItems: 'center',
|
|
|
|
- marginBottom: theme.spacing(0.5),
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- rowCount: {
|
|
|
|
- marginLeft: theme.spacing(1),
|
|
|
|
- },
|
|
|
|
- divider: {
|
|
|
|
- marginBottom: theme.spacing(2),
|
|
|
|
- },
|
|
|
|
- release: {
|
|
|
|
- fontSize: '16px',
|
|
|
|
-
|
|
|
|
- '& path': {
|
|
|
|
- fill: theme.palette.primary.main,
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- search: {
|
|
|
|
- fontSize: '16px',
|
|
|
|
- marginRight: theme.spacing(0.5),
|
|
|
|
- '& path': {
|
|
|
|
- fill: '#fff',
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- btn: {
|
|
|
|
- marginRight: theme.spacing(1),
|
|
|
|
- padding: theme.spacing(0.5, 1),
|
|
|
|
- lineHeight: '20px',
|
|
|
|
- fontSize: 14,
|
|
|
|
- },
|
|
|
|
-}));
|
|
|
|
-
|
|
|
|
-const CollectionCard: FC<CollectionCardProps> = ({
|
|
|
|
- collection,
|
|
|
|
- onRelease,
|
|
|
|
- wrapperClass = '',
|
|
|
|
-}) => {
|
|
|
|
- const { database } = useContext(dataContext);
|
|
|
|
- const [loading, setLoading] = useState(false);
|
|
|
|
- const [count, setCount] = useState<number>();
|
|
|
|
- const classes = useStyles();
|
|
|
|
- const { setDialog } = useContext(rootContext);
|
|
|
|
-
|
|
|
|
- const {
|
|
|
|
- collection_name,
|
|
|
|
- status: status,
|
|
|
|
- loadedPercentage,
|
|
|
|
- replicas,
|
|
|
|
- } = collection;
|
|
|
|
- const navigate = useNavigate();
|
|
|
|
- // icons
|
|
|
|
- const RightArrowIcon = icons.rightArrow;
|
|
|
|
- const ReleaseIcon = icons.release;
|
|
|
|
- const VectorSearchIcon = icons.navSearch;
|
|
|
|
- // i18n
|
|
|
|
- const { t: collectionTrans } = useTranslation('collection');
|
|
|
|
- const { t: btnTrans } = useTranslation('btn');
|
|
|
|
-
|
|
|
|
- const onReleaseClick = () => {
|
|
|
|
- setDialog({
|
|
|
|
- open: true,
|
|
|
|
- type: 'custom',
|
|
|
|
- params: {
|
|
|
|
- component: (
|
|
|
|
- <ReleaseCollectionDialog
|
|
|
|
- collection={collection_name}
|
|
|
|
- onRelease={onRelease}
|
|
|
|
- />
|
|
|
|
- ),
|
|
|
|
- },
|
|
|
|
- });
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- const onVectorSearchClick = () => {
|
|
|
|
- navigate({
|
|
|
|
- pathname: '/search',
|
|
|
|
- search: `?collectionName=${collection_name}`,
|
|
|
|
- });
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- const fetchData = async () => {
|
|
|
|
- try {
|
|
|
|
- setLoading(true);
|
|
|
|
- const data = await CollectionService.count(collection_name);
|
|
|
|
- setCount(data.rowCount);
|
|
|
|
- } catch (e) {
|
|
|
|
- } finally {
|
|
|
|
- setLoading(false);
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- useEffect(() => {
|
|
|
|
- if (status === LOADING_STATE.LOADED) {
|
|
|
|
- fetchData();
|
|
|
|
- }
|
|
|
|
- }, [status]);
|
|
|
|
-
|
|
|
|
- return (
|
|
|
|
- <Card
|
|
|
|
- className={`${classes.wrapper} ${wrapperClass} ${
|
|
|
|
- collection.status === LOADING_STATE.LOADING && classes.loading
|
|
|
|
- }`}
|
|
|
|
- >
|
|
|
|
- <CardContent>
|
|
|
|
- <div>
|
|
|
|
- <Status status={status} percentage={loadedPercentage} />
|
|
|
|
- </div>
|
|
|
|
- <Link
|
|
|
|
- className="link"
|
|
|
|
- to={`/databases/${database}/${collection_name}/data`}
|
|
|
|
- >
|
|
|
|
- {collection_name}
|
|
|
|
- <RightArrowIcon classes={{ root: classes.icon }} />
|
|
|
|
- </Link>
|
|
|
|
- <ul className={classes.content}>
|
|
|
|
- {replicas && replicas.length > 1 ? (
|
|
|
|
- <li>
|
|
|
|
- <Typography>{collectionTrans('replicaNum')}</Typography>:
|
|
|
|
- <Typography className={classes.rowCount}>
|
|
|
|
- {replicas.length}
|
|
|
|
- </Typography>
|
|
|
|
- </li>
|
|
|
|
- ) : null}
|
|
|
|
- <li>
|
|
|
|
- <Typography>{collectionTrans('count')}</Typography>:
|
|
|
|
- {loading ? (
|
|
|
|
- `...`
|
|
|
|
- ) : (
|
|
|
|
- <Typography className={classes.rowCount}>{count}</Typography>
|
|
|
|
- )}
|
|
|
|
- </li>
|
|
|
|
- </ul>
|
|
|
|
- <Divider classes={{ root: classes.divider }} />
|
|
|
|
- <CustomButton
|
|
|
|
- variant="contained"
|
|
|
|
- className={classes.btn}
|
|
|
|
- onClick={onVectorSearchClick}
|
|
|
|
- >
|
|
|
|
- <VectorSearchIcon classes={{ root: classes.search }} />
|
|
|
|
- {btnTrans('vectorSearch')}
|
|
|
|
- </CustomButton>
|
|
|
|
- <CustomIconButton
|
|
|
|
- onClick={onReleaseClick}
|
|
|
|
- tooltip={btnTrans('release')}
|
|
|
|
- >
|
|
|
|
- <ReleaseIcon classes={{ root: classes.release }} />
|
|
|
|
- </CustomIconButton>
|
|
|
|
- </CardContent>
|
|
|
|
- </Card>
|
|
|
|
- );
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-export default CollectionCard;
|
|
|