TokensTable.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 { getTokensColumns } from './TokensColumnDefs';
  23. const TokensTable = (tokensData) => {
  24. const {
  25. tokens,
  26. loading,
  27. activePage,
  28. pageSize,
  29. tokenCount,
  30. compactMode,
  31. handlePageChange,
  32. handlePageSizeChange,
  33. rowSelection,
  34. handleRow,
  35. showKeys,
  36. resolvedTokenKeys,
  37. loadingTokenKeys,
  38. toggleTokenVisibility,
  39. copyTokenKey,
  40. copyTokenConnectionString,
  41. manageToken,
  42. onOpenLink,
  43. setEditingToken,
  44. setShowEdit,
  45. refresh,
  46. groupRatios,
  47. t,
  48. } = tokensData;
  49. // Get all columns
  50. const columns = useMemo(() => {
  51. return getTokensColumns({
  52. t,
  53. showKeys,
  54. resolvedTokenKeys,
  55. loadingTokenKeys,
  56. toggleTokenVisibility,
  57. copyTokenKey,
  58. copyTokenConnectionString,
  59. manageToken,
  60. onOpenLink,
  61. setEditingToken,
  62. setShowEdit,
  63. refresh,
  64. groupRatios,
  65. });
  66. }, [
  67. t,
  68. showKeys,
  69. resolvedTokenKeys,
  70. loadingTokenKeys,
  71. toggleTokenVisibility,
  72. copyTokenKey,
  73. copyTokenConnectionString,
  74. manageToken,
  75. onOpenLink,
  76. setEditingToken,
  77. setShowEdit,
  78. refresh,
  79. groupRatios,
  80. ]);
  81. // Handle compact mode by removing fixed positioning
  82. const tableColumns = useMemo(() => {
  83. return compactMode
  84. ? columns.map((col) => {
  85. if (col.dataIndex === 'operate') {
  86. const { fixed, ...rest } = col;
  87. return rest;
  88. }
  89. return col;
  90. })
  91. : columns;
  92. }, [compactMode, columns]);
  93. return (
  94. <CardTable
  95. columns={tableColumns}
  96. dataSource={tokens}
  97. scroll={compactMode ? undefined : { x: 'max-content' }}
  98. pagination={{
  99. currentPage: activePage,
  100. pageSize: pageSize,
  101. total: tokenCount,
  102. showSizeChanger: true,
  103. pageSizeOptions: [10, 20, 50, 100],
  104. onPageSizeChange: handlePageSizeChange,
  105. onPageChange: handlePageChange,
  106. }}
  107. hidePagination={true}
  108. loading={loading}
  109. rowSelection={rowSelection}
  110. onRow={handleRow}
  111. empty={
  112. <Empty
  113. image={<IllustrationNoResult style={{ width: 150, height: 150 }} />}
  114. darkModeImage={
  115. <IllustrationNoResultDark style={{ width: 150, height: 150 }} />
  116. }
  117. description={t('搜索无结果')}
  118. style={{ padding: 30 }}
  119. />
  120. }
  121. className='rounded-xl overflow-hidden'
  122. size='middle'
  123. />
  124. );
  125. };
  126. export default TokensTable;