diff --git a/frontend/src/ts/components/pages/connections/FriendsList.tsx b/frontend/src/ts/components/pages/connections/FriendsList.tsx index b5a9dbb050a7..29e26d5b61f8 100644 --- a/frontend/src/ts/components/pages/connections/FriendsList.tsx +++ b/frontend/src/ts/components/pages/connections/FriendsList.tsx @@ -179,17 +179,24 @@ function getColumns({ defineColumn("completedTests", { enableSorting: true, header: "tests", - cell: (info) => `${info.getValue()}/${info.row.original.startedTests}`, + cell: (info) => { + const completedTests = info.getValue(); + const startedTests = info.row.original.startedTests; + + return `${completedTests ?? 0}/${startedTests ?? 0}`; + }, meta: { breakpoint: "lg", cellMeta: ({ row }) => { const testStats = formatTypingStatsRatio(row); + if (testStats.completedPercentage === "") { + return {}; + } + return { "data-balloon-pos": "up", - "aria-label": `${testStats.completedPercentage}% (${ - testStats.restartRatio - } restarts per completed test)`, + "aria-label": `${testStats.completedPercentage}% (${testStats.restartRatio} restarts per completed test)`, }; }, }, diff --git a/frontend/src/ts/utils/misc.ts b/frontend/src/ts/utils/misc.ts index 6480e38ae000..61ce99a62efe 100644 --- a/frontend/src/ts/utils/misc.ts +++ b/frontend/src/ts/utils/misc.ts @@ -715,21 +715,22 @@ export function formatTypingStatsRatio(stats: { completedPercentage: string; restartRatio: string; } { - if ( - stats.completedTests === undefined || - stats.startedTests === undefined || - stats.startedTests === 0 - ) { - return { completedPercentage: "", restartRatio: "" }; + const startedTests = stats.startedTests ?? 0; + const completedTests = stats.completedTests ?? 0; + + if (startedTests === 0) { + return { completedPercentage: "0", restartRatio: "0" }; } + + const abandonedTests = startedTests - completedTests; + const restartRatio = + completedTests === 0 ? "0" : (abandonedTests / completedTests).toFixed(1); + return { completedPercentage: Math.floor( - (stats.completedTests / stats.startedTests) * 100, + (completedTests / startedTests) * 100, ).toString(), - restartRatio: ( - (stats.startedTests - stats.completedTests) / - stats.completedTests - ).toFixed(1), + restartRatio, }; }