@@ -11,6 +11,7 @@ import {
1111import { getSanitizedInteractionsPerPage , parseTimestamp } from 'helpers' ;
1212
1313const EXTRACT_VAT_ID_REGEX = / ^ v ( [ 0 - 9 ] * ) $ / ;
14+ const IS_NUMBER_REGEX = / ^ [ 0 - 9 ] + ( .[ 0 - 9 ] * ) ? $ / ;
1415
1516const FORM_GROUP_CLASSES = 'flex flex-col gap-y-1' ;
1617const FORM_HELP_CLASSES = 'text-gray-D600 text-xs' ;
@@ -43,16 +44,24 @@ const Neo4jSequenceDiagram = () => {
4344 status : '' ,
4445 } ) ;
4546
46- const routerBlockHeight = searchParams . get ( 'blockHeight' ) || '' ;
47- const routerEndTime = searchParams . get ( 'endTime' ) || '' ;
47+ let routerBlockHeight = searchParams . get ( 'blockHeight' ) || '' ;
48+ let routerEndTime = searchParams . get ( 'endTime' ) || '' ;
4849 const routerInteractionsPerPage =
4950 searchParams . get ( 'interactionsPerPage' ) || '' ;
5051 const routerRunId = searchParams . get ( 'runId' ) || '' ;
51- const routerStartTime = searchParams . get ( 'startTime' ) || '' ;
52+ let routerStartTime = searchParams . get ( 'startTime' ) || '' ;
53+
54+ if ( ! routerBlockHeight . match ( IS_NUMBER_REGEX ) ) routerBlockHeight = '' ;
55+ if ( ! routerEndTime . match ( IS_NUMBER_REGEX ) ) routerEndTime = '' ;
56+ if ( ! routerStartTime . match ( IS_NUMBER_REGEX ) ) routerStartTime = '' ;
5257
5358 const fetchData = async ( ) => {
5459 if ( ! ( routerBlockHeight || routerEndTime || routerRunId || routerStartTime ) )
55- return ;
60+ return setData ( {
61+ interactions : [ ] ,
62+ runIds : [ ] ,
63+ vats : [ ] ,
64+ } ) ;
5665
5766 setState ( ( prevState ) => ( {
5867 ...prevState ,
@@ -127,18 +136,15 @@ const Neo4jSequenceDiagram = () => {
127136 useEffect ( ( ) => {
128137 if ( ! state . connectionHealthy ) return ;
129138
130- const currentTimestamp = Date . now ( ) ;
131-
132139 setState ( ( prevState ) => ( {
133140 ...prevState ,
134141 blockHeight : routerBlockHeight ,
135- endTime : routerEndTime || String ( currentTimestamp / 1000 ) ,
142+ endTime : routerEndTime ,
136143 interactionsPerPage : getSanitizedInteractionsPerPage (
137144 routerInteractionsPerPage ,
138145 ) ,
139146 runId : routerRunId ,
140- startTime :
141- routerStartTime || String ( ( currentTimestamp - 10 * 1000 ) / 1000 ) ,
147+ startTime : routerStartTime ,
142148 } ) ) ;
143149
144150 fetchData ( ) ;
@@ -184,7 +190,7 @@ const Neo4jSequenceDiagram = () => {
184190 < input
185191 className = { FORM_INPUT_CLASSES }
186192 onChange = { ( { target : { value : blockHeight } } ) =>
187- ! ( blockHeight && isNaN ( Number ( blockHeight ) ) ) &&
193+ ( ! blockHeight || blockHeight . match ( IS_NUMBER_REGEX ) ) &&
188194 setState ( ( prevState ) => ( { ...prevState , blockHeight } ) )
189195 }
190196 type = "text"
@@ -200,7 +206,7 @@ const Neo4jSequenceDiagram = () => {
200206 < input
201207 className = { FORM_INPUT_CLASSES }
202208 onChange = { ( { target : { value : startTime } } ) =>
203- ( ! startTime || Number ( startTime ) ) &&
209+ ( ! startTime || startTime . match ( IS_NUMBER_REGEX ) ) &&
204210 setState ( ( prevState ) => ( { ...prevState , startTime } ) )
205211 }
206212 placeholder = "1629570627.218393"
@@ -217,7 +223,7 @@ const Neo4jSequenceDiagram = () => {
217223 < input
218224 className = { FORM_INPUT_CLASSES }
219225 onChange = { ( { target : { value : endTime } } ) =>
220- ( ! endTime || Number ( endTime ) ) &&
226+ ( ! endTime || endTime . match ( IS_NUMBER_REGEX ) ) &&
221227 setState ( ( prevState ) => ( { ...prevState , endTime } ) )
222228 }
223229 placeholder = "1829570627.218393"
@@ -278,15 +284,13 @@ const Neo4jSequenceDiagram = () => {
278284 router . push (
279285 '/?' +
280286 [
281- ! isNaN ( Number ( state . blockHeight ) ) &&
282- `blockHeight=${ state . blockHeight } ` ,
287+ state . blockHeight && `blockHeight=${ state . blockHeight } ` ,
283288 'currentPage=1' ,
284289 state . endTime && `endTime=${ state . endTime } ` ,
285290 state . interactionsPerPage &&
286291 `interactionsPerPage=${ state . interactionsPerPage } ` ,
287292 state . runId && `runId=${ state . runId } ` ,
288- ! isNaN ( Number ( state . startTime ) ) &&
289- `startTime=${ state . startTime } ` ,
293+ state . startTime && `startTime=${ state . startTime } ` ,
290294 ]
291295 . filter ( Boolean )
292296 . join ( '&' ) ,
0 commit comments