diff --git a/static/app/views/organizationStats/index.spec.tsx b/static/app/views/organizationStats/index.spec.tsx index ae8b84701729..78239164e972 100644 --- a/static/app/views/organizationStats/index.spec.tsx +++ b/static/app/views/organizationStats/index.spec.tsx @@ -218,6 +218,25 @@ describe('OrganizationStats', () => { ); }); + it('defaults to errors when dataCategory does not support external stats', async () => { + // Categories like monitorSeats have showExternalStats=false and are absent from + // CHART_OPTIONS_DATACATEGORY. Passing them via the URL should fall back to errors + // rather than crashing the chart with "Selected item is not supported". + render(, { + organization, + initialRouterConfig: { + location: { + pathname: '/organizations/org-slug/stats/', + query: {dataCategory: DATA_CATEGORY_INFO.monitor_seat.plural}, + }, + }, + }); + + // Should render without throwing and default to the Errors category + expect(await screen.findByText('Project(s) Stats')).toBeInTheDocument(); + expect(screen.getAllByText('Errors')[0]).toBeInTheDocument(); + }); + it('does not leak query params onto next page links', async () => { render(, { organization, diff --git a/static/app/views/organizationStats/index.tsx b/static/app/views/organizationStats/index.tsx index 2c915c178dc7..701c313cff60 100644 --- a/static/app/views/organizationStats/index.tsx +++ b/static/app/views/organizationStats/index.tsx @@ -75,7 +75,12 @@ export class OrganizationStatsInner extends Component { const dataCategoryPlural = this.props.location?.query?.dataCategory; const categories = Object.values(DATA_CATEGORY_INFO); - const info = categories.find(c => c.plural === dataCategoryPlural); + // Only consider categories that are shown in the usage chart (showExternalStats). + // Categories that don't have showExternalStats (e.g. monitorSeats) are not + // present in CHART_OPTIONS_DATACATEGORY and would cause a crash in UsageChart. + const info = categories.find( + c => c.plural === dataCategoryPlural && c.statsInfo.showExternalStats + ); // Default to errors return info ?? DATA_CATEGORY_INFO.error;