layout.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import {Fragment, memo, useRef} from 'react';
  2. import styled from '@emotion/styled';
  3. import ButtonBar from 'sentry/components/buttonBar';
  4. import FeatureBadge from 'sentry/components/featureBadge';
  5. import FloatingFeedbackWidget from 'sentry/components/feedback/widget/floatingFeedbackWidget';
  6. import {GithubFeedbackButton} from 'sentry/components/githubFeedbackButton';
  7. import FullViewport from 'sentry/components/layouts/fullViewport';
  8. import * as Layout from 'sentry/components/layouts/thirds';
  9. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  10. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  11. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  12. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  13. import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  14. import SplitPanel, {BaseSplitDivider, DividerProps} from 'sentry/components/splitPanel';
  15. import {IconGrabbable} from 'sentry/icons';
  16. import {t} from 'sentry/locale';
  17. import {space} from 'sentry/styles/space';
  18. import {hasDDMExperimentalFeature} from 'sentry/utils/metrics/features';
  19. import {useDimensions} from 'sentry/utils/useDimensions';
  20. import useOrganization from 'sentry/utils/useOrganization';
  21. import {MetricScratchpad} from 'sentry/views/ddm/scratchpad';
  22. import {ScratchpadSelector} from 'sentry/views/ddm/scratchpadSelector';
  23. import {TraceTable} from 'sentry/views/ddm/traceTable';
  24. import {TrayContent} from 'sentry/views/ddm/trayContent';
  25. function MainContent({showTraceTable}: {showTraceTable?: boolean}) {
  26. return (
  27. <Fragment>
  28. <Layout.Header>
  29. <Layout.HeaderContent>
  30. <Layout.Title>
  31. {t('DDM')}
  32. <PageHeadingQuestionTooltip
  33. docsUrl="https://develop.sentry.dev/delightful-developer-metrics/"
  34. title={t('Delightful Developer Metrics.')}
  35. />
  36. <FeatureBadge type="alpha" />
  37. </Layout.Title>
  38. </Layout.HeaderContent>
  39. <Layout.HeaderActions>
  40. <ButtonBar gap={1}>
  41. <GithubFeedbackButton
  42. href="https://github.com/getsentry/sentry/discussions/58584"
  43. label={t('Discussion')}
  44. title={null}
  45. />
  46. </ButtonBar>
  47. </Layout.HeaderActions>
  48. </Layout.Header>
  49. <Layout.Body>
  50. <FloatingFeedbackWidget />
  51. <Layout.Main fullWidth>
  52. <PaddedContainer>
  53. <PageFilterBar condensed>
  54. <ProjectPageFilter />
  55. <EnvironmentPageFilter />
  56. <DatePageFilter />
  57. </PageFilterBar>
  58. <ScratchpadSelector />
  59. </PaddedContainer>
  60. <MetricScratchpad />
  61. </Layout.Main>
  62. {showTraceTable && <TraceTable />}
  63. </Layout.Body>
  64. </Fragment>
  65. );
  66. }
  67. export const DDMLayout = memo(() => {
  68. const organization = useOrganization();
  69. const hasNewLayout = hasDDMExperimentalFeature(organization);
  70. const measureRef = useRef<HTMLDivElement>(null);
  71. const {height} = useDimensions({elementRef: measureRef});
  72. const hasSize = height > 0;
  73. if (!hasNewLayout) {
  74. return (
  75. <Layout.Page>
  76. <MainContent showTraceTable />
  77. </Layout.Page>
  78. );
  79. }
  80. return (
  81. <FullViewport ref={measureRef}>
  82. {
  83. // FullViewport has a grid layout with `grid-template-rows: auto 1fr;`
  84. // therefore we need the empty div so that SplitPanel can span the whole height
  85. // TODO(arthur): Check on the styles of FullViewport
  86. }
  87. <div />
  88. {hasSize && (
  89. <SplitPanel
  90. availableSize={height}
  91. SplitDivider={SplitDivider}
  92. top={{
  93. content: (
  94. <ScrollingPage>
  95. <MainContent />
  96. </ScrollingPage>
  97. ),
  98. default: height * 0.7,
  99. min: 100,
  100. max: height - 58,
  101. }}
  102. bottom={<TrayContent />}
  103. />
  104. )}
  105. </FullViewport>
  106. );
  107. });
  108. const SplitDivider = styled((props: DividerProps) => (
  109. <BaseSplitDivider {...props} icon={<IconGrabbable size="xs" />} />
  110. ))<DividerProps>`
  111. border-top: 1px solid ${$p => $p.theme.border};
  112. `;
  113. const ScrollingPage = styled(Layout.Page)`
  114. height: 100%;
  115. overflow: auto;
  116. `;
  117. const PaddedContainer = styled('div')`
  118. margin-bottom: ${space(2)};
  119. display: grid;
  120. grid-template: 1fr / 1fr max-content;
  121. gap: ${space(1)};
  122. @media (max-width: ${props => props.theme.breakpoints.small}) {
  123. grid-template: 1fr 1fr / 1fr;
  124. }
  125. `;