panel.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import RemoveEffectVarConfirm from '../_base/components/remove-effect-var-confirm'
  5. import VarList from './components/var-list'
  6. import VarItem from './components/var-item'
  7. import useConfig from './use-config'
  8. import type { StartNodeType } from './types'
  9. import Split from '@/app/components/workflow/nodes/_base/components/split'
  10. import Field from '@/app/components/workflow/nodes/_base/components/field'
  11. import AddButton from '@/app/components/base/button/add-button'
  12. import ConfigVarModal from '@/app/components/app/configuration/config-var/config-modal'
  13. import type { InputVar, NodePanelProps } from '@/app/components/workflow/types'
  14. const i18nPrefix = 'workflow.nodes.start'
  15. const Panel: FC<NodePanelProps<StartNodeType>> = ({
  16. id,
  17. data,
  18. }) => {
  19. const { t } = useTranslation()
  20. const {
  21. readOnly,
  22. isChatMode,
  23. inputs,
  24. isShowAddVarModal,
  25. showAddVarModal,
  26. handleAddVariable,
  27. hideAddVarModal,
  28. handleVarListChange,
  29. isShowRemoveVarConfirm,
  30. hideRemoveVarConfirm,
  31. onRemoveVarConfirm,
  32. } = useConfig(id, data)
  33. const handleAddVarConfirm = (payload: InputVar) => {
  34. handleAddVariable(payload)
  35. hideAddVarModal()
  36. }
  37. return (
  38. <div className='mt-2'>
  39. <div className='px-4 pb-2 space-y-4'>
  40. <Field
  41. title={t(`${i18nPrefix}.inputField`)}
  42. operations={
  43. !readOnly ? <AddButton onClick={showAddVarModal} /> : undefined
  44. }
  45. >
  46. <>
  47. <VarList
  48. readonly={readOnly}
  49. list={inputs.variables || []}
  50. onChange={handleVarListChange}
  51. />
  52. <div className='mt-1 space-y-1'>
  53. <Split className='my-2' />
  54. {
  55. isChatMode && (
  56. <VarItem
  57. readonly
  58. payload={{
  59. variable: 'sys.query',
  60. } as any}
  61. rightContent={
  62. <div className='text-xs font-normal text-gray-500'>
  63. String
  64. </div>
  65. }
  66. />)
  67. }
  68. <VarItem
  69. readonly
  70. payload={{
  71. variable: 'sys.files',
  72. } as any}
  73. rightContent={
  74. <div className='text-xs font-normal text-gray-500'>
  75. Array[File]
  76. </div>
  77. }
  78. />
  79. {
  80. isChatMode && (
  81. <VarItem
  82. readonly
  83. payload={{
  84. variable: 'sys.conversation_id',
  85. } as any}
  86. rightContent={
  87. <div className='text-xs font-normal text-gray-500'>
  88. String
  89. </div>
  90. }
  91. />
  92. )
  93. }
  94. <VarItem
  95. readonly
  96. payload={{
  97. variable: 'sys.user_id',
  98. } as any}
  99. rightContent={
  100. <div className='text-xs font-normal text-gray-500'>
  101. String
  102. </div>
  103. }
  104. />
  105. </div>
  106. </>
  107. </Field>
  108. </div>
  109. {isShowAddVarModal && (
  110. <ConfigVarModal
  111. isCreate
  112. isShow={isShowAddVarModal}
  113. onClose={hideAddVarModal}
  114. onConfirm={handleAddVarConfirm}
  115. varKeys={inputs.variables.map(v => v.variable)}
  116. />
  117. )}
  118. <RemoveEffectVarConfirm
  119. isShow={isShowRemoveVarConfirm}
  120. onCancel={hideRemoveVarConfirm}
  121. onConfirm={onRemoveVarConfirm}
  122. />
  123. </div>
  124. )
  125. }
  126. export default React.memo(Panel)