partitions.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. console.log('==== data', data, 'loading', loading);
  25. const {
  26. pageSize,
  27. currentPage,
  28. handleCurrentPage,
  29. // offset,
  30. total,
  31. // setTotal
  32. } = usePaginationHook();
  33. const [selectedPartitions, setSelectedPartitions] = useState<PartitionView[]>(
  34. []
  35. );
  36. const toolbarConfigs: ToolBarConfig[] = [
  37. {
  38. label: t('create'),
  39. onClick: () => {},
  40. icon: 'add',
  41. },
  42. {
  43. type: 'iconBtn',
  44. onClick: () => {},
  45. label: t('delete'),
  46. icon: 'delete',
  47. },
  48. ];
  49. const colDefinitions: ColDefinitionsType[] = [
  50. {
  51. id: '_id',
  52. align: 'left',
  53. disablePadding: true,
  54. label: t('id'),
  55. },
  56. {
  57. id: '_name',
  58. align: 'left',
  59. disablePadding: false,
  60. label: t('name'),
  61. },
  62. {
  63. id: '_statusElement',
  64. align: 'left',
  65. disablePadding: false,
  66. label: t('status'),
  67. },
  68. {
  69. id: '_rowCount',
  70. align: 'left',
  71. disablePadding: false,
  72. label: (
  73. <span className="flex-center">
  74. {t('rowCount')}
  75. <CustomToolTip title={t('tooltip')}>
  76. <InfoIcon classes={{ root: classes.icon }} />
  77. </CustomToolTip>
  78. </span>
  79. ),
  80. },
  81. ];
  82. const handleSelectChange = (value: PartitionView[]) => {
  83. setSelectedPartitions(value);
  84. };
  85. const handlePageChange = (e: any, page: number) => {
  86. handleCurrentPage(page);
  87. setSelectedPartitions([]);
  88. };
  89. return (
  90. <section className={classes.wrapper}>
  91. <MilvusGrid
  92. toolbarConfigs={toolbarConfigs}
  93. colDefinitions={colDefinitions}
  94. rows={data}
  95. rowCount={total}
  96. primaryKey="id"
  97. openCheckBox={true}
  98. showHoverStyle={true}
  99. selected={selectedPartitions}
  100. setSelected={handleSelectChange}
  101. page={currentPage}
  102. onChangePage={handlePageChange}
  103. rowsPerPage={pageSize}
  104. isLoading={loading}
  105. />
  106. </section>
  107. );
  108. };
  109. export default Partitions;