選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

panel.tsx 5.3KB

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