Skip to content

Commit de63f55

Browse files
committed
UI fixes
1 parent 58d25be commit de63f55

3 files changed

Lines changed: 22 additions & 22 deletions

File tree

src/components/MermaidDiagram.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ mermaid.initialize({
3939
},
4040
});
4141

42-
type MermaidDiagramProps = {
43-
code: string;
44-
};
45-
4642
const MermaidDiagram = () => {
4743
const { interactions, vats } = useContext(InteractionContext);
4844
const pathName = usePathname();

src/components/Neo4jSequenceDiagram.tsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { getSanitizedInteractionsPerPage, parseTimestamp } from 'helpers';
1212

1313
const EXTRACT_VAT_ID_REGEX = /^v([0-9]*)$/;
14+
const IS_NUMBER_REGEX = /^[0-9]+(.[0-9]*)?$/;
1415

1516
const FORM_GROUP_CLASSES = 'flex flex-col gap-y-1';
1617
const 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('&'),

src/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const addParticipantTooltips = (
3434
interactions[
3535
currentPage * interactionsPerPage + Number(messageNumber) - 1
3636
];
37-
if (!interaction.crankNum) return;
37+
if (!interaction?.crankNum) return;
3838

3939
const horizontalPadding = 6;
4040
const verticalPadding = 3;
@@ -75,7 +75,7 @@ const addParticipantTooltips = (
7575
backgroundProvider.setAttribute('x', String(bbox.x - horizontalPadding));
7676
backgroundProvider.setAttribute('y', String(bbox.y - verticalPadding));
7777
backgroundProvider.classList.add(
78-
...'fill-yellow-100 stroke-gray-L200'.split(' '),
78+
...'fill-yellow-100 stroke-yellow-200'.split(' '),
7979
);
8080

8181
group.insertBefore(backgroundProvider, toolTip);

0 commit comments

Comments
 (0)