panel.tsx 5.1 KB

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