layout.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 {useMetricsContext} from 'sentry/views/metrics/context';
  21. import {useMetricsOnboardingSidebar} from 'sentry/views/metrics/ddmOnboarding/useMetricsOnboardingSidebar';
  22. import {IntervalSelect} from 'sentry/views/metrics/intervalSelect';
  23. import {PageHeaderActions} from 'sentry/views/metrics/pageHeaderActions';
  24. import {Queries} from 'sentry/views/metrics/queries';
  25. import {MetricScratchpad} from 'sentry/views/metrics/scratchpad';
  26. import {WidgetDetails} from 'sentry/views/metrics/widgetDetails';
  27. export const MetricsLayout = memo(() => {
  28. const organization = useOrganization();
  29. const {hasMetrics} = useMetricsContext();
  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="beta" />
  59. </Layout.Title>
  60. </Layout.HeaderContent>
  61. <Layout.HeaderActions>
  62. <PageHeaderActions
  63. showCustomMetricButton={hasMetrics}
  64. addCustomMetric={() => addCustomMetric('header')}
  65. />
  66. </Layout.HeaderActions>
  67. </Layout.Header>
  68. <Layout.Body>
  69. <FloatingFeedbackWidget />
  70. <Layout.Main fullWidth>
  71. <FilterContainer>
  72. <PageFilterBar condensed>
  73. <ProjectPageFilter />
  74. <EnvironmentPageFilter />
  75. <DatePageFilter />
  76. </PageFilterBar>
  77. <IntervalSelect />
  78. </FilterContainer>
  79. {hasMetrics ? (
  80. <Fragment>
  81. <Queries />
  82. <MetricScratchpad />
  83. <WidgetDetails />
  84. </Fragment>
  85. ) : (
  86. <OnboardingPanel image={<EmptyStateImage src={emptyStateImg} />}>
  87. <h3>{t('Get started with custom metrics')}</h3>
  88. <p>
  89. {t(
  90. "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."
  91. )}
  92. </p>
  93. <Button
  94. priority="primary"
  95. onClick={() => addCustomMetric('onboarding_panel')}
  96. >
  97. {t('Add Custom Metric')}
  98. </Button>
  99. </OnboardingPanel>
  100. )}
  101. </Layout.Main>
  102. </Layout.Body>
  103. </Fragment>
  104. );
  105. });
  106. const FilterContainer = styled('div')`
  107. margin-bottom: ${space(2)};
  108. display: flex;
  109. justify-content: flex-start;
  110. flex-wrap: wrap;
  111. gap: ${space(1)};
  112. `;
  113. const EmptyStateImage = styled('img')`
  114. @media (min-width: ${p => p.theme.breakpoints.small}) {
  115. user-select: none;
  116. position: absolute;
  117. top: 0;
  118. bottom: 0;
  119. width: 220px;
  120. margin-top: auto;
  121. margin-bottom: auto;
  122. transform: translateX(-50%);
  123. left: 50%;
  124. }
  125. @media (min-width: ${p => p.theme.breakpoints.large}) {
  126. transform: translateX(-60%);
  127. width: 280px;
  128. }
  129. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  130. transform: translateX(-75%);
  131. width: 320px;
  132. }
  133. `;