{selected.length > 0 && `${selected.length} ${t('feature.dataSet.selected', { ns: 'appDebug' })}`}
diff --git a/web/app/components/base/param-item/__tests__/score-threshold-item.spec.tsx b/web/app/components/base/param-item/__tests__/score-threshold-item.spec.tsx
index 026908fa9e..54a13e1b74 100644
--- a/web/app/components/base/param-item/__tests__/score-threshold-item.spec.tsx
+++ b/web/app/components/base/param-item/__tests__/score-threshold-item.spec.tsx
@@ -137,5 +137,11 @@ describe('ScoreThresholdItem', () => {
const input = screen.getByRole('textbox')
expect(input).toHaveValue('1')
})
+
+ it('should fall back to default value when value is undefined', () => {
+ render(
)
+ const input = screen.getByRole('textbox')
+ expect(input).toHaveValue('0.7')
+ })
})
})
diff --git a/web/app/components/base/param-item/score-threshold-item.tsx b/web/app/components/base/param-item/score-threshold-item.tsx
index c6c73713d7..cbaf190b99 100644
--- a/web/app/components/base/param-item/score-threshold-item.tsx
+++ b/web/app/components/base/param-item/score-threshold-item.tsx
@@ -6,7 +6,7 @@ import ParamItem from '.'
type Props = {
className?: string
- value: number
+ value?: number
onChange: (key: string, value: number) => void
enable: boolean
hasSwitch?: boolean
@@ -20,6 +20,18 @@ const VALUE_LIMIT = {
max: 1,
}
+const normalizeScoreThreshold = (value?: number): number => {
+ const normalizedValue = typeof value === 'number' && Number.isFinite(value)
+ ? value
+ : VALUE_LIMIT.default
+ const roundedValue = Number.parseFloat(normalizedValue.toFixed(2))
+
+ return Math.min(
+ VALUE_LIMIT.max,
+ Math.max(VALUE_LIMIT.min, roundedValue),
+ )
+}
+
const ScoreThresholdItem: FC
= ({
className,
value,
@@ -29,16 +41,10 @@ const ScoreThresholdItem: FC = ({
onSwitchChange,
}) => {
const { t } = useTranslation()
- const handleParamChange = (key: string, value: number) => {
- let notOutRangeValue = Number.parseFloat(value.toFixed(2))
- notOutRangeValue = Math.max(VALUE_LIMIT.min, notOutRangeValue)
- notOutRangeValue = Math.min(VALUE_LIMIT.max, notOutRangeValue)
- onChange(key, notOutRangeValue)
+ const handleParamChange = (key: string, nextValue: number) => {
+ onChange(key, normalizeScoreThreshold(nextValue))
}
- const safeValue = Math.min(
- VALUE_LIMIT.max,
- Math.max(VALUE_LIMIT.min, Number.parseFloat(value.toFixed(2))),
- )
+ const safeValue = normalizeScoreThreshold(value)
return (