2025-07-08 14:14:50 +08:00
|
|
|
import React, { useMemo } from 'react'
|
2025-05-22 14:49:40 +08:00
|
|
|
import Button from '@/app/components/base/button'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { useParams } from 'next/navigation'
|
|
|
|
import { RiArrowRightLine } from '@remixicon/react'
|
2025-05-29 17:42:00 +08:00
|
|
|
import Link from 'next/link'
|
2025-07-08 14:14:50 +08:00
|
|
|
import Checkbox from '@/app/components/base/checkbox'
|
2025-05-22 14:49:40 +08:00
|
|
|
|
|
|
|
type ActionsProps = {
|
|
|
|
disabled?: boolean
|
|
|
|
handleNextStep: () => void
|
2025-07-01 16:32:21 +08:00
|
|
|
showSelect?: boolean
|
2025-07-08 14:14:50 +08:00
|
|
|
totalOptions?: number
|
|
|
|
selectedOptions?: number
|
|
|
|
onSelectAll?: () => void
|
|
|
|
tip?: string
|
2025-05-22 14:49:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const Actions = ({
|
|
|
|
disabled,
|
|
|
|
handleNextStep,
|
2025-07-08 14:14:50 +08:00
|
|
|
showSelect = false,
|
|
|
|
totalOptions,
|
|
|
|
selectedOptions,
|
|
|
|
onSelectAll,
|
|
|
|
tip = '',
|
2025-05-22 14:49:40 +08:00
|
|
|
}: ActionsProps) => {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const { datasetId } = useParams()
|
|
|
|
|
2025-07-08 14:14:50 +08:00
|
|
|
const indeterminate = useMemo(() => {
|
|
|
|
if (!showSelect) return false
|
|
|
|
if (selectedOptions === undefined || totalOptions === undefined) return false
|
|
|
|
return selectedOptions > 0 && selectedOptions < totalOptions
|
|
|
|
}, [showSelect, selectedOptions, totalOptions])
|
|
|
|
|
|
|
|
const checked = useMemo(() => {
|
|
|
|
if (!showSelect) return false
|
|
|
|
if (selectedOptions === undefined || totalOptions === undefined) return false
|
|
|
|
return selectedOptions > 0 && selectedOptions === totalOptions
|
|
|
|
}, [showSelect, selectedOptions, totalOptions])
|
|
|
|
|
2025-05-22 14:49:40 +08:00
|
|
|
return (
|
2025-07-08 14:14:50 +08:00
|
|
|
<div className='flex items-center gap-x-2'>
|
|
|
|
{showSelect && (
|
|
|
|
<>
|
|
|
|
<div className='flex shrink-0 items-center gap-x-2 py-[3px] pl-4 pr-2'>
|
|
|
|
<Checkbox
|
|
|
|
onCheck={onSelectAll}
|
|
|
|
indeterminate={indeterminate}
|
|
|
|
checked={checked}
|
|
|
|
/>
|
|
|
|
<span className='system-sm-medium text-text-accent'>
|
|
|
|
{t('common.operation.selectAll')}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
{tip && (
|
|
|
|
<div className='system-xs-regular shrink-0 text-text-tertiary'>
|
|
|
|
{tip}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
<div className='flex grow items-center justify-end gap-x-2'>
|
|
|
|
<Link
|
|
|
|
href={`/datasets/${datasetId}/documents`}
|
|
|
|
replace
|
|
|
|
>
|
|
|
|
<Button
|
|
|
|
variant='ghost'
|
|
|
|
className='px-3 py-2'
|
|
|
|
>
|
|
|
|
{t('common.operation.cancel')}
|
|
|
|
</Button>
|
|
|
|
</Link>
|
2025-05-22 14:49:40 +08:00
|
|
|
<Button
|
2025-07-08 14:14:50 +08:00
|
|
|
disabled={disabled}
|
|
|
|
variant='primary'
|
|
|
|
onClick={handleNextStep}
|
|
|
|
className='gap-x-0.5'
|
2025-05-22 14:49:40 +08:00
|
|
|
>
|
2025-07-08 14:14:50 +08:00
|
|
|
<span className='px-0.5'>{t('datasetCreation.stepOne.button')}</span>
|
|
|
|
<RiArrowRightLine className='size-4' />
|
2025-05-22 14:49:40 +08:00
|
|
|
</Button>
|
2025-07-08 14:14:50 +08:00
|
|
|
</div>
|
2025-05-22 14:49:40 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default React.memo(Actions)
|