layout.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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('Delightful Developer Metrics.')}
  49. />
  50. <FeatureBadge type="alpha" />
  51. </Layout.Title>
  52. </Layout.HeaderContent>
  53. <Layout.HeaderActions>
  54. <PageHeaderActions
  55. showCustomMetricButton={hasMetrics}
  56. addCustomMetric={addCustomMetric}
  57. />
  58. </Layout.HeaderActions>
  59. </Layout.Header>
  60. <Layout.Body>
  61. <FloatingFeedbackWidget />
  62. <Layout.Main fullWidth>
  63. <PaddedContainer>
  64. <PageFilterBar condensed>
  65. <ProjectPageFilter />
  66. <EnvironmentPageFilter />
  67. <DatePageFilter />
  68. </PageFilterBar>
  69. </PaddedContainer>
  70. {isLoading ? (
  71. <LoadingIndicator />
  72. ) : hasMetrics ? (
  73. <Fragment>
  74. <Queries />
  75. <MetricScratchpad />
  76. <WidgetDetails />
  77. </Fragment>
  78. ) : (
  79. <OnboardingPanel image={<EmptyStateImage src={emptyStateImg} />}>
  80. <h3>{t('Get started with custom metrics')}</h3>
  81. <p>
  82. {t(
  83. "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."
  84. )}
  85. </p>
  86. <Button
  87. priority="primary"
  88. onClick={() => addCustomMetric('onboarding_panel')}
  89. >
  90. {t('Add Custom Metric')}
  91. </Button>
  92. </OnboardingPanel>
  93. )}
  94. </Layout.Main>
  95. </Layout.Body>
  96. </Fragment>
  97. );
  98. });
  99. const PaddedContainer = styled('div')`
  100. margin-bottom: ${space(2)};
  101. display: flex;
  102. justify-content: space-between;
  103. flex-wrap: wrap;
  104. gap: ${space(1)};
  105. `;
  106. const EmptyStateImage = styled('img')`
  107. @media (min-width: ${p => p.theme.breakpoints.small}) {
  108. user-select: none;
  109. position: absolute;
  110. top: 0;
  111. bottom: 0;
  112. width: 220px;
  113. margin-top: auto;
  114. margin-bottom: auto;
  115. transform: translateX(-50%);
  116. left: 50%;
  117. }
  118. @media (min-width: ${p => p.theme.breakpoints.large}) {
  119. transform: translateX(-60%);
  120. width: 280px;
  121. }
  122. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  123. transform: translateX(-75%);
  124. width: 320px;
  125. }
  126. `;