partitions.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { makeStyles, Theme } from '@material-ui/core';
  2. import { FC, useState } from 'react';
  3. import { PartitionView } from './Types';
  4. import MilvusGrid from '../../components/grid';
  5. import { ColDefinitionsType, ToolBarConfig } from '../../components/grid/Types';
  6. import { useTranslation } from 'react-i18next';
  7. import { usePaginationHook } from '../../hooks/Pagination';
  8. import icons from '../../components/icons/Icons';
  9. import CustomToolTip from '../../components/customToolTip/CustomToolTip';
  10. const useStyles = makeStyles((theme: Theme) => ({
  11. wrapper: {},
  12. icon: {
  13. fontSize: '20px',
  14. marginLeft: theme.spacing(0.5),
  15. },
  16. }));
  17. const Partitions: FC<{ data: PartitionView[]; loading: boolean }> = ({
  18. data,
  19. loading,
  20. }) => {
  21. const classes = useStyles();
  22. const { t } = useTranslation('partition');
  23. const InfoIcon = icons.info;
  24. const {
  25. pageSize,
  26. currentPage,
  27. handleCurrentPage,
  28. // offset,
  29. total,
  30. // setTotal
  31. } = usePaginationHook();
  32. const [selectedPartitions, setSelectedPartitions] = useState<PartitionView[]>(
  33. []
  34. );
  35. const toolbarConfigs: ToolBarConfig[] = [
  36. {
  37. label: t('create'),
  38. onClick: () => {},
  39. icon: 'add',
  40. },
  41. {
  42. type: 'iconBtn',
  43. onClick: () => {},
  44. label: t('delete'),
  45. icon: 'delete',
  46. },
  47. ];
  48. const colDefinitions: ColDefinitionsType[] = [
  49. {
  50. id: '_id',
  51. align: 'left',
  52. disablePadding: true,
  53. label: t('id'),
  54. },
  55. {
  56. id: '_name',
  57. align: 'left',
  58. disablePadding: false,
  59. label: t('name'),
  60. },
  61. {
  62. id: '_statusElement',
  63. align: 'left',
  64. disablePadding: false,
  65. label: t('status'),
  66. },
  67. {
  68. id: '_rowCount',
  69. align: 'left',
  70. disablePadding: false,
  71. label: (
  72. <span className="flex-center">
  73. {t('rowCount')}
  74. <CustomToolTip title={t('tooltip')}>
  75. <InfoIcon classes={{ root: classes.icon }} />
  76. </CustomToolTip>
  77. </span>
  78. ),
  79. },
  80. ];
  81. const handleSelectChange = (value: PartitionView[]) => {
  82. setSelectedPartitions(value);
  83. };
  84. const handlePageChange = (e: any, page: number) => {
  85. handleCurrentPage(page);
  86. setSelectedPartitions([]);
  87. };
  88. return (
  89. <section className={classes.wrapper}>
  90. <MilvusGrid
  91. toolbarConfigs={toolbarConfigs}
  92. colDefinitions={colDefinitions}
  93. rows={data}
  94. rowCount={total}
  95. primaryKey="id"
  96. openCheckBox={true}
  97. showHoverStyle={true}
  98. selected={selectedPartitions}
  99. setSelected={handleSelectChange}
  100. page={currentPage}
  101. onChangePage={handlePageChange}
  102. rowsPerPage={pageSize}
  103. isLoading={loading}
  104. />
  105. </section>
  106. );
  107. };
  108. export default Partitions;