layout.tsx 4.7 KB

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