Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App overview updates #508

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,37 @@ import {
Text,
} from "@pokt-foundation/pocket-blocks"
import { AnalyticsRelaysAggregated } from "~/models/dwh/sdk/models/AnalyticsRelaysAggregated"
import { getTotalErrors } from "~/utils/chartUtils"
import { commify } from "~/utils/formattingUtils"

const labels: Record<keyof AnalyticsRelaysAggregated, string> = {
avgLatency: "Average Latency",
countTotal: "Total Relays",
rateSuccess: "Success Rate",
rateError: "Error Rate",
rateError: "Total Errors",
categoryValue: "Account",
date: "Date",
}

const getFormattedValue = (
aggregate: AnalyticsRelaysAggregated,
key: keyof AnalyticsRelaysAggregated,
) => {
if (!aggregate) return "-"

switch (key) {
case "avgLatency":
return aggregate[key] ? `${aggregate[key]}ms` : "-"
case "rateSuccess":
return aggregate[key] ? `${aggregate[key]}%` : "-"
case "rateError":
const errorsTotal = getTotalErrors(aggregate)
return errorsTotal ? commify(errorsTotal) : "-"
default:
return commify(String(aggregate[key]))
}
}

const order: (keyof AnalyticsRelaysAggregated)[] = [
"countTotal",
"avgLatency",
Expand Down Expand Up @@ -47,11 +68,7 @@ export const AccountAppsOverview = ({
const { classes } = useStyles()

if (!aggregate) {
return (
<>
<div>-</div>
</>
)
return <>-</>
}

return (
Expand All @@ -67,7 +84,7 @@ export const AccountAppsOverview = ({
<Box key={key} className={classes.stat}>
<Stack align="center" spacing={0}>
<Text fw={600} fz="md">
{isLoading ? <Loader size="sm" /> : String(aggregate[key])}
{isLoading ? <Loader size="sm" /> : getFormattedValue(aggregate, key)}
</Text>
<Text>{labels[key as keyof AnalyticsRelaysAggregated]}</Text>
</Stack>
Expand Down
Loading