|
@@ -1,7 +1,6 @@
|
|
import { useState, useEffect, useRef, useContext } from 'react';
|
|
import { useState, useEffect, useRef, useContext } from 'react';
|
|
import { TextField, Typography } from '@material-ui/core';
|
|
import { TextField, Typography } from '@material-ui/core';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useTranslation } from 'react-i18next';
|
|
-import { useParams } from 'react-router-dom';
|
|
|
|
import { rootContext } from '@/context';
|
|
import { rootContext } from '@/context';
|
|
import { DataService } from '@/http';
|
|
import { DataService } from '@/http';
|
|
import { useQuery } from '@/hooks';
|
|
import { useQuery } from '@/hooks';
|
|
@@ -26,14 +25,40 @@ import CustomSelector from '@/components/customSelector/CustomSelector';
|
|
import EmptyDataDialog from '@/pages/dialogs/EmptyDataDialog';
|
|
import EmptyDataDialog from '@/pages/dialogs/EmptyDataDialog';
|
|
import ImportSampleDialog from '@/pages/dialogs/ImportSampleDialog';
|
|
import ImportSampleDialog from '@/pages/dialogs/ImportSampleDialog';
|
|
import { detectItemType } from '@/utils';
|
|
import { detectItemType } from '@/utils';
|
|
|
|
+import { CollectionObject, CollectionFullObject } from '@server/types';
|
|
|
|
+import StatusIcon, { LoadingType } from '@/components/status/StatusIcon';
|
|
|
|
+
|
|
|
|
+export interface CollectionDataProps {
|
|
|
|
+ collectionName: string;
|
|
|
|
+ collections: CollectionObject[];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const CollectionData = (props: CollectionDataProps) => {
|
|
|
|
+ // props
|
|
|
|
+ const { collections } = props;
|
|
|
|
+ const collection = collections.find(
|
|
|
|
+ i => i.collection_name === props.collectionName
|
|
|
|
+ ) as CollectionFullObject;
|
|
|
|
+
|
|
|
|
+ // collection is not found or collection full object is not ready
|
|
|
|
+ if (!collection || !collection.consistency_level) {
|
|
|
|
+ return <StatusIcon type={LoadingType.CREATING} />;
|
|
|
|
+ }
|
|
|
|
|
|
-const Data = () => {
|
|
|
|
- // get collection name from url
|
|
|
|
- const { collectionName = '' } = useParams<{ collectionName: string }>();
|
|
|
|
// UI state
|
|
// UI state
|
|
const [tableLoading, setTableLoading] = useState<boolean>();
|
|
const [tableLoading, setTableLoading] = useState<boolean>();
|
|
const [selectedData, setSelectedData] = useState<any[]>([]);
|
|
const [selectedData, setSelectedData] = useState<any[]>([]);
|
|
const [expression, setExpression] = useState<string>('');
|
|
const [expression, setExpression] = useState<string>('');
|
|
|
|
+ const [consistencyLevel, setConsistencyLevel] = useState<string>(
|
|
|
|
+ collection.consistency_level
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ // collection fields, combine static and dynamic fields
|
|
|
|
+ const fields = [
|
|
|
|
+ ...collection.schema.fields,
|
|
|
|
+ ...collection.schema.dynamicFields,
|
|
|
|
+ ];
|
|
|
|
+
|
|
// UI functions
|
|
// UI functions
|
|
const { setDialog, handleCloseDialog, openSnackBar } =
|
|
const { setDialog, handleCloseDialog, openSnackBar } =
|
|
useContext(rootContext);
|
|
useContext(rootContext);
|
|
@@ -89,7 +114,7 @@ const Data = () => {
|
|
};
|
|
};
|
|
const handleDelete = async () => {
|
|
const handleDelete = async () => {
|
|
// call delete api
|
|
// call delete api
|
|
- await DataService.deleteEntities(collectionName, {
|
|
|
|
|
|
+ await DataService.deleteEntities(collection.collection_name, {
|
|
expr: `${collection!.schema.primaryField.name} in [${selectedData
|
|
expr: `${collection!.schema.primaryField.name} in [${selectedData
|
|
.map(v =>
|
|
.map(v =>
|
|
collection!.schema.primaryField.data_type ===
|
|
collection!.schema.primaryField.data_type ===
|
|
@@ -107,23 +132,20 @@ const Data = () => {
|
|
|
|
|
|
// Query hook
|
|
// Query hook
|
|
const {
|
|
const {
|
|
- collection,
|
|
|
|
- fields,
|
|
|
|
currentPage,
|
|
currentPage,
|
|
total,
|
|
total,
|
|
pageSize,
|
|
pageSize,
|
|
expr,
|
|
expr,
|
|
queryResult,
|
|
queryResult,
|
|
setPageSize,
|
|
setPageSize,
|
|
- consistencyLevel,
|
|
|
|
- setConsistencyLevel,
|
|
|
|
setCurrentPage,
|
|
setCurrentPage,
|
|
setExpr,
|
|
setExpr,
|
|
query,
|
|
query,
|
|
reset,
|
|
reset,
|
|
count,
|
|
count,
|
|
} = useQuery({
|
|
} = useQuery({
|
|
- collectionName,
|
|
|
|
|
|
+ collection,
|
|
|
|
+ fields,
|
|
onQueryStart: (expr: string = '') => {
|
|
onQueryStart: (expr: string = '') => {
|
|
setTableLoading(true);
|
|
setTableLoading(true);
|
|
if (expr === '') {
|
|
if (expr === '') {
|
|
@@ -152,7 +174,7 @@ const Data = () => {
|
|
params: {
|
|
params: {
|
|
component: (
|
|
component: (
|
|
<InsertDialog
|
|
<InsertDialog
|
|
- defaultSelectedCollection={collectionName}
|
|
|
|
|
|
+ defaultSelectedCollection={collection.collection_name}
|
|
// user can't select partition on collection page, so default value is ''
|
|
// user can't select partition on collection page, so default value is ''
|
|
defaultSelectedPartition={''}
|
|
defaultSelectedPartition={''}
|
|
collections={[collection!]}
|
|
collections={[collection!]}
|
|
@@ -215,7 +237,7 @@ const Data = () => {
|
|
type: 'button',
|
|
type: 'button',
|
|
btnVariant: 'text',
|
|
btnVariant: 'text',
|
|
onClick: () => {
|
|
onClick: () => {
|
|
- saveCsvAs(selectedData, `${collectionName}.query.csv`);
|
|
|
|
|
|
+ saveCsvAs(selectedData, `${collection.collection_name}.query.csv`);
|
|
},
|
|
},
|
|
label: btnTrans('export'),
|
|
label: btnTrans('export'),
|
|
icon: 'download',
|
|
icon: 'download',
|
|
@@ -420,4 +442,4 @@ const Data = () => {
|
|
);
|
|
);
|
|
};
|
|
};
|
|
|
|
|
|
-export default Data;
|
|
|
|
|
|
+export default CollectionData;
|