Skip to content

Commit cbc6027

Browse files
committed
fix(spend-allocations): normalize singular billingMetric values for category select - Added normalizeBillingMetric function to map singular billingMetric values (e.g., 'error', 'attachment') to their plural DataCategory enum equivalents. - Updated selectedMetric initialization to use the normalization function, ensuring correct default selection in the allocation form modal.
1 parent d39033d commit cbc6027

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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,16 @@ const Select = styled(SelectField)`
544544
padding-left: 0;
545545
}
546546
`;
547+
548+
// Normalizes singular billingMetric values to match DataCategory enum
549+
function normalizeBillingMetric(metric: string): DataCategory {
550+
switch (metric) {
551+
case 'error':
552+
return DataCategory.ERRORS;
553+
case 'attachment':
554+
return DataCategory.ATTACHMENTS;
555+
// Add more mappings as needed
556+
default:
557+
return metric as DataCategory;
558+
}
559+
}

0 commit comments

Comments
 (0)