index.tsx 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import {
  6. RiErrorWarningFill,
  7. RiLoader2Line,
  8. } from '@remixicon/react'
  9. import cn from '@/utils/classnames'
  10. import { FilePlus02 } from '@/app/components/base/icons/src/vender/line/files'
  11. import { CheckCircle } from '@/app/components/base/icons/src/vender/solid/general'
  12. import Popover from '@/app/components/base/popover'
  13. export type ISegmentAddProps = {
  14. importStatus: ProcessStatus | string | undefined
  15. clearProcessStatus: () => void
  16. showNewSegmentModal: () => void
  17. showBatchModal: () => void
  18. }
  19. export enum ProcessStatus {
  20. WAITING = 'waiting',
  21. PROCESSING = 'processing',
  22. COMPLETED = 'completed',
  23. ERROR = 'error',
  24. }
  25. const SegmentAdd: FC<ISegmentAddProps> = ({
  26. importStatus,
  27. clearProcessStatus,
  28. showNewSegmentModal,
  29. showBatchModal,
  30. }) => {
  31. const { t } = useTranslation()
  32. if (importStatus) {
  33. return (
  34. <>
  35. {(importStatus === ProcessStatus.WAITING || importStatus === ProcessStatus.PROCESSING) && (
  36. <div className='relative overflow-hidden inline-flex items-center mr-2 px-3 py-[6px] text-blue-700 bg-[#F5F8FF] rounded-lg border border-black/5'>
  37. {importStatus === ProcessStatus.WAITING && <div className='absolute left-0 top-0 w-3/12 h-full bg-[#D1E0FF] z-0' />}
  38. {importStatus === ProcessStatus.PROCESSING && <div className='absolute left-0 top-0 w-2/3 h-full bg-[#D1E0FF] z-0' />}
  39. <RiLoader2Line className='animate-spin mr-2 w-4 h-4' />
  40. <span className='font-medium text-[13px] leading-[18px] z-10'>{t('datasetDocuments.list.batchModal.processing')}</span>
  41. </div>
  42. )}
  43. {importStatus === ProcessStatus.COMPLETED && (
  44. <div className='inline-flex items-center mr-2 px-3 py-[6px] text-gray-700 bg-[#F6FEF9] rounded-lg border border-black/5'>
  45. <CheckCircle className='mr-2 w-4 h-4 text-[#039855]' />
  46. <span className='font-medium text-[13px] leading-[18px]'>{t('datasetDocuments.list.batchModal.completed')}</span>
  47. <span className='pl-2 font-medium text-[13px] leading-[18px] text-[#155EEF] cursor-pointer' onClick={clearProcessStatus}>{t('datasetDocuments.list.batchModal.ok')}</span>
  48. </div>
  49. )}
  50. {importStatus === ProcessStatus.ERROR && (
  51. <div className='inline-flex items-center mr-2 px-3 py-[6px] text-red-600 bg-red-100 rounded-lg border border-black/5'>
  52. <RiErrorWarningFill className='mr-2 w-4 h-4 text-[#D92D20]' />
  53. <span className='font-medium text-[13px] leading-[18px]'>{t('datasetDocuments.list.batchModal.error')}</span>
  54. <span className='pl-2 font-medium text-[13px] leading-[18px] text-[#155EEF] cursor-pointer' onClick={clearProcessStatus}>{t('datasetDocuments.list.batchModal.ok')}</span>
  55. </div>
  56. )}
  57. </>
  58. )
  59. }
  60. return (
  61. <Popover
  62. manualClose
  63. trigger='click'
  64. htmlContent={
  65. <div className='w-full py-1'>
  66. <div className='py-2 px-3 mx-1 flex items-center gap-2 hover:bg-gray-100 rounded-lg cursor-pointer text-gray-700 text-sm' onClick={showNewSegmentModal}>{t('datasetDocuments.list.action.add')}</div>
  67. <div className='py-2 px-3 mx-1 flex items-center gap-2 hover:bg-gray-100 rounded-lg cursor-pointer text-gray-700 text-sm' onClick={showBatchModal}>{t('datasetDocuments.list.action.batchAdd')}</div>
  68. </div>
  69. }
  70. btnElement={
  71. <div className='inline-flex items-center'>
  72. <FilePlus02 className='w-4 h-4 text-gray-700' />
  73. <span className='pl-1'>{t('datasetDocuments.list.action.addButton')}</span>
  74. </div>
  75. }
  76. btnClassName={open => cn('mr-2 !py-[6px] !text-[13px] !leading-[18px] hover:bg-gray-50 border border-gray-200 hover:border-gray-300 hover:shadow-[0_1px_2px_rgba(16,24,40,0.05)]', open ? '!bg-gray-100 !shadow-none' : '!bg-transparent')}
  77. className='!w-[132px] h-fit !z-20 !translate-x-0 !left-0'
  78. />
  79. )
  80. }
  81. export default React.memo(SegmentAdd)