wwf
2 天以前 a430284aa21e3ae1f0d5654e55b2ad2852519cc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use client'
import type { FC } from 'react'
import React, { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import TextEditor from '@/app/components/workflow/nodes/_base/components/editor/text-editor'
import { LayoutGrid02 } from '@/app/components/base/icons/src/vender/line/layout'
 
const i18nPrefix = 'workflow.nodes.http'
 
type Props = {
  value: string
  onChange: (value: string) => void
  onSwitchToKeyValueEdit: () => void
}
 
const BulkEdit: FC<Props> = ({
  value,
  onChange,
  onSwitchToKeyValueEdit,
}) => {
  const { t } = useTranslation()
  const [tempValue, setTempValue] = React.useState(value)
 
  const handleChange = useCallback((value: string) => {
    setTempValue(value)
  }, [])
 
  const handleBlur = useCallback(() => {
    onChange(tempValue)
  }, [tempValue, onChange])
 
  const handleSwitchToKeyValueEdit = useCallback(() => {
    onChange(tempValue)
    onSwitchToKeyValueEdit()
  }, [tempValue, onChange, onSwitchToKeyValueEdit])
 
  return (
    <div>
      <TextEditor
        isInNode
        title={<div className='uppercase'>{t(`${i18nPrefix}.bulkEdit`)}</div>}
        value={tempValue}
        onChange={handleChange}
        onBlur={handleBlur}
        headerRight={
          <div className='flex items-center h-[18px]'>
            <div
              className='flex items-center space-x-1 cursor-pointer'
              onClick={handleSwitchToKeyValueEdit}
            >
              <LayoutGrid02 className='w-3 h-3 text-gray-500' />
              <div className='leading-[18px] text-xs font-normal text-gray-500'>{t(`${i18nPrefix}.keyValueEdit`)}</div>
            </div>
            <div className='ml-3 mr-1.5 w-px h-3 bg-gray-200'></div>
          </div>
        }
        minHeight={150}
      />
    </div>
  )
}
export default React.memo(BulkEdit)