SearchModal.jsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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, { useRef } from 'react';
  16. import { Modal, Form } from '@douyinfe/semi-ui';
  17. const SearchModal = ({
  18. searchModalVisible,
  19. handleSearchConfirm,
  20. handleCloseModal,
  21. isMobile,
  22. isAdminUser,
  23. inputs,
  24. dataExportDefaultTime,
  25. timeOptions,
  26. handleInputChange,
  27. t,
  28. }) => {
  29. const formRef = useRef();
  30. const FORM_FIELD_PROPS = {
  31. className: 'w-full mb-2 !rounded-lg',
  32. };
  33. const createFormField = (Component, props) => (
  34. <Component {...FORM_FIELD_PROPS} {...props} />
  35. );
  36. const { start_timestamp, end_timestamp, username } = inputs;
  37. return (
  38. <Modal
  39. title={t('搜索条件')}
  40. visible={searchModalVisible}
  41. onOk={handleSearchConfirm}
  42. onCancel={handleCloseModal}
  43. closeOnEsc={true}
  44. size={isMobile ? 'full-width' : 'small'}
  45. centered
  46. >
  47. <Form ref={formRef} layout='vertical' className='w-full'>
  48. {createFormField(Form.DatePicker, {
  49. field: 'start_timestamp',
  50. label: t('起始时间'),
  51. initValue: start_timestamp,
  52. value: start_timestamp,
  53. type: 'dateTime',
  54. name: 'start_timestamp',
  55. onChange: (value) => handleInputChange(value, 'start_timestamp'),
  56. })}
  57. {createFormField(Form.DatePicker, {
  58. field: 'end_timestamp',
  59. label: t('结束时间'),
  60. initValue: end_timestamp,
  61. value: end_timestamp,
  62. type: 'dateTime',
  63. name: 'end_timestamp',
  64. onChange: (value) => handleInputChange(value, 'end_timestamp'),
  65. })}
  66. {createFormField(Form.Select, {
  67. field: 'data_export_default_time',
  68. label: t('时间粒度'),
  69. initValue: dataExportDefaultTime,
  70. placeholder: t('时间粒度'),
  71. name: 'data_export_default_time',
  72. optionList: timeOptions,
  73. onChange: (value) =>
  74. handleInputChange(value, 'data_export_default_time'),
  75. })}
  76. {isAdminUser &&
  77. createFormField(Form.Input, {
  78. field: 'username',
  79. label: t('用户名称'),
  80. value: username,
  81. placeholder: t('可选值'),
  82. name: 'username',
  83. onChange: (value) => handleInputChange(value, 'username'),
  84. })}
  85. </Form>
  86. </Modal>
  87. );
  88. };
  89. export default SearchModal;