panel.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. </div>
  80. </>
  81. </Field>
  82. </div>
  83. {isShowAddVarModal && (
  84. <ConfigVarModal
  85. isCreate
  86. isShow={isShowAddVarModal}
  87. onClose={hideAddVarModal}
  88. onConfirm={handleAddVarConfirm}
  89. varKeys={inputs.variables.map(v => v.variable)}
  90. />
  91. )}
  92. <RemoveEffectVarConfirm
  93. isShow={isShowRemoveVarConfirm}
  94. onCancel={hideRemoveVarConfirm}
  95. onConfirm={onRemoveVarConfirm}
  96. />
  97. </div>
  98. )
  99. }
  100. export default React.memo(Panel)