Skip to content

Commit

Permalink
Handles errors on card summaries (#1935)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravenac95 authored Aug 8, 2024
1 parent 98ca8b5 commit 4702c16
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions apps/frontend/lib/metrics-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Various utilities for using metrics on the frontend
*/
import { logger } from "./logger";
import { groupRegistrations, registerFunction } from "./plasmic-register";

type ColumnReferenceFunc = (...args: any) => any;
Expand Down Expand Up @@ -30,17 +31,27 @@ function summarizeForCards(
metrics: Record<string, string>[],
cards: CardSummaryOptions[],
): CardSummary[] {
return cards.map((card) => {
let value = card.operation(metrics, card.column);
if (typeof value === "number") {
value = value.toLocaleString();
const summary: CardSummary[] = [];
cards.forEach((card) => {
try {
let value = card.operation(metrics, card.column);
console.log(metrics);
if (typeof value === "number") {
value = value.toLocaleString();
}
summary.push({
title: card.title,
subtitle: card.subtitle,
value: value,
});
} catch (e) {
logger.warn(
`error processing column ${card.column} for card rendering. skipping`,
);
return;
}
return {
title: card.title,
subtitle: card.subtitle,
value: value,
};
});
return summary;
}

export const register = groupRegistrations(
Expand Down

0 comments on commit 4702c16

Please sign in to comment.