Skip to content

Commit

Permalink
fix validate to > from
Browse files Browse the repository at this point in the history
  • Loading branch information
sanglevinh committed Jan 16, 2025
1 parent db38497 commit 2a6d8a0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions frontend/src/components/Workspace/FlowChart/Dialog/BoxFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,22 @@ const InputDim = (props: InputDim) => {

useEffect(() => {
setValue(p.value as string)
setValuePassed(p.value as string)
}, [p.value])

const validateValue = useCallback(
(string: string, isBlur?: boolean) => {
if (max || max === 0) {
if (max) {
return string
.split(",")
.map((e) => {
const dims = e.split(":")
if (!dims.filter(Boolean).length) return e
const dim0 = dims[0]
const dim1 = dims[1]
if (dim0 && !dim1 && Number(dim0) > max) return `${max}:`
if (dim0 && !dim1 && Number(dim0) >= max) return `${max - 1}:`
if (dim0 && dim1) {
return `${Number(dim0) > max ? max : dim0}:${Number(dim1) > max ? max : dim1}`
return `${Number(dim0) >= max ? max - 1 : dim0}:${Number(dim1) > max ? max : dim1}`
}
if (dim1 && !dim0) return `0:${dim1}`
if (isBlur && dim0 && !dim1) return `${dim0}:${max}`
Expand All @@ -70,8 +71,8 @@ const InputDim = (props: InputDim) => {
let regexTest = /^(\d+:\d+)(,\d+:\d+)*$/
if (!multiple) regexTest = /^(\d+:\d+)(\d+:\d+)*$/
value = validateValue(value)
if (regexTest.test(value) || !value) setValuePassed(value)
setValue(value)
if (regexTest.test(value) || !value) setValuePassed(value.trim())
setValue(value.trim())
},
[multiple, validateValue],
)
Expand All @@ -86,7 +87,7 @@ const InputDim = (props: InputDim) => {
return dim1 && Number(dim1) < Number(dim0) ? dim0 : undefined
})
if (errorEnd) {
return `The 'to' value must be >= ${errorEnd.split(":")[0]}`
return `The 'to' value must be > ${errorEnd.split(":")[0]}`
}
}
return null
Expand Down

0 comments on commit 2a6d8a0

Please sign in to comment.