Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Block Explorer UI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
Block Explorer UI
Commits
29ee43af
Commit
29ee43af
authored
2 months ago
by
Dima Rifai
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#415
- Refactor Events to prevent continous state changes causing slowness
parent
539628be
No related branches found
No related tags found
No related merge requests found
Pipeline
#112403
failed
2 months ago
Stage: build
Stage: test
Stage: test-report-aggregate
Stage: cleanup
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
components/searchRanges/SearchRanges.tsx
+56
-56
56 additions, 56 deletions
components/searchRanges/SearchRanges.tsx
with
56 additions
and
56 deletions
components/searchRanges/SearchRanges.tsx
+
56
−
56
View file @
29ee43af
...
@@ -39,33 +39,26 @@ const SearchRanges: React.FC<SearchRangesProps> = ({
...
@@ -39,33 +39,26 @@ const SearchRanges: React.FC<SearchRangesProps> = ({
// Validate and update numeric values
// Validate and update numeric values
const
handleNumericInput
=
(
const
handleNumericInput
=
(
value
:
string
,
e
:
React
.
ChangeEvent
<
HTMLInputElement
>
,
fieldSetter
:
Function
,
allowDecimal
:
boolean
=
false
allowDecimal
:
boolean
=
false
)
=>
{
)
=>
{
// If decimals are allowed, preserve the decimal point in the input value
let
cleanedValue
=
e
.
target
.
value
;
let
cleanedValue
=
allowDecimal
?
value
.
replace
(
/
[^
0-9.
]
/g
,
""
)
// Allow numbers and decimal point
// Clean the value based on the logic
:
value
.
replace
(
/
[^
0-9
]
/g
,
""
);
// Only allow numbers
cleanedValue
=
allowDecimal
?
cleanedValue
.
replace
(
/
[^
0-9.
]
/g
,
""
)
// Allow numbers and decimal point
// If the decimal is allowed, ensure there is only one decimal point
:
cleanedValue
.
replace
(
/
[^
0-9
]
/g
,
""
);
// Only allow numbers
if
(
allowDecimal
&&
cleanedValue
.
split
(
"
.
"
).
length
>
2
)
{
if
(
allowDecimal
&&
cleanedValue
.
split
(
"
.
"
).
length
>
2
)
{
// Remove extra decimals, keeping only the first one
cleanedValue
=
cleanedValue
.
slice
(
0
,
cleanedValue
.
indexOf
(
"
.
"
)
+
1
)
+
cleanedValue
=
cleanedValue
.
slice
(
0
,
cleanedValue
.
indexOf
(
"
.
"
)
+
1
)
+
cleanedValue
.
split
(
"
.
"
).
slice
(
1
).
join
(
""
);
// Remove
all
decimals
after the first one
cleanedValue
.
split
(
"
.
"
).
slice
(
1
).
join
(
""
);
// Remove
extra
decimals
}
}
// Limit the value to a maximum of 15 digits
if
(
cleanedValue
.
length
>
15
)
{
if
(
cleanedValue
.
length
>
15
)
{
cleanedValue
=
cleanedValue
.
slice
(
0
,
15
);
cleanedValue
=
cleanedValue
.
slice
(
0
,
15
);
// Limit to 15 digits
}
}
// If the cleaned value is empty, set it to undefined
e
.
target
.
value
=
cleanedValue
;
if
(
cleanedValue
===
""
)
{
fieldSetter
(
undefined
);
}
else
{
fieldSetter
(
cleanedValue
);
// Invalid input, set to undefined
}
};
};
useEffect
(()
=>
{
useEffect
(()
=>
{
...
@@ -114,10 +107,13 @@ const SearchRanges: React.FC<SearchRangesProps> = ({
...
@@ -114,10 +107,13 @@ const SearchRanges: React.FC<SearchRangesProps> = ({
<
Input
<
Input
className
=
"w-1/2 border-0 border-b-2 bg-theme"
className
=
"w-1/2 border-0 border-b-2 bg-theme"
type
=
"text"
// Use type="text" to allow custom validation
type
=
"text"
// Use type="text" to allow custom validation
value
=
{
lastBlocksValue
||
""
}
defaultValue
=
{
lastBlocksValue
||
""
}
onChange
=
{
(
e
)
=>
onChange
=
{
(
e
)
=>
handleNumericInput
(
e
)
}
handleNumericInput
(
e
.
target
.
value
,
setLastBlocksValue
)
onBlur
=
{
(
e
)
=>
{
}
const
value
=
e
.
target
.
value
;
const
numericValue
=
value
?
Number
(
value
)
:
undefined
;
setLastBlocksValue
(
numericValue
);
}
}
placeholder
=
{
"
Last
"
}
placeholder
=
{
"
Last
"
}
/>
/>
</
div
>
</
div
>
...
@@ -131,10 +127,13 @@ const SearchRanges: React.FC<SearchRangesProps> = ({
...
@@ -131,10 +127,13 @@ const SearchRanges: React.FC<SearchRangesProps> = ({
<
Input
<
Input
type
=
"text"
type
=
"text"
className
=
"bg-theme border-0 border-b-2 text-text"
className
=
"bg-theme border-0 border-b-2 text-text"
value
=
{
lastTimeUnitValue
||
""
}
defaultValue
=
{
lastTimeUnitValue
||
""
}
onChange
=
{
(
e
)
=>
onChange
=
{
(
e
)
=>
handleNumericInput
(
e
,
true
)
}
handleNumericInput
(
e
.
target
.
value
,
setLastTimeUnitValue
,
true
)
onBlur
=
{
(
e
)
=>
{
}
const
value
=
e
.
target
.
value
;
const
numericValue
=
value
?
Number
(
value
)
:
undefined
;
setLastTimeUnitValue
(
numericValue
);
}
}
placeholder
=
{
"
Last
"
}
placeholder
=
{
"
Last
"
}
/>
/>
</
div
>
</
div
>
...
@@ -173,10 +172,13 @@ const SearchRanges: React.FC<SearchRangesProps> = ({
...
@@ -173,10 +172,13 @@ const SearchRanges: React.FC<SearchRangesProps> = ({
type
=
"text"
type
=
"text"
className
=
"bg-theme border-0 border-b-2"
className
=
"bg-theme border-0 border-b-2"
data-testid
=
"from-block-input"
data-testid
=
"from-block-input"
value
=
{
fromBlock
||
""
}
defaultValue
=
{
fromBlock
||
""
}
onChange
=
{
(
e
)
=>
onChange
=
{
(
e
)
=>
handleNumericInput
(
e
)
}
handleNumericInput
(
e
.
target
.
value
,
setFromBlock
)
onBlur
=
{
(
e
)
=>
{
}
const
value
=
e
.
target
.
value
;
const
numericValue
=
value
?
Number
(
value
)
:
undefined
;
setFromBlock
(
numericValue
);
}
}
placeholder
=
"From"
placeholder
=
"From"
/>
/>
</
div
>
</
div
>
...
@@ -185,32 +187,30 @@ const SearchRanges: React.FC<SearchRangesProps> = ({
...
@@ -185,32 +187,30 @@ const SearchRanges: React.FC<SearchRangesProps> = ({
className
=
"bg-theme border-0 border-b-2"
className
=
"bg-theme border-0 border-b-2"
data-testid
=
"headblock-number"
data-testid
=
"headblock-number"
type
=
"text"
type
=
"text"
value
=
{
toBlock
||
""
}
defaultValue
=
{
toBlock
||
""
}
onChange
=
{
(
e
)
=>
onChange
=
{
(
e
)
=>
handleNumericInput
(
e
)
}
// Keep cleaning logic here on change
handleNumericInput
(
e
.
target
.
value
,
setToBlock
)
}
placeholder
=
{
"
To
"
}
placeholder
=
{
"
To
"
}
onBlur
=
{
()
=>
{
onBlur
=
{
(
e
:
React
.
FocusEvent
<
HTMLInputElement
>
)
=>
{
if
(
const
value
=
e
.
target
.
value
;
Number
(
toBlock
)
&&
const
numericValue
=
value
?
Number
(
value
)
:
undefined
;
// Default to NaN if empty string
Number
(
fromBlock
)
&&
if
(
!
isNaN
(
N
um
b
er
(
toBlock
))
&&
n
umer
icValue
&&
!
isNaN
(
Number
(
fromBlock
))
&&
fromBlock
&&
Number
(
toBlock
)
<
N
um
b
er
(
fromBlock
)
!
isNaN
(
n
umer
icValue
)
&&
)
{
!
isNaN
(
Number
(
fromBlock
))
&&
setBlockRangeError
(
numericValue
<
Number
(
fromBlock
)
"
To block must be greater than From block
"
)
{
);
setBlockRangeError
(
"
To block must be greater than From block
"
);
setToBlock
(
undefined
)
;
// Clear the 'toBlock' field
e
.
target
.
value
=
""
;
// Clear the 'toBlock' field
if validation fails
}
else
if
(
N
um
b
er
(
toBlock
)
<=
0
&&
Number
(
fromBlock
)
)
{
}
else
if
(
n
umer
icValue
!=
undefined
&&
numericValue
<=
0
&&
fromBlock
)
{
setBlockRangeError
(
setBlockRangeError
(
"
To block must be greater than From block
"
);
"
To block must be greater than From block
"
e
.
target
.
value
=
""
;
// Clear the 'toBlock' field if validation fails
);
}
else
{
setToBlock
(
undefined
);
// Clear the 'toBlock' field
setToBlock
(
numericValue
);
// Set the state only when validation passes
}
else
{
setBlockRangeError
(
null
);
// Clear error if valid
setBlockRangeError
(
null
);
// Clear the error message immediately if 'toBlock' is valid
}
}
}
}
}
}
/>
/>
</
div
>
</
div
>
</
div
>
</
div
>
...
@@ -247,4 +247,4 @@ const SearchRanges: React.FC<SearchRangesProps> = ({
...
@@ -247,4 +247,4 @@ const SearchRanges: React.FC<SearchRangesProps> = ({
);
);
};
};
export
default
SearchRanges
;
export
default
SearchRanges
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment