Skip to content

Commit c5e175c

Browse files
Refactor ActivityLogCard to use pure for...of loops without array methods
Co-authored-by: joaquim.verges <[email protected]>
1 parent dcc462f commit c5e175c

File tree

1 file changed

+38
-21
lines changed

1 file changed

+38
-21
lines changed

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/transactions/tx/[id]/transaction-details-ui.tsx

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -382,22 +382,31 @@ function ActivityLogCard({
382382
}: {
383383
activityLogs: ActivityLogEntry[];
384384
}) {
385-
// Sort activity logs and prepare JSX elements using for...of loop
385+
// Sort activity logs and prepare JSX elements using pure for...of loops
386386
const renderActivityLogs = () => {
387-
if (activityLogs.length === 0) {
387+
// Check if activity logs is empty using for...of loop
388+
let hasAnyLogs = false;
389+
for (const _log of activityLogs) {
390+
hasAnyLogs = true;
391+
break;
392+
}
393+
394+
if (!hasAnyLogs) {
388395
return (
389396
<p className="text-muted-foreground text-sm">
390397
No activity logs available for this transaction
391398
</p>
392399
);
393400
}
394401

395-
// Sort logs chronologically using for...of loop (manual sorting)
402+
// Sort logs chronologically using pure for...of loops (manual sorting)
396403
const sortedLogs: ActivityLogEntry[] = [];
404+
let sortedLogsCount = 0;
397405

398-
// Copy all logs to sortedLogs first
406+
// Copy all logs to sortedLogs first using manual counting
399407
for (const log of activityLogs) {
400-
sortedLogs[sortedLogs.length] = log;
408+
sortedLogs[sortedLogsCount] = log;
409+
sortedLogsCount++;
401410
}
402411

403412
// Manual bubble sort using only for...of loops with manual index tracking
@@ -409,31 +418,39 @@ function ActivityLogCard({
409418
let currentIndex = 0;
410419

411420
for (const log of sortedLogs) {
412-
if (
413-
prevLog &&
414-
new Date(prevLog.createdAt).getTime() >
415-
new Date(log.createdAt).getTime()
416-
) {
417-
// Swap elements using manual assignment
418-
sortedLogs[prevIndex] = log;
419-
sortedLogs[currentIndex] = prevLog;
420-
sortingComplete = false;
421+
// Only process valid logs (skip undefined entries)
422+
if (log && currentIndex < sortedLogsCount) {
423+
if (
424+
prevLog &&
425+
new Date(prevLog.createdAt).getTime() >
426+
new Date(log.createdAt).getTime()
427+
) {
428+
// Swap elements using manual assignment
429+
sortedLogs[prevIndex] = log;
430+
sortedLogs[currentIndex] = prevLog;
431+
sortingComplete = false;
432+
}
433+
434+
prevLog = log;
435+
prevIndex = currentIndex;
421436
}
422-
423-
prevLog = log;
424-
prevIndex = currentIndex;
425437
currentIndex++;
426438
}
427439
}
428440

429441
const logElements: React.ReactElement[] = [];
442+
let logElementsCount = 0;
430443
let index = 0;
431444

432445
for (const log of sortedLogs) {
433-
const isLast = index === sortedLogs.length - 1;
434-
logElements[logElements.length] = (
435-
<ActivityLogEntryItem isLast={isLast} key={log.id} log={log} />
436-
);
446+
// Only process valid logs and within our count
447+
if (log && index < sortedLogsCount) {
448+
const isLast = index === sortedLogsCount - 1;
449+
logElements[logElementsCount] = (
450+
<ActivityLogEntryItem isLast={isLast} key={log.id} log={log} />
451+
);
452+
logElementsCount++;
453+
}
437454
index++;
438455
}
439456

0 commit comments

Comments
 (0)