score-threshold-item.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import ParamItem from '.'
  6. type Props = {
  7. className?: string
  8. value: number
  9. onChange: (key: string, value: number) => void
  10. enable: boolean
  11. hasSwitch?: boolean
  12. onSwitchChange?: (key: string, enable: boolean) => void
  13. }
  14. const VALUE_LIMIT = {
  15. default: 0.7,
  16. step: 0.01,
  17. min: 0,
  18. max: 1,
  19. }
  20. const key = 'score_threshold'
  21. const ScoreThresholdItem: FC<Props> = ({
  22. className,
  23. value,
  24. enable,
  25. onChange,
  26. hasSwitch,
  27. onSwitchChange,
  28. }) => {
  29. const { t } = useTranslation()
  30. const handleParamChange = (key: string, value: number) => {
  31. let notOutRangeValue = parseFloat(value.toFixed(2))
  32. notOutRangeValue = Math.max(VALUE_LIMIT.min, notOutRangeValue)
  33. notOutRangeValue = Math.min(VALUE_LIMIT.max, notOutRangeValue)
  34. onChange(key, notOutRangeValue)
  35. }
  36. return (
  37. <ParamItem
  38. className={className}
  39. id={key}
  40. name={t(`appDebug.datasetConfig.${key}`)}
  41. tip={t(`appDebug.datasetConfig.${key}Tip`) as string}
  42. {...VALUE_LIMIT}
  43. value={value}
  44. enable={enable}
  45. onChange={handleParamChange}
  46. hasSwitch={hasSwitch}
  47. onSwitchChange={onSwitchChange}
  48. />
  49. )
  50. }
  51. export default React.memo(ScoreThresholdItem)