Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions static/gsAdmin/components/addGiftEventsAction.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {DataCategory, DataCategoryExact} from 'sentry/types/core';

import {AddGiftEventsAction} from 'admin/components/addGiftEventsAction';
import {openAdminConfirmModal} from 'admin/components/adminConfirmationModal';
import {BILLED_DATA_CATEGORY_INFO} from 'getsentry/constants';
import {getBilledDataCategoryInfo} from 'getsentry/constants';
import {getCategoryInfoFromPlural} from 'getsentry/utils/dataCategory';

describe('AddGiftEventsAction', () => {
Expand All @@ -18,7 +18,7 @@ describe('AddGiftEventsAction', () => {
const triggerGiftModal = () => {
const billedCategoryInfo = categoryOverride
? getCategoryInfoFromPlural(categoryOverride)
: BILLED_DATA_CATEGORY_INFO[DataCategoryExact.SPAN];
: getBilledDataCategoryInfo()[DataCategoryExact.SPAN];
openAdminConfirmModal({
renderModalSpecificContent: deps => (
<AddGiftEventsAction
Expand Down
4 changes: 2 additions & 2 deletions static/gsAdmin/components/customers/customerOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {DetailList} from 'admin/components/detailList';
import {DetailsContainer} from 'admin/components/detailsContainer';
import {ExtendProductTrialAction} from 'admin/components/extendProductTrialAction';
import {getLogQuery} from 'admin/utils';
import {BILLED_DATA_CATEGORY_INFO, UNLIMITED} from 'getsentry/constants';
import {getBilledDataCategoryInfo, UNLIMITED} from 'getsentry/constants';
import type {
Plan,
ReservedBudget,
Expand Down Expand Up @@ -482,7 +482,7 @@ export function CustomerOverview({customer, onAction, organization}: Props) {
// TODO(cells) We also should show the customer's cell.
const locality = localityMap[organization.links.regionUrl] ?? '??';

const productTrialCategories = Object.values(BILLED_DATA_CATEGORY_INFO).filter(
const productTrialCategories = Object.values(getBilledDataCategoryInfo()).filter(
categoryInfo => {
// Category must be in the plan's categories
if (!customer.planDetails?.categories.includes(categoryInfo.plural)) {
Expand Down
6 changes: 3 additions & 3 deletions static/gsApp/components/gsBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {ProductTrialAlert} from 'getsentry/components/productTrial/productTrialA
import {getProductForPath} from 'getsentry/components/productTrial/productTrialPaths';
import {makeLinkToOwnersAndBillingMembers} from 'getsentry/components/profiling/alerts';
import {withSubscription} from 'getsentry/components/withSubscription';
import {BILLED_DATA_CATEGORY_INFO} from 'getsentry/constants';
import {getBilledDataCategoryInfo} from 'getsentry/constants';
import {SubscriptionStore} from 'getsentry/stores/subscriptionStore';
import {
type BilledDataCategoryInfo,
Expand Down Expand Up @@ -80,7 +80,7 @@ enum ModalType {
const TRIAL_ENDING_DAY_WINDOW = 3;

function objectFromBilledCategories(callback: (c: BilledDataCategoryInfo) => any) {
return Object.values(BILLED_DATA_CATEGORY_INFO).reduce(
return Object.values(getBilledDataCategoryInfo()).reduce(
(acc, c) => {
if (c.isBilledCategory) {
acc[c.singular as EventType] = callback(c);
Expand Down Expand Up @@ -634,7 +634,7 @@ class GSBanner extends Component<Props, State> {
const category_warning_prompts: string[] = [];
const category_product_trial_prompts: string[] = [];

Object.values(BILLED_DATA_CATEGORY_INFO)
Object.values(getBilledDataCategoryInfo())
.filter(
categoryInfo =>
categoryInfo.isBilledCategory &&
Expand Down
13 changes: 12 additions & 1 deletion static/gsApp/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Object.entries(DEFAULT_BILLED_DATA_CATEGORY_INFO).forEach(
* All categories with isBilledCategory: true, should be explicitly
* added to this object with billing info.
*/
export const BILLED_DATA_CATEGORY_INFO = {
const BILLED_DATA_CATEGORY_INFO = {
...DEFAULT_BILLED_DATA_CATEGORY_INFO,
[DataCategoryExact.ERROR]: {
...DEFAULT_BILLED_DATA_CATEGORY_INFO[DataCategoryExact.ERROR],
Expand Down Expand Up @@ -234,3 +234,14 @@ export const BILLED_DATA_CATEGORY_INFO = {
adminOnlyProductTrialFeature: 'expose-category-installable-build',
},
} as const satisfies Record<DataCategoryExact, BilledDataCategoryInfo>;

/**
* Returns billing-enriched data category info for all categories.
* This wraps the static constant so it can later be replaced with a backend call.
*/
export function getBilledDataCategoryInfo(): Record<
DataCategoryExact,
BilledDataCategoryInfo
> {
return BILLED_DATA_CATEGORY_INFO;
}
Comment thread
volokluev marked this conversation as resolved.
Outdated
6 changes: 4 additions & 2 deletions static/gsApp/utils/dataCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {DataCategory, DataCategoryExact} from 'sentry/types/core';
import {oxfordizeArray} from 'sentry/utils/oxfordizeArray';
import {toTitleCase} from 'sentry/utils/string/toTitleCase';

import {BILLED_DATA_CATEGORY_INFO, UNLIMITED_RESERVED} from 'getsentry/constants';
import {getBilledDataCategoryInfo, UNLIMITED_RESERVED} from 'getsentry/constants';
import type {
BilledDataCategoryInfo,
BillingMetricHistory,
Expand All @@ -28,7 +28,9 @@ import {MILLISECONDS_IN_HOUR} from 'getsentry/utils/billing';
export function getCategoryInfoFromPlural(
category: DataCategory
): BilledDataCategoryInfo | null {
const info = Object.values(BILLED_DATA_CATEGORY_INFO).find(c => c.plural === category);
const info = Object.values(getBilledDataCategoryInfo()).find(
c => c.plural === category
);
if (!info) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {RequestMethod} from 'sentry/utils/api/apiQueryKey';
import {useApi} from 'sentry/utils/useApi';
import {useOrganization} from 'sentry/utils/useOrganization';

import {AllocationTargetTypes, BILLED_DATA_CATEGORY_INFO} from 'getsentry/constants';
import {AllocationTargetTypes, getBilledDataCategoryInfo} from 'getsentry/constants';
import type {Subscription} from 'getsentry/types';
import {
getCategoryInfoFromPlural,
Expand Down Expand Up @@ -541,10 +541,10 @@ const Select = styled(SelectField)`
}
`;

// Normalizes singular billingMetric values to match DataCategory enum using BILLED_DATA_CATEGORY_INFO
// Normalizes singular billingMetric values to match DataCategory enum using getBilledDataCategoryInfo()
function normalizeBillingMetric(metric: string): DataCategory {
return (
Object.values(BILLED_DATA_CATEGORY_INFO)
Object.values(getBilledDataCategoryInfo())
.filter(info => info.canAllocate)
.find(c => c.name === metric)?.plural ?? (metric as DataCategory)
);
Expand Down
Loading