layout.tsx 4.6 KB

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