UsageLogsTable.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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, Descriptions } from '@douyinfe/semi-ui';
  17. import CardTable from '../../common/ui/CardTable';
  18. import {
  19. IllustrationNoResult,
  20. IllustrationNoResultDark,
  21. } from '@douyinfe/semi-illustrations';
  22. import { getLogsColumns } from './UsageLogsColumnDefs';
  23. const LogsTable = (logsData) => {
  24. const {
  25. logs,
  26. expandData,
  27. loading,
  28. activePage,
  29. pageSize,
  30. logCount,
  31. compactMode,
  32. visibleColumns,
  33. handlePageChange,
  34. handlePageSizeChange,
  35. copyText,
  36. showUserInfoFunc,
  37. openChannelAffinityUsageCacheModal,
  38. hasExpandableRows,
  39. isAdminUser,
  40. billingDisplayMode,
  41. t,
  42. COLUMN_KEYS,
  43. } = logsData;
  44. // Get all columns
  45. const allColumns = useMemo(() => {
  46. return getLogsColumns({
  47. t,
  48. COLUMN_KEYS,
  49. copyText,
  50. showUserInfoFunc,
  51. openChannelAffinityUsageCacheModal,
  52. isAdminUser,
  53. billingDisplayMode,
  54. });
  55. }, [
  56. t,
  57. COLUMN_KEYS,
  58. copyText,
  59. showUserInfoFunc,
  60. openChannelAffinityUsageCacheModal,
  61. isAdminUser,
  62. billingDisplayMode,
  63. ]);
  64. // Filter columns based on visibility settings
  65. const getVisibleColumns = () => {
  66. return allColumns.filter((column) => visibleColumns[column.key]);
  67. };
  68. const visibleColumnsList = useMemo(() => {
  69. return getVisibleColumns();
  70. }, [visibleColumns, allColumns]);
  71. const tableColumns = useMemo(() => {
  72. return compactMode
  73. ? visibleColumnsList.map(({ fixed, ...rest }) => rest)
  74. : visibleColumnsList;
  75. }, [compactMode, visibleColumnsList]);
  76. const expandRowRender = (record, index) => {
  77. return <Descriptions data={expandData[record.key]} />;
  78. };
  79. return (
  80. <CardTable
  81. columns={tableColumns}
  82. {...(hasExpandableRows() && {
  83. expandedRowRender: expandRowRender,
  84. expandRowByClick: true,
  85. rowExpandable: (record) =>
  86. expandData[record.key] && expandData[record.key].length > 0,
  87. })}
  88. dataSource={logs}
  89. rowKey='key'
  90. loading={loading}
  91. scroll={compactMode ? undefined : { x: 'max-content' }}
  92. className='rounded-xl overflow-hidden'
  93. size='small'
  94. empty={
  95. <Empty
  96. image={<IllustrationNoResult style={{ width: 150, height: 150 }} />}
  97. darkModeImage={
  98. <IllustrationNoResultDark style={{ width: 150, height: 150 }} />
  99. }
  100. description={t('搜索无结果')}
  101. style={{ padding: 30 }}
  102. />
  103. }
  104. pagination={{
  105. currentPage: activePage,
  106. pageSize: pageSize,
  107. total: logCount,
  108. pageSizeOptions: [10, 20, 50, 100],
  109. showSizeChanger: true,
  110. onPageSizeChange: (size) => {
  111. handlePageSizeChange(size);
  112. },
  113. onPageChange: handlePageChange,
  114. }}
  115. hidePagination={true}
  116. />
  117. );
  118. };
  119. export default LogsTable;