panel.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import cn from 'classnames'
  5. import useConfig from './use-config'
  6. import ApiInput from './components/api-input'
  7. import KeyValue from './components/key-value'
  8. import EditBody from './components/edit-body'
  9. import AuthorizationModal from './components/authorization'
  10. import type { HttpNodeType } from './types'
  11. import Timeout from './components/timeout'
  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. isShow
  125. onHide={hideAuthorization}
  126. payload={inputs.authorization}
  127. onChange={setAuthorization}
  128. />
  129. )}
  130. <Split />
  131. <div className='px-4 pt-4 pb-2'>
  132. <OutputVars>
  133. <>
  134. <VarItem
  135. name='body'
  136. type='string'
  137. description={t(`${i18nPrefix}.outputVars.body`)}
  138. />
  139. <VarItem
  140. name='status_code'
  141. type='number'
  142. description={t(`${i18nPrefix}.outputVars.statusCode`)}
  143. />
  144. <VarItem
  145. name='headers'
  146. type='object'
  147. description={t(`${i18nPrefix}.outputVars.headers`)}
  148. />
  149. <VarItem
  150. name='files'
  151. type='Array[File]'
  152. description={t(`${i18nPrefix}.outputVars.files`)}
  153. />
  154. </>
  155. </OutputVars>
  156. </div>
  157. {isShowSingleRun && (
  158. <BeforeRunForm
  159. nodeName={inputs.title}
  160. onHide={hideSingleRun}
  161. forms={[
  162. {
  163. inputs: varInputs,
  164. values: inputVarValues,
  165. onChange: setInputVarValues,
  166. },
  167. ]}
  168. runningStatus={runningStatus}
  169. onRun={handleRun}
  170. onStop={handleStop}
  171. result={<ResultPanel {...runResult} showSteps={false} />}
  172. />
  173. )}
  174. </div >
  175. )
  176. }
  177. export default React.memo(Panel)