Skip to content

Commit 34269b7

Browse files
feat(billing): Formatting utility for Logs (#95450)
Closes: https://linear.app/getsentry/issue/BIL-1098/add-formatting-for-changeplanaction Refactors duplicate byte category checks into a reusable utility function --------- Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
1 parent 82e2139 commit 34269b7

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

static/gsAdmin/components/planList.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import Form from 'sentry/components/forms/form';
99
import type FormModel from 'sentry/components/forms/model';
1010
import type {Data, OnSubmitCallback} from 'sentry/components/forms/types';
1111
import {space} from 'sentry/styles/space';
12-
import {DataCategory} from 'sentry/types/core';
12+
import type {DataCategory} from 'sentry/types/core';
1313
import type {Organization} from 'sentry/types/organization';
1414
import {toTitleCase} from 'sentry/utils/string/toTitleCase';
1515

1616
import {ANNUAL} from 'getsentry/constants';
1717
import type {BillingConfig, Plan, Subscription} from 'getsentry/types';
18-
import {getPlanCategoryName} from 'getsentry/utils/dataCategory';
18+
import {getPlanCategoryName, isByteCategory} from 'getsentry/utils/dataCategory';
1919
import formatCurrency from 'getsentry/utils/formatCurrency';
2020

2121
type Props = {
@@ -58,7 +58,7 @@ function PlanList({
5858
return (
5959
<CurrentValueText>
6060
Current: {reservedValue.toLocaleString()}{' '}
61-
{category === DataCategory.ATTACHMENTS ? 'GB' : ''}
61+
{isByteCategory(category) ? 'GB' : ''}
6262
</CurrentValueText>
6363
);
6464
}
@@ -147,10 +147,9 @@ function PlanList({
147147
const reservedKey = `reserved${toTitleCase(category, {
148148
allowInnerUpperCase: true,
149149
})}`;
150-
const label =
151-
category === DataCategory.ATTACHMENTS
152-
? `${titleCategory} (GB)`
153-
: titleCategory;
150+
const label = isByteCategory(category)
151+
? `${titleCategory} (GB)`
152+
: titleCategory;
154153
const fieldValue = formModel.getValue(reservedKey);
155154
const currentValueDisplay = getCurrentValueDisplay(category);
156155
return (

static/gsApp/utils/billing.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import type {
2626
Subscription,
2727
} from 'getsentry/types';
2828
import {OnDemandBudgetMode, PlanName, PlanTier} from 'getsentry/types';
29-
import {isContinuousProfiling} from 'getsentry/utils/dataCategory';
29+
import {isByteCategory, isContinuousProfiling} from 'getsentry/utils/dataCategory';
3030
import titleCase from 'getsentry/utils/titleCase';
3131
import {displayPriceWithCents} from 'getsentry/views/amCheckout/utils';
3232

@@ -138,10 +138,7 @@ export function formatReservedWithUnits(
138138
if (isReservedBudget) {
139139
return displayPriceWithCents({cents: reservedQuantity ?? 0});
140140
}
141-
if (
142-
dataCategory !== DataCategory.ATTACHMENTS &&
143-
dataCategory !== DataCategory.LOG_BYTE
144-
) {
141+
if (!isByteCategory(dataCategory)) {
145142
return formatReservedNumberToString(reservedQuantity, options);
146143
}
147144
// convert reservedQuantity to BYTES to check for unlimited
@@ -168,10 +165,7 @@ export function formatUsageWithUnits(
168165
dataCategory: DataCategory,
169166
options: FormatOptions = {isAbbreviated: false, useUnitScaling: false}
170167
) {
171-
if (
172-
dataCategory === DataCategory.ATTACHMENTS ||
173-
dataCategory === DataCategory.LOG_BYTE
174-
) {
168+
if (isByteCategory(dataCategory)) {
175169
if (options.useUnitScaling) {
176170
return formatByteUnits(usageQuantity);
177171
}

static/gsApp/views/subscriptionPage/reservedUsageChart.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {
5454
import {
5555
getPlanCategoryName,
5656
hasCategoryFeature,
57+
isByteCategory,
5758
isPartOfReservedBudget,
5859
} from 'getsentry/utils/dataCategory';
5960
import formatCurrency from 'getsentry/utils/formatCurrency';
@@ -188,7 +189,7 @@ function mapReservedToChart(reserved: number | null, category: DataCategory) {
188189
return 0;
189190
}
190191

191-
if (category === DataCategory.ATTACHMENTS) {
192+
if (isByteCategory(category)) {
192193
return typeof reserved === 'number' ? reserved * GIGABYTE : 0;
193194
}
194195
return reserved || 0;

static/gsApp/views/subscriptionPage/usageAlert.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ import {
2323
isUnlimitedReserved,
2424
UsageAction,
2525
} from 'getsentry/utils/billing';
26-
import {getPlanCategoryName, sortCategoriesWithKeys} from 'getsentry/utils/dataCategory';
26+
import {
27+
getPlanCategoryName,
28+
isByteCategory,
29+
sortCategoriesWithKeys,
30+
} from 'getsentry/utils/dataCategory';
2731

2832
import {ButtonWrapper, SubscriptionBody} from './styles';
2933

@@ -86,8 +90,9 @@ function UsageAlert({subscription, usage}: Props) {
8690
return acc;
8791
}
8892
const projected = usage.totals[category]?.projected || 0;
89-
const projectedWithReservedUnit =
90-
category === DataCategory.ATTACHMENTS ? projected / GIGABYTE : projected;
93+
const projectedWithReservedUnit = isByteCategory(category)
94+
? projected / GIGABYTE
95+
: projected;
9196

9297
const hasOverage =
9398
!!currentHistory.reserved &&

0 commit comments

Comments
 (0)