Skip to content

Commit 019ffa5

Browse files
committed
#RI-2967 - Max-len and slower-than fields should be filled by default values when user saves empty lines
1 parent a1f33c9 commit 019ffa5

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

redisinsight/ui/src/constants/durationUnits.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const DURATION_UNITS: EuiSuperSelectOption<DurationUnits>[] = [
1818

1919
export const MINUS_ONE = -1
2020
export const DEFAULT_SLOWLOG_MAX_LEN = 128
21-
export const DEFAULT_SLOWLOG_SLOWER_THAN = 10000
21+
export const DEFAULT_SLOWLOG_SLOWER_THAN = 10_000
2222
export const DEFAULT_SLOWLOG_DURATION_UNIT = DurationUnits.microSeconds
2323

2424
export default DURATION_UNITS

redisinsight/ui/src/pages/slowLog/components/SlowLogConfig/SlowLogConfig.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ const SlowLogConfig = ({ closePopover, onRefresh }: Props) => {
7070
}
7171

7272
const calculateSlowlogLogSlowerThan = (initSlowerThan: string) => {
73+
if (initSlowerThan === '') {
74+
return DEFAULT_SLOWLOG_SLOWER_THAN
75+
}
76+
if (initSlowerThan === `${MINUS_ONE}`) {
77+
return MINUS_ONE
78+
}
7379
if (initSlowerThan === `${MINUS_ONE}`) {
7480
return MINUS_ONE
7581
}
@@ -81,7 +87,7 @@ const SlowLogConfig = ({ closePopover, onRefresh }: Props) => {
8187
dispatch(patchSlowLogConfigAction(
8288
instanceId,
8389
{
84-
slowlogMaxLen: +maxLen,
90+
slowlogMaxLen: maxLen ? toNumber(maxLen) : DEFAULT_SLOWLOG_MAX_LEN,
8591
slowlogLogSlowerThan,
8692
},
8793
durationUnit,
@@ -96,7 +102,7 @@ const SlowLogConfig = ({ closePopover, onRefresh }: Props) => {
96102
closePopover()
97103
}
98104

99-
const disabledApplyBtn = () => errorValidateNegativeInteger(`${slowerThan}`) || loading
105+
const disabledApplyBtn = () => (errorValidateNegativeInteger(`${slowerThan}`) && !!slowerThan) || loading
100106

101107
const clusterContent = () => (
102108
<>
@@ -124,6 +130,14 @@ const SlowLogConfig = ({ closePopover, onRefresh }: Props) => {
124130
)
125131

126132
const unitConverter = () => {
133+
if (Number.isNaN(toNumber(slowerThan))) {
134+
return `- ${DurationUnits.milliSeconds}`
135+
}
136+
137+
if (slowerThan === `${MINUS_ONE}`) {
138+
return `-1 ${DurationUnits.milliSeconds}`
139+
}
140+
127141
if (durationUnit === DurationUnits.microSeconds) {
128142
const value = numberWithSpaces(convertNumberByUnits(toNumber(slowerThan), DurationUnits.milliSeconds))
129143
return `${value} ${DurationUnits.milliSeconds}`
@@ -150,11 +164,11 @@ const SlowLogConfig = ({ closePopover, onRefresh }: Props) => {
150164
name="slowerThan"
151165
id="slowerThan"
152166
className={styles.input}
153-
placeholder={`${slowlogLogSlowerThan}`}
154167
value={slowerThan}
155168
onChange={(e: ChangeEvent<HTMLInputElement>) => {
156169
setSlowerThan(validateNumber(e.target.value.trim(), Infinity, -1))
157170
}}
171+
placeholder={`${convertNumberByUnits(DEFAULT_SLOWLOG_SLOWER_THAN, durationUnit)}`}
158172
autoComplete="off"
159173
data-testid="slower-than-input"
160174
/>
@@ -184,7 +198,7 @@ const SlowLogConfig = ({ closePopover, onRefresh }: Props) => {
184198
name="maxLen"
185199
id="maxLen"
186200
className={styles.input}
187-
placeholder={`${slowlogMaxLen}`}
201+
placeholder={`${DEFAULT_SLOWLOG_MAX_LEN}`}
188202
value={maxLen}
189203
onChange={(e: ChangeEvent<HTMLInputElement>) => { setMaxLen(validateNumber(e.target.value.trim())) }}
190204
autoComplete="off"

0 commit comments

Comments
 (0)