Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor(web): migrate HTTP timeout inputs (#40953)

yyh297fdc7cb852
diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json
index 0bfb65d1eb8..ff3bb9e8481 100644
--- a/oxlint-suppressions.json
+++ b/oxlint-suppressions.json
@@ -4004,11 +4004,6 @@
"count": 1
}
},
- "web/app/components/workflow/nodes/http/components/timeout/index.tsx": {
- "no-restricted-imports": {
- "count": 1
- }
- },
"web/app/components/workflow/nodes/http/panel.tsx": {
"jsx-a11y/click-events-have-key-events": {
"count": 2
diff --git a/web/app/components/workflow/nodes/http/components/timeout/index.spec.tsx b/web/app/components/workflow/nodes/http/components/timeout/index.spec.tsx
new file mode 100644
index 00000000000..9a2422e48de
--- /dev/null
+++ b/web/app/components/workflow/nodes/http/components/timeout/index.spec.tsx
@@ -0,0 +1,93 @@
+import type { ReactNode } from 'react'
+import type { Timeout as TimeoutPayload } from '../../types'
+import { render, screen } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
+import { useState } from 'react'
+import { withSelectorKey } from '@/test/i18n-mock'
+import Timeout from './index'
+
+vi.mock('react-i18next', () => ({
+ useTranslation: () => ({
+ t: withSelectorKey((key: string) => key),
+ }),
+}))
+
+vi.mock('@/app/components/workflow/store', () => ({
+ useStore: (selector: (state: { nodesDefaultConfigs: object }) => unknown) =>
+ selector({ nodesDefaultConfigs: {} }),
+}))
+
+vi.mock('@/app/components/workflow/nodes/_base/components/collapse', () => ({
+ FieldCollapse: ({ children, title }: { children: ReactNode; title: string }) => (
+ <section aria-label={title}>{children}</section>
+ ),
+}))
+
+type TimeoutHarnessProps = {
+ onChange: (payload: TimeoutPayload) => void
+ readonly?: boolean
+}
+
+function TimeoutHarness({ onChange, readonly = false }: TimeoutHarnessProps) {
+ const [payload, setPayload] = useState<TimeoutPayload>({ connect: 5, read: 10, write: 15 })
+
+ return (
+ <Timeout
+ readonly={readonly}
+ nodeId="http-node"
+ payload={payload}
+ onChange={(nextPayload) => {
+ setPayload(nextPayload)
+ onChange(nextPayload)
+ }}
+ />
+ )
+}
+
+describe('HTTP timeout fields', () => {
+ it('associates every timeout with its visible label and description', () => {
+ render(<TimeoutHarness onChange={vi.fn()} />)
+
+ const connectInput = screen.getByRole('textbox', {
+ name: 'nodes.http.timeout.connectLabel',
+ })
+ const readInput = screen.getByRole('textbox', { name: 'nodes.http.timeout.readLabel' })
+ const writeInput = screen.getByRole('textbox', { name: 'nodes.http.timeout.writeLabel' })
+
+ expect(connectInput).toHaveAccessibleDescription('nodes.http.timeout.connectPlaceholder')
+ expect(readInput).toHaveAccessibleDescription('nodes.http.timeout.readPlaceholder')
+ expect(writeInput).toHaveAccessibleDescription('nodes.http.timeout.writePlaceholder')
+ })
+
+ it('stores integer values and maps an empty field to the backend default', async () => {
+ const user = userEvent.setup()
+ const onChange = vi.fn()
+ render(<TimeoutHarness onChange={onChange} />)
+ const connectInput = screen.getByRole('textbox', {
+ name: 'nodes.http.timeout.connectLabel',
+ })
+
+ await user.clear(connectInput)
+
+ expect(onChange).toHaveBeenLastCalledWith({ connect: undefined, read: 10, write: 15 })
+
+ await user.type(connectInput, '8.9')
+
+ expect(onChange).toHaveBeenLastCalledWith({ connect: 9, read: 10, write: 15 })
+ })
+
+ it('does not update read-only timeout fields', async () => {
+ const user = userEvent.setup()
+ const onChange = vi.fn()
+ render(<TimeoutHarness readonly onChange={onChange} />)
+ const connectInput = screen.getByRole('textbox', {
+ name: 'nodes.http.timeout.connectLabel',
+ })
+
+ expect(connectInput).toHaveAttribute('readonly')
+
+ await user.type(connectInput, '8')
+
+ expect(onChange).not.toHaveBeenCalled()
+ })
+})
diff --git a/web/app/components/workflow/nodes/http/components/timeout/index.tsx b/web/app/components/workflow/nodes/http/components/timeout/index.tsx
index 88cb805aeb5..b5f3ec19c32 100644
--- a/web/app/components/workflow/nodes/http/components/timeout/index.tsx
+++ b/web/app/components/workflow/nodes/http/components/timeout/index.tsx
@@ -1,9 +1,10 @@
'use client'
import type { FC } from 'react'
import type { Timeout as TimeoutPayloadType } from '../../types'
+import { Field, FieldDescription, FieldLabel } from '@langgenius/dify-ui/field'
+import { NumberField, NumberFieldGroup, NumberFieldInput } from '@langgenius/dify-ui/number-field'
import * as React from 'react'
import { useTranslation } from 'react-i18next'
-import Input from '@/app/components/base/input'
import { FieldCollapse } from '@/app/components/workflow/nodes/_base/components/collapse'
import { useStore } from '@/app/components/workflow/store'
import { BlockEnum } from '@/app/components/workflow/types'
@@ -28,33 +29,26 @@ const InputField: FC<{
max: number
}> = ({ title, description, placeholder, value, onChange, readOnly, min, max }) => {
return (
- <div className="space-y-1">
+ <Field>
<div className="flex h-4.5 items-center space-x-2">
- <span className="text-[13px] font-medium text-text-primary">{title}</span>
- <span className="text-xs font-normal text-text-tertiary">{description}</span>
+ <FieldLabel className="p-0 text-[13px] font-medium text-text-primary">{title}</FieldLabel>
+ <FieldDescription className="p-0 text-xs font-normal text-text-tertiary">
+ {description}
+ </FieldDescription>
</div>
- <Input
- type="number"
- value={value}
- onChange={(e) => {
- const inputValue = e.target.value
- if (inputValue === '') {
- // When user clears the input, set to undefined to let backend use default values
- onChange(undefined)
- } else {
- const parsedValue = Number.parseInt(inputValue, 10)
- if (!Number.isNaN(parsedValue)) {
- const value = Math.max(min, Math.min(max, parsedValue))
- onChange(value)
- }
- }
- }}
- placeholder={placeholder}
- readOnly={readOnly}
+ <NumberField
+ value={value ?? null}
min={min}
max={max}
- />
- </div>
+ format={{ maximumFractionDigits: 0 }}
+ readOnly={readOnly}
+ onValueChange={(nextValue) => onChange(nextValue ?? undefined)}
+ >
+ <NumberFieldGroup>
+ <NumberFieldInput placeholder={placeholder} />
+ </NumberFieldGroup>
+ </NumberField>
+ </Field>
)
}