Skip to content

Commit db0d197

Browse files
fix: better input status for ThresholdValueInput (#3640)
1 parent 419caee commit db0d197

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

cypress/e2e/shared/notificationRules.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('NotificationRules', () => {
6969
.click()
7070
.type('{backspace}{backspace}')
7171
.invoke('attr', 'type')
72-
.should('equal', 'text')
72+
.should('equal', 'number')
7373
.getByTestID('input-field-CRIT--error')
7474
.should('have.length', 1)
7575
.and('have.value', '')

src/alerting/components/builder/ThresholdValueInput.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Libraries
2-
import React, {FC} from 'react'
2+
import React, {FC, useState} from 'react'
33

44
// Components
5-
import {FlexBox, Input, InputType} from '@influxdata/clockface'
5+
import {ComponentStatus, FlexBox, Input, InputType} from '@influxdata/clockface'
66
import {GreaterThreshold, LesserThreshold} from 'src/types'
77

88
// Utils
@@ -20,17 +20,28 @@ const ThresholdValueStatement: FC<Props> = ({
2020
changeValue,
2121
level,
2222
}) => {
23+
const [value, setValue] = useState(threshold.value.toString())
24+
2325
const onChangeValue = (e: React.ChangeEvent<HTMLInputElement>) => {
26+
setValue(e.target.value)
2427
changeValue(convertUserInputToNumOrNaN(e))
2528
}
29+
const getInputStatus = (): ComponentStatus => {
30+
if (Number(value)) {
31+
return ComponentStatus.Default
32+
}
33+
34+
return ComponentStatus.Error
35+
}
2636
return (
2737
<FlexBox.Child testID="component-spacer--flex-child">
2838
<Input
2939
onChange={onChangeValue}
3040
name=""
3141
type={InputType.Number}
32-
value={threshold.value}
42+
value={value}
3343
testID={`input-field-${level}`}
44+
status={getInputStatus()}
3445
/>
3546
</FlexBox.Child>
3647
)

0 commit comments

Comments
 (0)