Skip to content

Commit

Permalink
fix human readable logs data
Browse files Browse the repository at this point in the history
  • Loading branch information
LoV432 committed Nov 6, 2023
1 parent 85aaf56 commit 6529848
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/components/dashboard/ConnectionLogsListModal.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ function ConnectionLogsList({ days }: { days: number }) {
}, [days]);
return (
<div className="overflow-x-auto">
{humanReadableDisconnectedTime !== 'No Disconnects' ? (
<div className="badge badge-error h-fit gap-2">
{!humanReadableDisconnectedTime.includes('No Disconnects') ? (
<div className="h-fit gap-2 text-error">
{humanReadableDisconnectedTime}
</div>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function DashboardCardTotalDisconnectTime({
<>
<DashboardCardBase backgroundColor={backgroundColor}>
<div className="text-xl font-bold">
{humanReadableDisconnectedTime} in 24 hours
{humanReadableDisconnectedTime}
<Image
onClick={toggleConnectionLogsListModal}
className="ml-3 inline cursor-pointer"
Expand Down
12 changes: 8 additions & 4 deletions lib/logs-list-to-human-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ export function connectionLogsListToHumanFormat(
allConnectionLogs: connectionLogsList,
totalDays = 1
) {
const totalDaysString =
totalDays > 1 ? `last ${totalDays} days` : `past 24 hours`;

const noDisconnectsReturnString = `No Disconnects in ${totalDaysString}`;
if (allConnectionLogs.length === 0) {
return 'No Disconnects';
return noDisconnectsReturnString;
}
allConnectionLogs = allConnectionLogs.reverse();

Expand All @@ -32,7 +36,7 @@ export function connectionLogsListToHumanFormat(
minute: '2-digit'
})}`;
}
return 'No Disconnects';
return noDisconnectsReturnString;
}

let totalDisconnects = 0;
Expand Down Expand Up @@ -73,7 +77,7 @@ export function connectionLogsListToHumanFormat(
}

if (totalDisconnects === 0 && totalDowntimeInMS === 0) {
return 'No Disconnects';
return noDisconnectsReturnString;
}

// This will happen when there is no disconnect within the time frame of totalDays but there is a downtime
Expand All @@ -83,7 +87,7 @@ export function connectionLogsListToHumanFormat(
const totalDisconnectsString = totalDisconnectsToString(totalDisconnects);
const totalDowntimeString = millisecondsToReadableTime(totalDowntimeInMS);

return `${totalDisconnectsString} with ${totalDowntimeString} of downtime`;
return `${totalDisconnectsString} with ${totalDowntimeString} of downtime in ${totalDaysString}`;
}

function totalDisconnectsToString(totalDisconnects: number) {
Expand Down

0 comments on commit 6529848

Please sign in to comment.