mirror of
https://github.com/langgenius/dify.git
synced 2026-02-03 17:41:35 +08:00
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
63 lines
2.2 KiB
TypeScript
63 lines
2.2 KiB
TypeScript
import type { FC } from 'react'
|
|
import * as React from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import Input from '@/app/components/base/input'
|
|
import { cn } from '@/utils/classnames'
|
|
|
|
const i18nPrefix = 'nodes.humanInput'
|
|
|
|
type Props = {
|
|
timeout: number
|
|
unit: 'day' | 'hour'
|
|
onChange: (state: { timeout: number, unit: 'day' | 'hour' }) => void
|
|
}
|
|
|
|
const TimeoutInput: FC<Props> = ({
|
|
timeout,
|
|
unit,
|
|
onChange,
|
|
}) => {
|
|
const { t } = useTranslation()
|
|
|
|
const handleValueChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
const value = e.target.value
|
|
if (/^\d*$/.test(value))
|
|
onChange({ timeout: Number(value) || 1, unit })
|
|
else
|
|
onChange({ timeout: 1, unit })
|
|
}
|
|
return (
|
|
<div className="flex items-center gap-1">
|
|
<Input
|
|
wrapperClassName="w-16"
|
|
type="number"
|
|
value={timeout}
|
|
min={1}
|
|
onChange={handleValueChange}
|
|
/>
|
|
<div className="flex items-center gap-0.5 rounded-[10px] bg-components-segmented-control-bg-normal p-0.5">
|
|
<div
|
|
className={cn(
|
|
'cursor-pointer rounded-lg px-2 py-1 text-text-tertiary hover:bg-state-base-hover hover:text-text-secondary',
|
|
unit === 'day' && 'bg-components-segmented-control-item-active-bg text-text-accent-light-mode-only shadow-sm hover:bg-components-segmented-control-item-active-bg hover:text-text-accent-light-mode-only',
|
|
)}
|
|
onClick={() => onChange({ timeout, unit: 'day' })}
|
|
>
|
|
<div className="system-sm-medium p-0.5">{t(`${i18nPrefix}.timeout.days`, { ns: 'workflow' })}</div>
|
|
</div>
|
|
<div
|
|
className={cn(
|
|
'cursor-pointer rounded-lg px-2 py-1 text-text-tertiary hover:bg-state-base-hover hover:text-text-secondary',
|
|
unit === 'hour' && 'bg-components-segmented-control-item-active-bg text-text-accent-light-mode-only shadow-sm hover:bg-components-segmented-control-item-active-bg hover:text-text-accent-light-mode-only',
|
|
)}
|
|
onClick={() => onChange({ timeout, unit: 'hour' })}
|
|
>
|
|
<div className="system-sm-medium p-0.5">{t(`${i18nPrefix}.timeout.hours`, { ns: 'workflow' })}</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default TimeoutInput
|