wwf
昨天 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'use client'
import type { FC } from 'react'
import React, { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import type { Limit } from '../types'
import InputNumberWithSlider from '../../_base/components/input-number-with-slider'
import cn from '@/utils/classnames'
import Field from '@/app/components/workflow/nodes/_base/components/field'
import Switch from '@/app/components/base/switch'
 
const i18nPrefix = 'workflow.nodes.listFilter'
const LIMIT_SIZE_MIN = 1
const LIMIT_SIZE_MAX = 20
const LIMIT_SIZE_DEFAULT = 10
 
type Props = {
  className?: string
  readonly: boolean
  config: Limit
  onChange: (limit: Limit) => void
  canSetRoleName?: boolean
}
 
const LIMIT_DEFAULT: Limit = {
  enabled: false,
  size: LIMIT_SIZE_DEFAULT,
}
 
const LimitConfig: FC<Props> = ({
  className,
  readonly,
  config = LIMIT_DEFAULT,
  onChange,
}) => {
  const { t } = useTranslation()
  const payload = config
 
  const handleLimitEnabledChange = useCallback((enabled: boolean) => {
    onChange({
      ...config,
      enabled,
    })
  }, [config, onChange])
 
  const handleLimitSizeChange = useCallback((size: number | string) => {
    onChange({
      ...config,
      size: parseInt(size as string),
    })
  }, [onChange, config])
 
  return (
    <div className={cn(className)}>
      <Field
        title={t(`${i18nPrefix}.limit`)}
        operations={
          <Switch
            defaultValue={payload.enabled}
            onChange={handleLimitEnabledChange}
            size='md'
            disabled={readonly}
          />
        }
      >
        {payload?.enabled
          ? (
            <InputNumberWithSlider
              value={payload?.size || LIMIT_SIZE_DEFAULT}
              min={LIMIT_SIZE_MIN}
              max={LIMIT_SIZE_MAX}
              onChange={handleLimitSizeChange}
              readonly={readonly || !payload?.enabled}
            />
          )
          : null}
      </Field>
    </div>
  )
}
export default React.memo(LimitConfig)