ModelsTable.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact support@quantumnous.com
  14. */
  15. import React, { useMemo } from 'react';
  16. import { Empty } from '@douyinfe/semi-ui';
  17. import CardTable from '../../common/ui/CardTable';
  18. import {
  19. IllustrationNoResult,
  20. IllustrationNoResultDark,
  21. } from '@douyinfe/semi-illustrations';
  22. import { getModelsColumns } from './ModelsColumnDefs';
  23. const ModelsTable = (modelsData) => {
  24. const {
  25. models,
  26. loading,
  27. activePage,
  28. pageSize,
  29. modelCount,
  30. compactMode,
  31. handlePageChange,
  32. handlePageSizeChange,
  33. rowSelection,
  34. handleRow,
  35. manageModel,
  36. setEditingModel,
  37. setShowEdit,
  38. refresh,
  39. vendorMap,
  40. t,
  41. } = modelsData;
  42. // Get all columns
  43. const columns = useMemo(() => {
  44. return getModelsColumns({
  45. t,
  46. manageModel,
  47. setEditingModel,
  48. setShowEdit,
  49. refresh,
  50. vendorMap,
  51. });
  52. }, [t, manageModel, setEditingModel, setShowEdit, refresh, vendorMap]);
  53. // Handle compact mode by removing fixed positioning
  54. const tableColumns = useMemo(() => {
  55. return compactMode
  56. ? columns.map((col) => {
  57. if (col.dataIndex === 'operate') {
  58. const { fixed, ...rest } = col;
  59. return rest;
  60. }
  61. return col;
  62. })
  63. : columns;
  64. }, [compactMode, columns]);
  65. return (
  66. <CardTable
  67. columns={tableColumns}
  68. dataSource={models}
  69. scroll={compactMode ? undefined : { x: 'max-content' }}
  70. pagination={{
  71. currentPage: activePage,
  72. pageSize: pageSize,
  73. total: modelCount,
  74. showSizeChanger: true,
  75. pageSizeOptions: [10, 20, 50, 100],
  76. onPageSizeChange: handlePageSizeChange,
  77. onPageChange: handlePageChange,
  78. }}
  79. hidePagination={true}
  80. loading={loading}
  81. rowSelection={rowSelection}
  82. onRow={handleRow}
  83. empty={
  84. <Empty
  85. image={<IllustrationNoResult style={{ width: 150, height: 150 }} />}
  86. darkModeImage={
  87. <IllustrationNoResultDark style={{ width: 150, height: 150 }} />
  88. }
  89. description={t('搜索无结果')}
  90. style={{ padding: 30 }}
  91. />
  92. }
  93. className='rounded-xl overflow-hidden'
  94. size='middle'
  95. />
  96. );
  97. };
  98. export default ModelsTable;