layout.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import {Fragment, memo, useCallback} from 'react';
  2. import styled from '@emotion/styled';
  3. import * as Sentry from '@sentry/react';
  4. import emptyStateImg from 'sentry-images/spot/custom-metrics-empty-state.svg';
  5. import Feature from 'sentry/components/acl/feature';
  6. import {Button} from 'sentry/components/button';
  7. import FeatureBadge from 'sentry/components/featureBadge';
  8. import FloatingFeedbackWidget from 'sentry/components/feedback/widget/floatingFeedbackWidget';
  9. import * as Layout from 'sentry/components/layouts/thirds';
  10. import OnboardingPanel from 'sentry/components/onboardingPanel';
  11. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  12. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  13. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  14. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  15. import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  16. import {t} from 'sentry/locale';
  17. import {space} from 'sentry/styles/space';
  18. import {trackAnalytics} from 'sentry/utils/analytics';
  19. import {METRICS_DOCS_URL} from 'sentry/utils/metrics/constants';
  20. import useOrganization from 'sentry/utils/useOrganization';
  21. import {useDDMContext} from 'sentry/views/ddm/context';
  22. import {useMetricsOnboardingSidebar} from 'sentry/views/ddm/ddmOnboarding/useMetricsOnboardingSidebar';
  23. import {PageHeaderActions} from 'sentry/views/ddm/pageHeaderActions';
  24. import {Queries} from 'sentry/views/ddm/queries';
  25. import {MetricScratchpad} from 'sentry/views/ddm/scratchpad';
  26. import {WidgetDetails} from 'sentry/views/ddm/widgetDetails';
  27. export const DDMLayout = memo(() => {
  28. const organization = useOrganization();
  29. const {hasMetrics} = useDDMContext();
  30. const {activateSidebar} = useMetricsOnboardingSidebar();
  31. const addCustomMetric = useCallback(
  32. (referrer: 'header' | 'onboarding_panel') => {
  33. Sentry.metrics.increment('ddm.add_custom_metric', 1, {
  34. tags: {
  35. referrer,
  36. },
  37. });
  38. trackAnalytics('ddm.open-onboarding', {
  39. organization,
  40. source: referrer,
  41. });
  42. activateSidebar();
  43. },
  44. [activateSidebar, organization]
  45. );
  46. return (
  47. <Fragment>
  48. <Layout.Header>
  49. <Layout.HeaderContent>
  50. <Layout.Title>
  51. {t('Metrics')}
  52. <PageHeadingQuestionTooltip
  53. docsUrl={METRICS_DOCS_URL}
  54. title={t(
  55. 'Metrics help you track and visualize the data points you care about, making it easier to monitor your application health and identify issues.'
  56. )}
  57. />
  58. <FeatureBadge type="alpha" />
  59. </Layout.Title>
  60. </Layout.HeaderContent>
  61. <Layout.HeaderActions>
  62. <Feature
  63. hookName="feature-disabled:dashboards-edit"
  64. features="organizations:dashboards-edit"
  65. >
  66. {({hasFeature}) => (
  67. <PageHeaderActions
  68. showCustomMetricButton={hasMetrics}
  69. addCustomMetric={() => addCustomMetric('header')}
  70. hasDashboardFeature={hasFeature}
  71. />
  72. )}
  73. </Feature>
  74. </Layout.HeaderActions>
  75. </Layout.Header>
  76. <Layout.Body>
  77. <FloatingFeedbackWidget />
  78. <Layout.Main fullWidth>
  79. <PaddedContainer>
  80. <PageFilterBar condensed>
  81. <ProjectPageFilter />
  82. <EnvironmentPageFilter />
  83. <DatePageFilter />
  84. </PageFilterBar>
  85. </PaddedContainer>
  86. {hasMetrics ? (
  87. <Fragment>
  88. <Queries />
  89. <MetricScratchpad />
  90. <WidgetDetails />
  91. </Fragment>
  92. ) : (
  93. <OnboardingPanel image={<EmptyStateImage src={emptyStateImg} />}>
  94. <h3>{t('Get started with custom metrics')}</h3>
  95. <p>
  96. {t(
  97. "Send your own metrics to Sentry to track your system's behaviour and profit from the same powerful features as you do with errors, like alerting and dashboards."
  98. )}
  99. </p>
  100. <Button
  101. priority="primary"
  102. onClick={() => addCustomMetric('onboarding_panel')}
  103. >
  104. {t('Add Custom Metric')}
  105. </Button>
  106. </OnboardingPanel>
  107. )}
  108. </Layout.Main>
  109. </Layout.Body>
  110. </Fragment>
  111. );
  112. });
  113. const PaddedContainer = styled('div')`
  114. margin-bottom: ${space(2)};
  115. display: flex;
  116. justify-content: space-between;
  117. flex-wrap: wrap;
  118. gap: ${space(1)};
  119. `;
  120. const EmptyStateImage = styled('img')`
  121. @media (min-width: ${p => p.theme.breakpoints.small}) {
  122. user-select: none;
  123. position: absolute;
  124. top: 0;
  125. bottom: 0;
  126. width: 220px;
  127. margin-top: auto;
  128. margin-bottom: auto;
  129. transform: translateX(-50%);
  130. left: 50%;
  131. }
  132. @media (min-width: ${p => p.theme.breakpoints.large}) {
  133. transform: translateX(-60%);
  134. width: 280px;
  135. }
  136. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  137. transform: translateX(-75%);
  138. width: 320px;
  139. }
  140. `;