-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #257 from zilliztech/segments_view
segments view
- Loading branch information
Showing
7 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { useEffect, useState, FC } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { CollectionHttp } from '@/http'; | ||
import { usePaginationHook } from '@/hooks'; | ||
import AttuGrid from '@/components/grid/Grid'; | ||
import { ColDefinitionsType } from '@/components/grid/Types'; | ||
import { ToolBarConfig } from '@/components/grid/Types'; | ||
import CustomToolBar from '@/components/grid/ToolBar'; | ||
import { getQueryStyles } from '../query/Styles'; | ||
import { Segment } from './Types'; | ||
|
||
const Segments: FC<{ | ||
collectionName: string; | ||
}> = ({ collectionName }) => { | ||
const classes = getQueryStyles(); | ||
const [segments, setSegements] = useState<Segment[]>([]); | ||
const { t: collectionTrans } = useTranslation('collection'); | ||
const [loading, setLoading] = useState<boolean>(true); | ||
|
||
const fetchSegments = async () => { | ||
setLoading(true); | ||
|
||
const psegments = await CollectionHttp.getPSegments(collectionName); | ||
const qsegments = await CollectionHttp.getQSegments(collectionName); | ||
|
||
const combinedArray = psegments.infos.map((p: any) => { | ||
const q = qsegments.infos.find((q: any) => q.segmentID === p.segmentID); | ||
return { | ||
...p, | ||
...(q && | ||
Object.keys(q).reduce((acc: any, key) => { | ||
acc[`q_${key}`] = q[key]; | ||
return acc; | ||
}, {})), | ||
}; | ||
}); | ||
|
||
setSegements(combinedArray); | ||
setLoading(false); | ||
}; | ||
|
||
const toolbarConfigs: ToolBarConfig[] = [ | ||
{ | ||
type: 'iconBtn', | ||
onClick: () => { | ||
fetchSegments(); | ||
}, | ||
label: collectionTrans('refresh'), | ||
icon: 'refresh', | ||
}, | ||
]; | ||
|
||
const colDefinitions: ColDefinitionsType[] = [ | ||
{ | ||
id: 'segmentID', | ||
align: 'left', | ||
disablePadding: false, | ||
label: collectionTrans('segmentID'), | ||
}, | ||
{ | ||
id: 'partitionID', | ||
align: 'left', | ||
disablePadding: false, | ||
label: collectionTrans('partitionID'), | ||
}, | ||
{ | ||
id: 'state', | ||
align: 'left', | ||
disablePadding: false, | ||
label: collectionTrans('segPState'), | ||
}, | ||
{ | ||
id: 'num_rows', | ||
align: 'left', | ||
disablePadding: false, | ||
label: collectionTrans('num_rows'), | ||
}, | ||
{ | ||
id: 'q_nodeIds', | ||
align: 'left', | ||
disablePadding: false, | ||
label: collectionTrans('q_nodeIds'), | ||
}, | ||
{ | ||
id: 'q_state', | ||
align: 'left', | ||
disablePadding: false, | ||
label: collectionTrans('q_state'), | ||
}, | ||
{ | ||
id: 'q_index_name', | ||
align: 'left', | ||
disablePadding: false, | ||
label: collectionTrans('q_index_name'), | ||
}, | ||
]; | ||
|
||
useEffect(() => { | ||
fetchSegments(); | ||
}, []); | ||
|
||
const { | ||
pageSize, | ||
handlePageSize, | ||
currentPage, | ||
handleCurrentPage, | ||
total, | ||
data, | ||
order, | ||
orderBy, | ||
handleGridSort, | ||
} = usePaginationHook(segments); | ||
|
||
const handlePageChange = (e: any, page: number) => { | ||
handleCurrentPage(page); | ||
}; | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<CustomToolBar toolbarConfigs={toolbarConfigs} /> | ||
|
||
<AttuGrid | ||
toolbarConfigs={[]} | ||
colDefinitions={colDefinitions} | ||
rows={data} | ||
rowCount={total} | ||
primaryKey="name" | ||
showPagination={true} | ||
openCheckBox={false} | ||
page={currentPage} | ||
onPageChange={handlePageChange} | ||
rowsPerPage={pageSize} | ||
setRowsPerPage={handlePageSize} | ||
isLoading={loading} | ||
order={order} | ||
orderBy={orderBy} | ||
handleSort={handleGridSort} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Segments; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export type Segment = { | ||
collectionID: string; | ||
num_rows: string; | ||
partitionID: string; | ||
q_collectionID: string; | ||
q_indexID: string; | ||
q_index_name: string; | ||
q_mem_size: string; | ||
q_nodeID: string; | ||
q_nodeIds: string[]; | ||
q_num_rows: string; | ||
q_partitionID: string; | ||
q_segmentID: string; | ||
q_state: string; | ||
segmentID: string; | ||
state: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters