batch-action.tsx 4.7 KB

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