ddm.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import {useEffect} from 'react';
  2. import * as Sentry from '@sentry/react';
  3. import {Alert} from 'sentry/components/alert';
  4. import * as Layout from 'sentry/components/layouts/thirds';
  5. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  6. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  7. import {t} from 'sentry/locale';
  8. import {trackAnalytics} from 'sentry/utils/analytics';
  9. import {hasCustomMetrics} from 'sentry/utils/metrics/features';
  10. import useOrganization from 'sentry/utils/useOrganization';
  11. import {DDMContextProvider, useDDMContext} from 'sentry/views/ddm/context';
  12. import {MetricsLayout} from 'sentry/views/ddm/layout';
  13. import {useOptInModal} from 'sentry/views/ddm/optInModal';
  14. function WrappedPageFiltersContainer({children}: {children: React.ReactNode}) {
  15. const {isDefaultQuery} = useDDMContext();
  16. return (
  17. <PageFiltersContainer disablePersistence={isDefaultQuery}>
  18. {children}
  19. </PageFiltersContainer>
  20. );
  21. }
  22. function Metrics() {
  23. const organization = useOrganization();
  24. useOptInModal();
  25. useEffect(() => {
  26. trackAnalytics('ddm.page-view', {
  27. organization,
  28. });
  29. Sentry.metrics.increment('ddm.visit');
  30. // eslint-disable-next-line react-hooks/exhaustive-deps
  31. }, []);
  32. if (!hasCustomMetrics(organization)) {
  33. return (
  34. <Layout.Page withPadding>
  35. <Alert type="warning">{t("You don't have access to this feature")}</Alert>
  36. </Layout.Page>
  37. );
  38. }
  39. return (
  40. <SentryDocumentTitle title={t('Metrics')} orgSlug={organization.slug}>
  41. <DDMContextProvider>
  42. <WrappedPageFiltersContainer>
  43. <MetricsLayout />
  44. </WrappedPageFiltersContainer>
  45. </DDMContextProvider>
  46. </SentryDocumentTitle>
  47. );
  48. }
  49. export default Metrics;