File size: 1,357 Bytes
4304c6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
'use client'
import type { FC } from 'react'
import React from 'react'
import { useTranslation } from 'react-i18next'
import ParamItem from '.'

type Props = {
  className?: string
  value: number
  onChange: (key: string, value: number) => void
  enable: boolean
  hasSwitch?: boolean
  onSwitchChange?: (key: string, enable: boolean) => void
}

const VALUE_LIMIT = {
  default: 0.7,
  step: 0.01,
  min: 0,
  max: 1,
}

const key = 'score_threshold'
const ScoreThresholdItem: FC<Props> = ({

  className,

  value,

  enable,

  onChange,

  hasSwitch,

  onSwitchChange,

}) => {
  const { t } = useTranslation()
  const handleParamChange = (key: string, value: number) => {
    let notOutRangeValue = parseFloat(value.toFixed(2))
    notOutRangeValue = Math.max(VALUE_LIMIT.min, notOutRangeValue)
    notOutRangeValue = Math.min(VALUE_LIMIT.max, notOutRangeValue)
    onChange(key, notOutRangeValue)
  }
  return (
    <ParamItem

      className={className}

      id={key}

      name={t(`appDebug.datasetConfig.${key}`)}

      tip={t(`appDebug.datasetConfig.${key}Tip`) as string}

      {...VALUE_LIMIT}

      value={value}

      enable={enable}

      onChange={handleParamChange}

      hasSwitch={hasSwitch}

      onSwitchChange={onSwitchChange}

    />
  )
}
export default React.memo(ScoreThresholdItem)