You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

panel.tsx 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import type { FC } from 'react'
  2. import { memo } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import useConfig from './use-config'
  5. import ApiInput from './components/api-input'
  6. import KeyValue from './components/key-value'
  7. import EditBody from './components/edit-body'
  8. import AuthorizationModal from './components/authorization'
  9. import type { HttpNodeType } from './types'
  10. import Timeout from './components/timeout'
  11. import CurlPanel from './components/curl-panel'
  12. import cn from '@/utils/classnames'
  13. import Switch from '@/app/components/base/switch'
  14. import Field from '@/app/components/workflow/nodes/_base/components/field'
  15. import Split from '@/app/components/workflow/nodes/_base/components/split'
  16. import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
  17. import { Settings01 } from '@/app/components/base/icons/src/vender/line/general'
  18. import { FileArrow01 } from '@/app/components/base/icons/src/vender/line/files'
  19. import type { NodePanelProps } from '@/app/components/workflow/types'
  20. const i18nPrefix = 'workflow.nodes.http'
  21. const Panel: FC<NodePanelProps<HttpNodeType>> = ({
  22. id,
  23. data,
  24. }) => {
  25. const { t } = useTranslation()
  26. const {
  27. readOnly,
  28. isDataReady,
  29. inputs,
  30. handleMethodChange,
  31. handleUrlChange,
  32. headers,
  33. setHeaders,
  34. addHeader,
  35. params,
  36. setParams,
  37. addParam,
  38. setBody,
  39. isShowAuthorization,
  40. showAuthorization,
  41. hideAuthorization,
  42. setAuthorization,
  43. setTimeout,
  44. isShowCurlPanel,
  45. showCurlPanel,
  46. hideCurlPanel,
  47. handleCurlImport,
  48. handleSSLVerifyChange,
  49. } = useConfig(id, data)
  50. // To prevent prompt editor in body not update data.
  51. if (!isDataReady)
  52. return null
  53. return (
  54. <div className='pt-2'>
  55. <div className='space-y-4 px-4 pb-4'>
  56. <Field
  57. title={t(`${i18nPrefix}.api`)}
  58. required
  59. operations={
  60. <div className='flex'>
  61. <div
  62. onClick={showAuthorization}
  63. className={cn(!readOnly && 'cursor-pointer hover:bg-state-base-hover', 'flex h-6 items-center space-x-1 rounded-md px-2 ')}
  64. >
  65. {!readOnly && <Settings01 className='h-3 w-3 text-text-tertiary' />}
  66. <div className='text-xs font-medium text-text-tertiary'>
  67. {t(`${i18nPrefix}.authorization.authorization`)}
  68. <span className='ml-1 text-text-secondary'>{t(`${i18nPrefix}.authorization.${inputs.authorization.type}`)}</span>
  69. </div>
  70. </div>
  71. <div
  72. onClick={showCurlPanel}
  73. className={cn(!readOnly && 'cursor-pointer hover:bg-state-base-hover', 'flex h-6 items-center space-x-1 rounded-md px-2 ')}
  74. >
  75. {!readOnly && <FileArrow01 className='h-3 w-3 text-text-tertiary' />}
  76. <div className='text-xs font-medium text-text-tertiary'>
  77. {t(`${i18nPrefix}.curl.title`)}
  78. </div>
  79. </div>
  80. </div>
  81. }
  82. >
  83. <ApiInput
  84. nodeId={id}
  85. readonly={readOnly}
  86. method={inputs.method}
  87. onMethodChange={handleMethodChange}
  88. url={inputs.url}
  89. onUrlChange={handleUrlChange}
  90. />
  91. </Field>
  92. <Field
  93. title={t(`${i18nPrefix}.headers`)}
  94. >
  95. <KeyValue
  96. nodeId={id}
  97. list={headers}
  98. onChange={setHeaders}
  99. onAdd={addHeader}
  100. readonly={readOnly}
  101. />
  102. </Field>
  103. <Field
  104. title={t(`${i18nPrefix}.params`)}
  105. >
  106. <KeyValue
  107. nodeId={id}
  108. list={params}
  109. onChange={setParams}
  110. onAdd={addParam}
  111. readonly={readOnly}
  112. />
  113. </Field>
  114. <Field
  115. title={t(`${i18nPrefix}.body`)}
  116. required
  117. >
  118. <EditBody
  119. nodeId={id}
  120. readonly={readOnly}
  121. payload={inputs.body}
  122. onChange={setBody}
  123. />
  124. </Field>
  125. <Field
  126. title={t(`${i18nPrefix}.verifySSL.title`)}
  127. tooltip={t(`${i18nPrefix}.verifySSL.warningTooltip`)}
  128. operations={
  129. <Switch
  130. defaultValue={!!inputs.ssl_verify}
  131. onChange={handleSSLVerifyChange}
  132. size='md'
  133. disabled={readOnly}
  134. />
  135. }>
  136. </Field>
  137. </div>
  138. <Split />
  139. <Timeout
  140. nodeId={id}
  141. readonly={readOnly}
  142. payload={inputs.timeout}
  143. onChange={setTimeout}
  144. />
  145. {(isShowAuthorization && !readOnly) && (
  146. <AuthorizationModal
  147. nodeId={id}
  148. isShow
  149. onHide={hideAuthorization}
  150. payload={inputs.authorization}
  151. onChange={setAuthorization}
  152. />
  153. )}
  154. <Split />
  155. <div className=''>
  156. <OutputVars>
  157. <>
  158. <VarItem
  159. name='body'
  160. type='string'
  161. description={t(`${i18nPrefix}.outputVars.body`)}
  162. />
  163. <VarItem
  164. name='status_code'
  165. type='number'
  166. description={t(`${i18nPrefix}.outputVars.statusCode`)}
  167. />
  168. <VarItem
  169. name='headers'
  170. type='object'
  171. description={t(`${i18nPrefix}.outputVars.headers`)}
  172. />
  173. <VarItem
  174. name='files'
  175. type='Array[File]'
  176. description={t(`${i18nPrefix}.outputVars.files`)}
  177. />
  178. </>
  179. </OutputVars>
  180. </div>
  181. {(isShowCurlPanel && !readOnly) && (
  182. <CurlPanel
  183. nodeId={id}
  184. isShow
  185. onHide={hideCurlPanel}
  186. handleCurlImport={handleCurlImport}
  187. />
  188. )}
  189. </div>
  190. )
  191. }
  192. export default memo(Panel)