您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import {
  5. RiQuestionLine,
  6. } from '@remixicon/react'
  7. import { CodeLanguage } from '../code/types'
  8. import useConfig from './use-config'
  9. import type { TemplateTransformNodeType } from './types'
  10. import VarList from '@/app/components/workflow/nodes/_base/components/variable/var-list'
  11. import AddButton from '@/app/components/base/button/add-button'
  12. import Field from '@/app/components/workflow/nodes/_base/components/field'
  13. import Split from '@/app/components/workflow/nodes/_base/components/split'
  14. import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor/editor-support-vars'
  15. import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
  16. import type { NodePanelProps } from '@/app/components/workflow/types'
  17. const i18nPrefix = 'workflow.nodes.templateTransform'
  18. const Panel: FC<NodePanelProps<TemplateTransformNodeType>> = ({
  19. id,
  20. data,
  21. }) => {
  22. const { t } = useTranslation()
  23. const {
  24. readOnly,
  25. inputs,
  26. availableVars,
  27. handleVarListChange,
  28. handleVarNameChange,
  29. handleAddVariable,
  30. handleAddEmptyVariable,
  31. handleCodeChange,
  32. filterVar,
  33. } = useConfig(id, data)
  34. return (
  35. <div className='mt-2'>
  36. <div className='space-y-4 px-4 pb-4'>
  37. <Field
  38. title={t(`${i18nPrefix}.inputVars`)}
  39. operations={
  40. !readOnly ? <AddButton onClick={handleAddEmptyVariable} /> : undefined
  41. }
  42. >
  43. <VarList
  44. nodeId={id}
  45. readonly={readOnly}
  46. list={inputs.variables}
  47. onChange={handleVarListChange}
  48. onVarNameChange={handleVarNameChange}
  49. filterVar={filterVar}
  50. isSupportFileVar={false}
  51. />
  52. </Field>
  53. <Split />
  54. <CodeEditor
  55. availableVars={availableVars}
  56. varList={inputs.variables}
  57. onAddVar={handleAddVariable}
  58. isInNode
  59. readOnly={readOnly}
  60. language={CodeLanguage.python3}
  61. title={
  62. <div className='uppercase'>{t(`${i18nPrefix}.code`)}</div>
  63. }
  64. headerRight={
  65. <div className='flex items-center'>
  66. <a
  67. className='flex h-[18px] items-center space-x-0.5 text-xs font-normal text-text-tertiary'
  68. href="https://jinja.palletsprojects.com/en/3.1.x/templates/"
  69. target='_blank'>
  70. <span>{t(`${i18nPrefix}.codeSupportTip`)}</span>
  71. <RiQuestionLine className='h-3 w-3' />
  72. </a>
  73. <div className='mx-1.5 h-3 w-px bg-divider-regular'></div>
  74. </div>
  75. }
  76. value={inputs.template}
  77. onChange={handleCodeChange}
  78. />
  79. </div>
  80. <Split />
  81. <div>
  82. <OutputVars>
  83. <>
  84. <VarItem
  85. name='output'
  86. type='string'
  87. description={t(`${i18nPrefix}.outputVars.output`)}
  88. />
  89. </>
  90. </OutputVars>
  91. </div>
  92. </div>
  93. )
  94. }
  95. export default React.memo(Panel)