layout.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 LoadingIndicator from 'sentry/components/loadingIndicator';
  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 {metricsMeta, isLoading} = useDDMContext();
  30. const hasMetrics = !isLoading && metricsMeta.length > 0;
  31. const {activateSidebar} = useMetricsOnboardingSidebar();
  32. const addCustomMetric = useCallback(
  33. (referrer: 'header' | 'onboarding_panel') => {
  34. Sentry.metrics.increment('ddm.add_custom_metric', 1, {
  35. tags: {
  36. referrer,
  37. },
  38. });
  39. trackAnalytics('ddm.open-onboarding', {
  40. organization,
  41. source: referrer,
  42. });
  43. activateSidebar();
  44. },
  45. [activateSidebar, organization]
  46. );
  47. return (
  48. <Fragment>
  49. <Layout.Header>
  50. <Layout.HeaderContent>
  51. <Layout.Title>
  52. {t('Metrics')}
  53. <PageHeadingQuestionTooltip
  54. docsUrl={METRICS_DOCS_URL}
  55. title={t(
  56. 'Metrics help you track and visualize the data points you care about, making it easier to monitor your application health and identify issues.'
  57. )}
  58. />
  59. <FeatureBadge type="alpha" />
  60. </Layout.Title>
  61. </Layout.HeaderContent>
  62. <Layout.HeaderActions>
  63. <PageHeaderActions
  64. showCustomMetricButton={hasMetrics}
  65. addCustomMetric={() => addCustomMetric('header')}
  66. />
  67. </Layout.HeaderActions>
  68. </Layout.Header>
  69. <Layout.Body>
  70. <FloatingFeedbackWidget />
  71. <Layout.Main fullWidth>
  72. <PaddedContainer>
  73. <PageFilterBar condensed>
  74. <ProjectPageFilter />
  75. <EnvironmentPageFilter />
  76. <DatePageFilter />
  77. </PageFilterBar>
  78. </PaddedContainer>
  79. {isLoading ? (
  80. <LoadingIndicator />
  81. ) : hasMetrics ? (
  82. <Fragment>
  83. <Queries />
  84. <MetricScratchpad />
  85. <WidgetDetails />
  86. </Fragment>
  87. ) : (
  88. <OnboardingPanel image={<EmptyStateImage src={emptyStateImg} />}>
  89. <h3>{t('Get started with custom metrics')}</h3>
  90. <p>
  91. {t(
  92. "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."
  93. )}
  94. </p>
  95. <Button
  96. priority="primary"
  97. onClick={() => addCustomMetric('onboarding_panel')}
  98. >
  99. {t('Add Custom Metric')}
  100. </Button>
  101. </OnboardingPanel>
  102. )}
  103. </Layout.Main>
  104. </Layout.Body>
  105. </Fragment>
  106. );
  107. });
  108. const PaddedContainer = styled('div')`
  109. margin-bottom: ${space(2)};
  110. display: flex;
  111. justify-content: space-between;
  112. flex-wrap: wrap;
  113. gap: ${space(1)};
  114. `;
  115. const EmptyStateImage = styled('img')`
  116. @media (min-width: ${p => p.theme.breakpoints.small}) {
  117. user-select: none;
  118. position: absolute;
  119. top: 0;
  120. bottom: 0;
  121. width: 220px;
  122. margin-top: auto;
  123. margin-bottom: auto;
  124. transform: translateX(-50%);
  125. left: 50%;
  126. }
  127. @media (min-width: ${p => p.theme.breakpoints.large}) {
  128. transform: translateX(-60%);
  129. width: 280px;
  130. }
  131. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  132. transform: translateX(-75%);
  133. width: 320px;
  134. }
  135. `;