mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-19 19:59:10 +08:00
feat: max number with slider
This commit is contained in:
parent
77d0aac1d3
commit
fca5af5073
@ -2,10 +2,12 @@
|
|||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React, { useCallback } from 'react'
|
import React, { useCallback } from 'react'
|
||||||
import produce from 'immer'
|
import produce from 'immer'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
import type { UploadFileSetting } from '../../../types'
|
import type { UploadFileSetting } from '../../../types'
|
||||||
import { SupportUploadFileTypes } from '../../../types'
|
import { SupportUploadFileTypes } from '../../../types'
|
||||||
import OptionCard from './option-card'
|
import OptionCard from './option-card'
|
||||||
import FileTypeItem from './file-type-item'
|
import FileTypeItem from './file-type-item'
|
||||||
|
import InputNumberWithSlider from './input-number-with-slider'
|
||||||
import Field from '@/app/components/app/configuration/config-var/config-modal/field'
|
import Field from '@/app/components/app/configuration/config-var/config-modal/field'
|
||||||
import { TransferMethod } from '@/types/app'
|
import { TransferMethod } from '@/types/app'
|
||||||
|
|
||||||
@ -20,6 +22,8 @@ const FileUploadSetting: FC<Props> = ({
|
|||||||
isMultiple,
|
isMultiple,
|
||||||
onChange,
|
onChange,
|
||||||
}) => {
|
}) => {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
uploadMethod,
|
uploadMethod,
|
||||||
maxUploadNumLimit,
|
maxUploadNumLimit,
|
||||||
@ -54,6 +58,13 @@ const FileUploadSetting: FC<Props> = ({
|
|||||||
onChange(newPayload)
|
onChange(newPayload)
|
||||||
}, [onChange, payload])
|
}, [onChange, payload])
|
||||||
|
|
||||||
|
const handleMaxUploadNumLimitChange = useCallback((value: number) => {
|
||||||
|
const newPayload = produce(payload, (draft) => {
|
||||||
|
draft.maxUploadNumLimit = value
|
||||||
|
})
|
||||||
|
onChange(newPayload)
|
||||||
|
}, [onChange, payload])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Field
|
<Field
|
||||||
@ -103,10 +114,17 @@ const FileUploadSetting: FC<Props> = ({
|
|||||||
</Field>
|
</Field>
|
||||||
{isMultiple && (
|
{isMultiple && (
|
||||||
<Field
|
<Field
|
||||||
title='Max number of uploads'
|
className='mt-4'
|
||||||
|
title={t('appDebug.variableConig.maxNumberOfUploads')!}
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<span>Max number of uploads</span>
|
<div className='mb-1.5 text-text-tertiary body-xs-regular'>{t('appDebug.variableConig.maxNumberTip')}</div>
|
||||||
|
<InputNumberWithSlider
|
||||||
|
value={maxUploadNumLimit || 1}
|
||||||
|
min={1}
|
||||||
|
max={10}
|
||||||
|
onChange={handleMaxUploadNumLimitChange}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
'use client'
|
||||||
|
import type { FC } from 'react'
|
||||||
|
import React, { useCallback } from 'react'
|
||||||
|
import Slider from '@/app/components/base/slider'
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
value: number
|
||||||
|
defaultValue?: number
|
||||||
|
min?: number
|
||||||
|
max?: number
|
||||||
|
readonly?: boolean
|
||||||
|
onChange: (value: number) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const InputNumberWithSlider: FC<Props> = ({
|
||||||
|
value,
|
||||||
|
defaultValue = 0,
|
||||||
|
min,
|
||||||
|
max,
|
||||||
|
readonly,
|
||||||
|
onChange,
|
||||||
|
}) => {
|
||||||
|
const handleBlur = useCallback(() => {
|
||||||
|
if (value === undefined || value === null)
|
||||||
|
onChange(defaultValue)
|
||||||
|
}, [defaultValue, onChange, value])
|
||||||
|
|
||||||
|
const handleChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
onChange(parseFloat(e.target.value))
|
||||||
|
}, [onChange])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='flex justify-between items-center h-8 space-x-2'>
|
||||||
|
<input
|
||||||
|
value={value}
|
||||||
|
className='shrink-0 block pl-3 w-12 h-8 appearance-none outline-none rounded-lg bg-gray-100 text-[13px] text-gra-900'
|
||||||
|
type='number'
|
||||||
|
min={min}
|
||||||
|
max={max}
|
||||||
|
step={1}
|
||||||
|
onChange={handleChange}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
disabled={readonly}
|
||||||
|
/>
|
||||||
|
<Slider
|
||||||
|
className='grow'
|
||||||
|
value={value}
|
||||||
|
min={min}
|
||||||
|
max={max}
|
||||||
|
step={1}
|
||||||
|
onChange={onChange}
|
||||||
|
disabled={readonly}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
export default React.memo(InputNumberWithSlider)
|
@ -343,6 +343,8 @@ const translation = {
|
|||||||
createPlaceholder: 'File extension, e.g .doc',
|
createPlaceholder: 'File extension, e.g .doc',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
'maxNumberOfUploads': 'Max number of uploads',
|
||||||
|
'maxNumberTip': 'Max 15MB each',
|
||||||
'errorMsg': {
|
'errorMsg': {
|
||||||
varNameRequired: 'Variable name is required',
|
varNameRequired: 'Variable name is required',
|
||||||
labelNameRequired: 'Label name is required',
|
labelNameRequired: 'Label name is required',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user