Skip to content

Commit 95fb310

Browse files
authored
fix(spend-allocations): normalize singular billingMetric values for c… (#92196)
This PR addresses an issue where the Spend Allocation edit modal would not correctly pre-select the category if the backend provided a singular billingMetric value (e.g., "error" or "attachment") instead of the plural form expected by the frontend (e.g., "errors", "attachments"). What was changed: - Added a normalizeBillingMetric function to map singular billingMetric values to their correct plural DataCategory enum equivalents. - Updated the initialization of the selectedMetric state to use this normalization function, ensuring the correct default value is selected in the modal. Why: Without this normalization, users would see the category select default to an incorrect or empty value when editing allocations for certain categories, leading to confusion and escalation Fixes: #91213
1 parent 76e7bfa commit 95fb310

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

static/gsApp/views/spendAllocations/components/allocationForm.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type {Organization} from 'sentry/types/organization';
2222
import useApi from 'sentry/utils/useApi';
2323
import withOrganization from 'sentry/utils/withOrganization';
2424

25-
import {AllocationTargetTypes} from 'getsentry/constants';
25+
import {AllocationTargetTypes, BILLED_DATA_CATEGORY_INFO} from 'getsentry/constants';
2626
import type {Subscription} from 'getsentry/types';
2727
import {
2828
getCategoryInfoFromPlural,
@@ -64,7 +64,7 @@ function AllocationForm({
6464
const [showPrice, setShowPrice] = useState<boolean>(false);
6565
const [selectedMetric, setSelectedMetric] = useState<DataCategory>(
6666
initializedData
67-
? (initializedData.billingMetric as DataCategory)
67+
? normalizeBillingMetric(initializedData.billingMetric)
6868
: initialMetric && getCategoryInfoFromPlural(initialMetric)?.canAllocate
6969
? initialMetric
7070
: DataCategory.ERRORS // default to errors
@@ -544,3 +544,12 @@ const Select = styled(SelectField)`
544544
padding-left: 0;
545545
}
546546
`;
547+
548+
// Normalizes singular billingMetric values to match DataCategory enum using BILLED_DATA_CATEGORY_INFO
549+
function normalizeBillingMetric(metric: string): DataCategory {
550+
return (
551+
Object.values(BILLED_DATA_CATEGORY_INFO)
552+
.filter(info => info.canAllocate)
553+
.find(c => c.name === metric)?.plural ?? (metric as DataCategory)
554+
);
555+
}

0 commit comments

Comments
 (0)