Browse Source

feat(self-hosted): Remove other categories from stats dropdown for errors only sh (#72154)

![Screenshot 2024-06-05 at 11 37
39 AM](https://github.com/getsentry/sentry/assets/25517925/6efb9118-e94d-45eb-8d62-7960f881010d)
Hubert Deng 9 months ago
parent
commit
113ee48d3b

+ 13 - 0
static/app/views/organizationStats/index.spec.tsx

@@ -1,10 +1,12 @@
 import {ProjectFixture} from 'sentry-fixture/project';
+import {UserFixture} from 'sentry-fixture/user';
 
 import {initializeOrg} from 'sentry-test/initializeOrg';
 import {act, render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
 
 import {DATA_CATEGORY_INFO, DEFAULT_STATS_PERIOD} from 'sentry/constants';
 import {ALL_ACCESS_PROJECTS} from 'sentry/constants/pageFilters';
+import ConfigStore from 'sentry/stores/configStore';
 import OrganizationStore from 'sentry/stores/organizationStore';
 import PageFiltersStore from 'sentry/stores/pageFiltersStore';
 import ProjectsStore from 'sentry/stores/projectsStore';
@@ -55,6 +57,8 @@ describe('OrganizationStats', function () {
       url: endpoint,
       body: mockStatsResponse,
     });
+    ConfigStore.init();
+    ConfigStore.set('user', UserFixture());
   });
 
   afterEach(() => {
@@ -167,6 +171,15 @@ describe('OrganizationStats', function () {
     expect(screen.getByTestId('empty-message')).toBeInTheDocument();
   });
 
+  it('renders with just errors category for errors-only self-hosted', async () => {
+    ConfigStore.set('isSelfHostedErrorsOnly', true);
+    render(<OrganizationStats {...defaultProps} />, {router});
+    await userEvent.click(await screen.findByText('Category'));
+    // Shows only errors as stats category
+    expect(screen.getAllByRole('option')).toHaveLength(1);
+    expect(screen.getByRole('option', {name: 'Errors'})).toBeInTheDocument();
+  });
+
   /**
    * Router Handling
    */

+ 5 - 0
static/app/views/organizationStats/index.tsx

@@ -22,6 +22,7 @@ import type {ChangeData} from 'sentry/components/timeRangeSelector';
 import {DATA_CATEGORY_INFO, DEFAULT_STATS_PERIOD} from 'sentry/constants';
 import {ALL_ACCESS_PROJECTS} from 'sentry/constants/pageFilters';
 import {t, tct} from 'sentry/locale';
+import ConfigStore from 'sentry/stores/configStore';
 import {space} from 'sentry/styles/space';
 import type {DataCategoryInfo, DateString, PageFilters} from 'sentry/types/core';
 import type {Organization} from 'sentry/types/organization';
@@ -230,8 +231,12 @@ export class OrganizationStats extends Component<OrganizationStatsProps> {
 
   renderProjectPageControl = () => {
     const {organization} = this.props;
+    const isSelfHostedErrorsOnly = ConfigStore.get('isSelfHostedErrorsOnly');
 
     const options = CHART_OPTIONS_DATACATEGORY.filter(opt => {
+      if (isSelfHostedErrorsOnly) {
+        return opt.value === DATA_CATEGORY_INFO.error.plural;
+      }
       if (opt.value === DATA_CATEGORY_INFO.replay.plural) {
         return organization.features.includes('session-replay');
       }