ColumnSelectorModal.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 from 'react';
  16. import { Modal, Button, Checkbox } from '@douyinfe/semi-ui';
  17. import { getMjLogsColumns } from '../MjLogsColumnDefs.js';
  18. const ColumnSelectorModal = ({
  19. showColumnSelector,
  20. setShowColumnSelector,
  21. visibleColumns,
  22. handleColumnVisibilityChange,
  23. handleSelectAll,
  24. initDefaultColumns,
  25. COLUMN_KEYS,
  26. isAdminUser,
  27. copyText,
  28. openContentModal,
  29. openImageModal,
  30. t,
  31. }) => {
  32. // Get all columns for display in selector
  33. const allColumns = getMjLogsColumns({
  34. t,
  35. COLUMN_KEYS,
  36. copyText,
  37. openContentModal,
  38. openImageModal,
  39. isAdminUser,
  40. });
  41. return (
  42. <Modal
  43. title={t('列设置')}
  44. visible={showColumnSelector}
  45. onCancel={() => setShowColumnSelector(false)}
  46. footer={
  47. <div className="flex justify-end">
  48. <Button onClick={() => initDefaultColumns()}>
  49. {t('重置')}
  50. </Button>
  51. <Button onClick={() => setShowColumnSelector(false)}>
  52. {t('取消')}
  53. </Button>
  54. <Button onClick={() => setShowColumnSelector(false)}>
  55. {t('确定')}
  56. </Button>
  57. </div>
  58. }
  59. >
  60. <div style={{ marginBottom: 20 }}>
  61. <Checkbox
  62. checked={Object.values(visibleColumns).every((v) => v === true)}
  63. indeterminate={
  64. Object.values(visibleColumns).some((v) => v === true) &&
  65. !Object.values(visibleColumns).every((v) => v === true)
  66. }
  67. onChange={(e) => handleSelectAll(e.target.checked)}
  68. >
  69. {t('全选')}
  70. </Checkbox>
  71. </div>
  72. <div
  73. className="flex flex-wrap max-h-96 overflow-y-auto rounded-lg p-4"
  74. style={{ border: '1px solid var(--semi-color-border)' }}
  75. >
  76. {allColumns.map((column) => {
  77. // Skip admin-only columns for non-admin users
  78. if (
  79. !isAdminUser &&
  80. (column.key === COLUMN_KEYS.CHANNEL ||
  81. column.key === COLUMN_KEYS.SUBMIT_RESULT)
  82. ) {
  83. return null;
  84. }
  85. return (
  86. <div key={column.key} className="w-1/2 mb-4 pr-2">
  87. <Checkbox
  88. checked={!!visibleColumns[column.key]}
  89. onChange={(e) =>
  90. handleColumnVisibilityChange(column.key, e.target.checked)
  91. }
  92. >
  93. {column.title}
  94. </Checkbox>
  95. </div>
  96. );
  97. })}
  98. </div>
  99. </Modal>
  100. );
  101. };
  102. export default ColumnSelectorModal;