mirror of
https://github.com/langgenius/dify.git
synced 2025-12-16 12:42:31 +00: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>
91 lines
2.6 KiB
TypeScript
91 lines
2.6 KiB
TypeScript
import React, { useMemo } from 'react'
|
|
import Button from '@/app/components/base/button'
|
|
import { useTranslation } from 'react-i18next'
|
|
import { useParams } from 'next/navigation'
|
|
import { RiArrowRightLine } from '@remixicon/react'
|
|
import Link from 'next/link'
|
|
import Checkbox from '@/app/components/base/checkbox'
|
|
|
|
type ActionsProps = {
|
|
disabled?: boolean
|
|
handleNextStep: () => void
|
|
showSelect?: boolean
|
|
totalOptions?: number
|
|
selectedOptions?: number
|
|
onSelectAll?: () => void
|
|
tip?: string
|
|
}
|
|
|
|
const Actions = ({
|
|
disabled,
|
|
handleNextStep,
|
|
showSelect = false,
|
|
totalOptions,
|
|
selectedOptions,
|
|
onSelectAll,
|
|
tip = '',
|
|
}: ActionsProps) => {
|
|
const { t } = useTranslation()
|
|
const { datasetId } = useParams()
|
|
|
|
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])
|
|
|
|
return (
|
|
<div className='flex items-center gap-x-2 overflow-hidden'>
|
|
{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 title={tip} className='system-xs-regular max-w-full truncate 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>
|
|
<Button
|
|
disabled={disabled}
|
|
variant='primary'
|
|
onClick={handleNextStep}
|
|
className='gap-x-0.5'
|
|
>
|
|
<span className='px-0.5'>{t('datasetCreation.stepOne.button')}</span>
|
|
<RiArrowRightLine className='size-4' />
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default React.memo(Actions)
|