mirror of
https://github.com/langgenius/dify.git
synced 2026-01-29 15:13:53 +08:00
Signed-off-by: -LAN- <laipz8200@outlook.com> Co-authored-by: twwu <twwu@dify.ai> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: jyong <718720800@qq.com> Co-authored-by: Wu Tianwei <30284043+WTW0313@users.noreply.github.com> Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com> Co-authored-by: lyzno1 <yuanyouhuilyz@gmail.com> Co-authored-by: quicksand <quicksandzn@gmail.com> Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com> Co-authored-by: lyzno1 <92089059+lyzno1@users.noreply.github.com> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: nite-knite <nkCoding@gmail.com> Co-authored-by: Hanqing Zhao <sherry9277@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Harry <xh001x@hotmail.com>
131 lines
4.1 KiB
TypeScript
131 lines
4.1 KiB
TypeScript
import React, { type FC } from 'react'
|
|
import { RiArchive2Line, RiCheckboxCircleLine, RiCloseCircleLine, RiDeleteBinLine, RiDraftLine } from '@remixicon/react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import { useBoolean } from 'ahooks'
|
|
import Divider from '@/app/components/base/divider'
|
|
import cn from '@/utils/classnames'
|
|
import Confirm from '@/app/components/base/confirm'
|
|
import Button from '@/app/components/base/button'
|
|
|
|
const i18nPrefix = 'dataset.batchAction'
|
|
type IBatchActionProps = {
|
|
className?: string
|
|
selectedIds: string[]
|
|
onBatchEnable: () => void
|
|
onBatchDisable: () => void
|
|
onBatchDelete: () => Promise<void>
|
|
onArchive?: () => void
|
|
onEditMetadata?: () => void
|
|
onCancel: () => void
|
|
}
|
|
|
|
const BatchAction: FC<IBatchActionProps> = ({
|
|
className,
|
|
selectedIds,
|
|
onBatchEnable,
|
|
onBatchDisable,
|
|
onArchive,
|
|
onBatchDelete,
|
|
onEditMetadata,
|
|
onCancel,
|
|
}) => {
|
|
const { t } = useTranslation()
|
|
const [isShowDeleteConfirm, {
|
|
setTrue: showDeleteConfirm,
|
|
setFalse: hideDeleteConfirm,
|
|
}] = useBoolean(false)
|
|
const [isDeleting, {
|
|
setTrue: setIsDeleting,
|
|
}] = useBoolean(false)
|
|
|
|
const handleBatchDelete = async () => {
|
|
setIsDeleting()
|
|
await onBatchDelete()
|
|
hideDeleteConfirm()
|
|
}
|
|
return (
|
|
<div className={cn('flex w-full justify-center gap-x-2', className)}>
|
|
<div className='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'>
|
|
<div className='inline-flex items-center gap-x-2 py-1 pl-2 pr-3'>
|
|
<span className='system-xs-medium flex h-5 w-5 items-center justify-center rounded-md bg-text-accent text-text-primary-on-surface'>
|
|
{selectedIds.length}
|
|
</span>
|
|
<span className='system-sm-semibold text-text-accent'>{t(`${i18nPrefix}.selected`)}</span>
|
|
</div>
|
|
<Divider type='vertical' className='mx-0.5 h-3.5 bg-divider-regular' />
|
|
<Button
|
|
variant='ghost'
|
|
className='gap-x-0.5 px-3'
|
|
onClick={onBatchEnable}
|
|
>
|
|
<RiCheckboxCircleLine className='size-4' />
|
|
<span className='px-0.5'>{t(`${i18nPrefix}.enable`)}</span>
|
|
</Button>
|
|
<Button
|
|
variant='ghost'
|
|
className='gap-x-0.5 px-3'
|
|
onClick={onBatchDisable}
|
|
>
|
|
<RiCloseCircleLine className='size-4' />
|
|
<span className='px-0.5'>{t(`${i18nPrefix}.disable`)}</span>
|
|
</Button>
|
|
{onEditMetadata && (
|
|
<Button
|
|
variant='ghost'
|
|
className='gap-x-0.5 px-3'
|
|
onClick={onEditMetadata}
|
|
>
|
|
<RiDraftLine className='size-4' />
|
|
<span className='px-0.5'>{t('dataset.metadata.metadata')}</span>
|
|
</Button>
|
|
)}
|
|
|
|
{onArchive && (
|
|
<Button
|
|
variant='ghost'
|
|
className='gap-x-0.5 px-3'
|
|
onClick={onArchive}
|
|
>
|
|
<RiArchive2Line className='size-4' />
|
|
<span className='px-0.5'>{t(`${i18nPrefix}.archive`)}</span>
|
|
</Button>
|
|
)}
|
|
<Button
|
|
variant='ghost'
|
|
destructive
|
|
className='gap-x-0.5 px-3'
|
|
onClick={showDeleteConfirm}
|
|
>
|
|
<RiDeleteBinLine className='size-4' />
|
|
<span className='px-0.5'>{t(`${i18nPrefix}.delete`)}</span>
|
|
</Button>
|
|
|
|
<Divider type='vertical' className='mx-0.5 h-3.5 bg-divider-regular' />
|
|
<Button
|
|
variant='ghost'
|
|
className='px-3'
|
|
onClick={onCancel}
|
|
>
|
|
<span className='px-0.5'>{t(`${i18nPrefix}.cancel`)}</span>
|
|
</Button>
|
|
</div>
|
|
{
|
|
isShowDeleteConfirm && (
|
|
<Confirm
|
|
isShow
|
|
title={t('datasetDocuments.list.delete.title')}
|
|
content={t('datasetDocuments.list.delete.content')}
|
|
confirmText={t('common.operation.sure')}
|
|
onConfirm={handleBatchDelete}
|
|
onCancel={hideDeleteConfirm}
|
|
isLoading={isDeleting}
|
|
isDisabled={isDeleting}
|
|
/>
|
|
)
|
|
}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default React.memo(BatchAction)
|