batch-action.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import React, { type FC } from 'react'
  2. import { RiArchive2Line, RiCheckboxCircleLine, RiCloseCircleLine, RiDeleteBinLine, RiDownloadLine, RiDraftLine } from '@remixicon/react'
  3. import { useTranslation } from 'react-i18next'
  4. import { useBoolean } from 'ahooks'
  5. import Divider from '@/app/components/base/divider'
  6. import classNames from '@/utils/classnames'
  7. import Confirm from '@/app/components/base/confirm'
  8. const i18nPrefix = 'dataset.batchAction'
  9. type IBatchActionProps = {
  10. className?: string
  11. selectedIds: string[]
  12. onBatchEnable: () => void
  13. onBatchDisable: () => void
  14. onBatchDelete: () => Promise<void>
  15. onArchive?: () => void
  16. onEditMetadata?: () => void
  17. onBatchDownload?: () => void
  18. onCancel: () => void
  19. }
  20. const BatchAction: FC<IBatchActionProps> = ({
  21. className,
  22. selectedIds,
  23. onBatchEnable,
  24. onBatchDisable,
  25. onArchive,
  26. onBatchDelete,
  27. onEditMetadata,
  28. onBatchDownload,
  29. onCancel,
  30. }) => {
  31. const { t } = useTranslation()
  32. const [isShowDeleteConfirm, {
  33. setTrue: showDeleteConfirm,
  34. setFalse: hideDeleteConfirm,
  35. }] = useBoolean(false)
  36. const [isDeleting, {
  37. setTrue: setIsDeleting,
  38. }] = useBoolean(false)
  39. const handleBatchDelete = async () => {
  40. setIsDeleting()
  41. await onBatchDelete()
  42. hideDeleteConfirm()
  43. }
  44. return (
  45. <div className={classNames('pointer-events-none flex w-full justify-center gap-x-2', className)}>
  46. <div className='pointer-events-auto flex items-center gap-x-1 rounded-[10px] border border-components-actionbar-border-accent bg-components-actionbar-bg-accent p-1 shadow-xl shadow-shadow-shadow-5 backdrop-blur-[5px]'>
  47. <div className='inline-flex items-center gap-x-2 py-1 pl-2 pr-3'>
  48. <span className='flex h-5 w-5 items-center justify-center rounded-md bg-text-accent px-1 py-0.5 text-xs font-medium text-text-primary-on-surface'>
  49. {selectedIds.length}
  50. </span>
  51. <span className='text-[13px] font-semibold leading-[16px] text-text-accent'>{t(`${i18nPrefix}.selected`)}</span>
  52. </div>
  53. <Divider type='vertical' className='mx-0.5 h-3.5 bg-divider-regular' />
  54. <div className='flex items-center gap-x-0.5 px-3 py-2'>
  55. <RiCheckboxCircleLine className='h-4 w-4 text-components-button-ghost-text' />
  56. <button type='button' className='px-0.5 text-[13px] font-medium leading-[16px] text-components-button-ghost-text' onClick={onBatchEnable}>
  57. {t(`${i18nPrefix}.enable`)}
  58. </button>
  59. </div>
  60. <div className='flex items-center gap-x-0.5 px-3 py-2'>
  61. <RiCloseCircleLine className='h-4 w-4 text-components-button-ghost-text' />
  62. <button type='button' className='px-0.5 text-[13px] font-medium leading-[16px] text-components-button-ghost-text' onClick={onBatchDisable}>
  63. {t(`${i18nPrefix}.disable`)}
  64. </button>
  65. </div>
  66. {onEditMetadata && (
  67. <div className='flex items-center gap-x-0.5 px-3 py-2'>
  68. <RiDraftLine className='h-4 w-4 text-components-button-ghost-text' />
  69. <button type='button' className='px-0.5 text-[13px] font-medium leading-[16px] text-components-button-ghost-text' onClick={onEditMetadata}>
  70. {t('dataset.metadata.metadata')}
  71. </button>
  72. </div>
  73. )}
  74. {onBatchDownload && (
  75. <div className='flex items-center gap-x-0.5 px-3 py-2'>
  76. <RiDownloadLine className='h-4 w-4 text-components-button-ghost-text' />
  77. <button type='button' className='px-0.5 text-[13px] font-medium leading-[16px] text-components-button-ghost-text' onClick={onBatchDownload}>
  78. {t(`${i18nPrefix}.download`)}
  79. </button>
  80. </div>
  81. )}
  82. {onArchive && (
  83. <div className='flex items-center gap-x-0.5 px-3 py-2'>
  84. <RiArchive2Line className='h-4 w-4 text-components-button-ghost-text' />
  85. <button type='button' className='px-0.5 text-[13px] font-medium leading-[16px] text-components-button-ghost-text' onClick={onArchive}>
  86. {t(`${i18nPrefix}.archive`)}
  87. </button>
  88. </div>
  89. )}
  90. <div className='flex items-center gap-x-0.5 px-3 py-2'>
  91. <RiDeleteBinLine className='h-4 w-4 text-components-button-destructive-ghost-text' />
  92. <button type='button' className='px-0.5 text-[13px] font-medium leading-[16px] text-components-button-destructive-ghost-text' onClick={showDeleteConfirm}>
  93. {t(`${i18nPrefix}.delete`)}
  94. </button>
  95. </div>
  96. <Divider type='vertical' className='mx-0.5 h-3.5 bg-divider-regular' />
  97. <button type='button' className='px-3.5 py-2 text-[13px] font-medium leading-[16px] text-components-button-ghost-text' onClick={onCancel}>
  98. {t(`${i18nPrefix}.cancel`)}
  99. </button>
  100. </div>
  101. {
  102. isShowDeleteConfirm && (
  103. <Confirm
  104. isShow
  105. title={t('datasetDocuments.list.delete.title')}
  106. content={t('datasetDocuments.list.delete.content')}
  107. confirmText={t('common.operation.sure')}
  108. onConfirm={handleBatchDelete}
  109. onCancel={hideDeleteConfirm}
  110. isLoading={isDeleting}
  111. isDisabled={isDeleting}
  112. />
  113. )
  114. }
  115. </div>
  116. )
  117. }
  118. export default React.memo(BatchAction)