From 792f28451c6a492995abf3f8565baf56960f7ad4 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Thu, 7 Aug 2025 10:44:25 +0800 Subject: [PATCH] timeout new data structure --- .../nodes/human-input/components/timeout.tsx | 19 ++++++++++--------- .../workflow/nodes/human-input/default.ts | 6 ++---- .../workflow/nodes/human-input/panel.tsx | 1 + .../workflow/nodes/human-input/types.ts | 8 ++------ .../workflow/nodes/human-input/use-config.ts | 8 +++----- 5 files changed, 18 insertions(+), 24 deletions(-) diff --git a/web/app/components/workflow/nodes/human-input/components/timeout.tsx b/web/app/components/workflow/nodes/human-input/components/timeout.tsx index d40d3dcf42..5d700c36b2 100644 --- a/web/app/components/workflow/nodes/human-input/components/timeout.tsx +++ b/web/app/components/workflow/nodes/human-input/components/timeout.tsx @@ -1,19 +1,20 @@ import type { FC } from 'react' import React from 'react' import { useTranslation } from 'react-i18next' -import type { Timeout } from '../types' import Input from '@/app/components/base/input' import cn from '@/utils/classnames' const i18nPrefix = 'workflow.nodes.humanInput' type Props = { - timeout: Timeout - onChange: (state: Timeout) => void + timeout: number + unit: 'day' | 'hour' + onChange: (state: { timeout: number; unit: 'day' | 'hour' }) => void } const TimeoutInput: FC = ({ timeout, + unit, onChange, }) => { const { t } = useTranslation() @@ -22,26 +23,26 @@ const TimeoutInput: FC = ({ onChange({ ...timeout, value: Number(e.target.value) })} + onChange={e => onChange({ timeout: Number(e.target.value), unit })} />
onChange({ ...timeout, unit: 'days' })} + onClick={() => onChange({ timeout, unit: 'day' })} >
{t(`${i18nPrefix}.timeout.days`)}
onChange({ ...timeout, unit: 'hours' })} + onClick={() => onChange({ timeout, unit: 'hour' })} >
{t(`${i18nPrefix}.timeout.hours`)}
diff --git a/web/app/components/workflow/nodes/human-input/default.ts b/web/app/components/workflow/nodes/human-input/default.ts index a881e5f29f..a007a65a28 100644 --- a/web/app/components/workflow/nodes/human-input/default.ts +++ b/web/app/components/workflow/nodes/human-input/default.ts @@ -37,10 +37,8 @@ const nodeDefault: NodeDefault = { button_style: UserActionButtonType.Ghost, }, ], - timeout: { - value: 3, - unit: 'days', - }, + timeout: 3, + timeout_unit: 'day', }, getAvailablePrevNodes(isChatMode: boolean) { const nodes = isChatMode diff --git a/web/app/components/workflow/nodes/human-input/panel.tsx b/web/app/components/workflow/nodes/human-input/panel.tsx index dbb143e757..1a7096a23c 100644 --- a/web/app/components/workflow/nodes/human-input/panel.tsx +++ b/web/app/components/workflow/nodes/human-input/panel.tsx @@ -100,6 +100,7 @@ const Panel: FC> = ({
{t(`${i18nPrefix}.timeout.title`)}
diff --git a/web/app/components/workflow/nodes/human-input/types.ts b/web/app/components/workflow/nodes/human-input/types.ts index a51f537ab9..41c7a6a11e 100644 --- a/web/app/components/workflow/nodes/human-input/types.ts +++ b/web/app/components/workflow/nodes/human-input/types.ts @@ -4,15 +4,11 @@ export type HumanInputNodeType = CommonNodeType & { delivery_methods: DeliveryMethod[] form_content: any user_actions: UserAction[] - timeout: Timeout + timeout: number + timeout_unit: 'hour' | 'day' outputs: Variable[] } -export type Timeout = { - value: number - unit: 'hours' | 'days' -} - export enum DeliveryMethodType { WebApp = 'webapp', Email = 'email', diff --git a/web/app/components/workflow/nodes/human-input/use-config.ts b/web/app/components/workflow/nodes/human-input/use-config.ts index 31a341bc68..b58cb5139b 100644 --- a/web/app/components/workflow/nodes/human-input/use-config.ts +++ b/web/app/components/workflow/nodes/human-input/use-config.ts @@ -1,5 +1,5 @@ import produce from 'immer' -import type { DeliveryMethod, HumanInputNodeType, Timeout, UserAction } from './types' +import type { DeliveryMethod, HumanInputNodeType, UserAction } from './types' import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud' import { useNodesReadOnly, @@ -8,9 +8,6 @@ const useConfig = (id: string, payload: HumanInputNodeType) => { const { nodesReadOnly: readOnly } = useNodesReadOnly() const { inputs, setInputs } = useNodeCrud(id, payload) - // 1 check email address valid - // 2 use immer to handle delivery method configuration - const handleDeliveryMethodChange = (methods: DeliveryMethod[]) => { setInputs({ ...inputs, @@ -45,10 +42,11 @@ const useConfig = (id: string, payload: HumanInputNodeType) => { }) } - const handleTimeoutChange = (timeout: Timeout) => { + const handleTimeoutChange = ({ timeout, unit }: { timeout: number; unit: 'hour' | 'day' }) => { setInputs({ ...inputs, timeout, + timeout_unit: unit, }) }