index.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import { useBoolean } from 'ahooks'
  6. import type { Timeout as TimeoutPayloadType } from '../../types'
  7. import cn from '@/utils/classnames'
  8. import { ChevronRight } from '@/app/components/base/icons/src/vender/line/arrows'
  9. type Props = {
  10. readonly: boolean
  11. nodeId: string
  12. payload: TimeoutPayloadType
  13. onChange: (payload: TimeoutPayloadType) => void
  14. }
  15. const i18nPrefix = 'workflow.nodes.http'
  16. const InputField: FC<{
  17. title: string
  18. description: string
  19. placeholder: string
  20. value?: number
  21. onChange: (value: number) => void
  22. readOnly?: boolean
  23. min: number
  24. max: number
  25. }> = ({ title, description, placeholder, value, onChange, readOnly, min, max }) => {
  26. return (
  27. <div className="space-y-1">
  28. <div className="flex items-center h-[18px] space-x-2">
  29. <span className="text-[13px] font-medium text-gray-900">{title}</span>
  30. <span className="text-xs font-normal text-gray-500">{description}</span>
  31. </div>
  32. <input className="w-full px-3 text-sm leading-9 text-gray-900 border-0 rounded-lg grow h-9 bg-gray-100 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-gray-200" value={value} onChange={(e) => {
  33. const value = Math.max(min, Math.min(max, parseInt(e.target.value, 10)))
  34. onChange(value)
  35. }} placeholder={placeholder} type='number' readOnly={readOnly} min={min} max={max} />
  36. </div>
  37. )
  38. }
  39. const Timeout: FC<Props> = ({ readonly, payload, onChange }) => {
  40. const { t } = useTranslation()
  41. const { connect, read, write, max_connect_timeout, max_read_timeout, max_write_timeout } = payload ?? {}
  42. const [isFold, {
  43. toggle: toggleFold,
  44. }] = useBoolean(true)
  45. return (
  46. <>
  47. <div>
  48. <div
  49. onClick={toggleFold}
  50. className={cn('flex justify-between leading-[18px] text-[13px] font-semibold text-gray-700 uppercase cursor-pointer')}>
  51. <div>{t(`${i18nPrefix}.timeout.title`)}</div>
  52. <ChevronRight className='w-4 h-4 text-gray-500 transform transition-transform' style={{ transform: isFold ? 'rotate(0deg)' : 'rotate(90deg)' }} />
  53. </div>
  54. {!isFold && (
  55. <div className='mt-2 space-y-1'>
  56. <div className="space-y-3">
  57. <InputField
  58. title={t('workflow.nodes.http.timeout.connectLabel')!}
  59. description={t('workflow.nodes.http.timeout.connectPlaceholder')!}
  60. placeholder={t('workflow.nodes.http.timeout.connectPlaceholder')!}
  61. readOnly={readonly}
  62. value={connect}
  63. onChange={v => onChange?.({ ...payload, connect: v })}
  64. min={1}
  65. max={max_connect_timeout || 300}
  66. />
  67. <InputField
  68. title={t('workflow.nodes.http.timeout.readLabel')!}
  69. description={t('workflow.nodes.http.timeout.readPlaceholder')!}
  70. placeholder={t('workflow.nodes.http.timeout.readPlaceholder')!}
  71. readOnly={readonly}
  72. value={read}
  73. onChange={v => onChange?.({ ...payload, read: v })}
  74. min={1}
  75. max={max_read_timeout || 600}
  76. />
  77. <InputField
  78. title={t('workflow.nodes.http.timeout.writeLabel')!}
  79. description={t('workflow.nodes.http.timeout.writePlaceholder')!}
  80. placeholder={t('workflow.nodes.http.timeout.writePlaceholder')!}
  81. readOnly={readonly}
  82. value={write}
  83. onChange={v => onChange?.({ ...payload, write: v })}
  84. min={1}
  85. max={max_write_timeout || 600}
  86. />
  87. </div>
  88. </div>
  89. )}
  90. </div>
  91. </>
  92. )
  93. }
  94. export default React.memo(Timeout)