MjLogsTable.jsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 { getMjLogsColumns } from './MjLogsColumnDefs';
  23. const MjLogsTable = (mjLogsData) => {
  24. const {
  25. logs,
  26. loading,
  27. activePage,
  28. pageSize,
  29. logCount,
  30. compactMode,
  31. visibleColumns,
  32. handlePageChange,
  33. handlePageSizeChange,
  34. copyText,
  35. openContentModal,
  36. openImageModal,
  37. isAdminUser,
  38. t,
  39. COLUMN_KEYS,
  40. } = mjLogsData;
  41. // Get all columns
  42. const allColumns = useMemo(() => {
  43. return getMjLogsColumns({
  44. t,
  45. COLUMN_KEYS,
  46. copyText,
  47. openContentModal,
  48. openImageModal,
  49. isAdminUser,
  50. });
  51. }, [
  52. t,
  53. COLUMN_KEYS,
  54. copyText,
  55. openContentModal,
  56. openImageModal,
  57. isAdminUser,
  58. ]);
  59. // Filter columns based on visibility settings
  60. const getVisibleColumns = () => {
  61. return allColumns.filter((column) => visibleColumns[column.key]);
  62. };
  63. const visibleColumnsList = useMemo(() => {
  64. return getVisibleColumns();
  65. }, [visibleColumns, allColumns]);
  66. const tableColumns = useMemo(() => {
  67. return compactMode
  68. ? visibleColumnsList.map(({ fixed, ...rest }) => rest)
  69. : visibleColumnsList;
  70. }, [compactMode, visibleColumnsList]);
  71. return (
  72. <CardTable
  73. columns={tableColumns}
  74. dataSource={logs}
  75. rowKey='key'
  76. loading={loading}
  77. scroll={compactMode ? undefined : { x: 'max-content' }}
  78. className="rounded-xl overflow-hidden"
  79. size="middle"
  80. empty={
  81. <Empty
  82. image={
  83. <IllustrationNoResult style={{ width: 150, height: 150 }} />
  84. }
  85. darkModeImage={
  86. <IllustrationNoResultDark style={{ width: 150, height: 150 }} />
  87. }
  88. description={t('搜索无结果')}
  89. style={{ padding: 30 }}
  90. />
  91. }
  92. pagination={{
  93. currentPage: activePage,
  94. pageSize: pageSize,
  95. total: logCount,
  96. pageSizeOptions: [10, 20, 50, 100],
  97. showSizeChanger: true,
  98. onPageSizeChange: handlePageSizeChange,
  99. onPageChange: handlePageChange,
  100. }}
  101. hidePagination={true}
  102. />
  103. );
  104. };
  105. export default MjLogsTable;