Skip to content

Commit d7260ca

Browse files
committed
fix for divide by zero
1 parent cd15d51 commit d7260ca

File tree

1 file changed

+9
-2
lines changed
  • apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.metrics.custom.$dashboardId

1 file changed

+9
-2
lines changed

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.metrics.custom.$dashboardId/route.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ export default function Page() {
256256
const totalWidgetCount = Object.keys(state.widgets).length;
257257
const widgetLimits = { used: currentWidgetCount, limit: widgetLimitPerDashboard };
258258
const widgetIsAtLimit = currentWidgetCount >= widgetLimitPerDashboard;
259+
const widgetLimitRatio =
260+
widgetLimits.limit > 0
261+
? widgetLimits.used / widgetLimits.limit
262+
: widgetLimits.used > 0
263+
? 1
264+
: 0;
265+
const widgetLimitPercent = Math.min(100, Math.max(0, Math.round(widgetLimitRatio * 100)));
259266
const widgetCanUpgrade = plan?.v3Subscription?.plan && !canExceedWidgets;
260267

261268
// Build the query action URL for the editor
@@ -501,14 +508,14 @@ export default function Page() {
501508
r="10"
502509
cx="12"
503510
cy="12"
504-
strokeDasharray={`${(widgetLimits.used / widgetLimits.limit) * 62.8} 62.8`}
511+
strokeDasharray={`${widgetLimitRatio * 62.8} 62.8`}
505512
strokeDashoffset="0"
506513
strokeLinecap="round"
507514
/>
508515
</svg>
509516
</div>
510517
}
511-
content={`${Math.round((widgetLimits.used / widgetLimits.limit) * 100)}%`}
518+
content={`${widgetLimitPercent}%`}
512519
/>
513520
<div className="flex w-full items-center justify-between gap-6">
514521
{widgetIsAtLimit ? (

0 commit comments

Comments
 (0)