batch-action.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import React, { type FC } from 'react'
  2. import { RiArchive2Line, RiCheckboxCircleLine, RiCloseCircleLine, RiDeleteBinLine } 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. onCancel: () => void
  17. }
  18. const BatchAction: FC<IBatchActionProps> = ({
  19. className,
  20. selectedIds,
  21. onBatchEnable,
  22. onBatchDisable,
  23. onArchive,
  24. onBatchDelete,
  25. onCancel,
  26. }) => {
  27. const { t } = useTranslation()
  28. const [isShowDeleteConfirm, {
  29. setTrue: showDeleteConfirm,
  30. setFalse: hideDeleteConfirm,
  31. }] = useBoolean(false)
  32. const [isDeleting, {
  33. setTrue: setIsDeleting,
  34. }] = useBoolean(false)
  35. const handleBatchDelete = async () => {
  36. setIsDeleting()
  37. await onBatchDelete()
  38. hideDeleteConfirm()
  39. }
  40. return (
  41. <div className={classNames('w-full flex justify-center gap-x-2', className)}>
  42. <div className='flex items-center gap-x-1 p-1 rounded-[10px] bg-components-actionbar-bg-accent border border-components-actionbar-border-accent shadow-xl shadow-shadow-shadow-5 backdrop-blur-[5px]'>
  43. <div className='inline-flex items-center gap-x-2 pl-2 pr-3 py-1'>
  44. <span className='w-5 h-5 flex items-center justify-center px-1 py-0.5 bg-text-accent rounded-md text-text-primary-on-surface text-xs font-medium'>
  45. {selectedIds.length}
  46. </span>
  47. <span className='text-text-accent text-[13px] font-semibold leading-[16px]'>{t(`${i18nPrefix}.selected`)}</span>
  48. </div>
  49. <Divider type='vertical' className='mx-0.5 h-3.5 bg-divider-regular' />
  50. <div className='flex items-center gap-x-0.5 px-3 py-2'>
  51. <RiCheckboxCircleLine className='w-4 h-4 text-components-button-ghost-text' />
  52. <button type='button' className='px-0.5 text-components-button-ghost-text text-[13px] font-medium leading-[16px]' onClick={onBatchEnable}>
  53. {t(`${i18nPrefix}.enable`)}
  54. </button>
  55. </div>
  56. <div className='flex items-center gap-x-0.5 px-3 py-2'>
  57. <RiCloseCircleLine className='w-4 h-4 text-components-button-ghost-text' />
  58. <button type='button' className='px-0.5 text-components-button-ghost-text text-[13px] font-medium leading-[16px]' onClick={onBatchDisable}>
  59. {t(`${i18nPrefix}.disable`)}
  60. </button>
  61. </div>
  62. {onArchive && (
  63. <div className='flex items-center gap-x-0.5 px-3 py-2'>
  64. <RiArchive2Line className='w-4 h-4 text-components-button-ghost-text' />
  65. <button type='button' className='px-0.5 text-components-button-ghost-text text-[13px] font-medium leading-[16px]' onClick={onArchive}>
  66. {t(`${i18nPrefix}.archive`)}
  67. </button>
  68. </div>
  69. )}
  70. <div className='flex items-center gap-x-0.5 px-3 py-2'>
  71. <RiDeleteBinLine className='w-4 h-4 text-components-button-destructive-ghost-text' />
  72. <button type='button' className='px-0.5 text-components-button-destructive-ghost-text text-[13px] font-medium leading-[16px]' onClick={showDeleteConfirm}>
  73. {t(`${i18nPrefix}.delete`)}
  74. </button>
  75. </div>
  76. <Divider type='vertical' className='mx-0.5 h-3.5 bg-divider-regular' />
  77. <button type='button' className='px-3.5 py-2 text-components-button-ghost-text text-[13px] font-medium leading-[16px]' onClick={onCancel}>
  78. {t(`${i18nPrefix}.cancel`)}
  79. </button>
  80. </div>
  81. {
  82. isShowDeleteConfirm && (
  83. <Confirm
  84. isShow
  85. title={t('datasetDocuments.list.delete.title')}
  86. content={t('datasetDocuments.list.delete.content')}
  87. confirmText={t('common.operation.sure')}
  88. onConfirm={handleBatchDelete}
  89. onCancel={hideDeleteConfirm}
  90. isLoading={isDeleting}
  91. isDisabled={isDeleting}
  92. />
  93. )
  94. }
  95. </div>
  96. )
  97. }
  98. export default React.memo(BatchAction)