widgetHeader.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import styled from '@emotion/styled';
  2. import {HeaderTitleLegend} from 'sentry/components/charts/styles';
  3. import FeatureBadge from 'sentry/components/featureBadge';
  4. import QuestionTooltip from 'sentry/components/questionTooltip';
  5. import TextOverflow from 'sentry/components/textOverflow';
  6. import {space} from 'sentry/styles/space';
  7. import {MEPTag} from 'sentry/utils/performance/contexts/metricsEnhancedPerformanceDataContext';
  8. import {RELEASE_LEVEL} from 'sentry/views/performance/database/settings';
  9. import {
  10. GenericPerformanceWidgetProps,
  11. WidgetDataConstraint,
  12. WidgetDataProps,
  13. } from '../types';
  14. import {PerformanceWidgetSetting} from '../widgetDefinitions';
  15. export function WidgetHeader<T extends WidgetDataConstraint>(
  16. props: GenericPerformanceWidgetProps<T> & WidgetDataProps<T>
  17. ) {
  18. const {title, titleTooltip, Subtitle, HeaderActions, InteractiveTitle, chartSetting} =
  19. props;
  20. const isStarfishDBWidget =
  21. chartSetting === PerformanceWidgetSetting.MOST_TIME_SPENT_DB_QUERIES;
  22. return (
  23. <WidgetHeaderContainer>
  24. <TitleContainer>
  25. <StyledHeaderTitleLegend data-test-id="performance-widget-title">
  26. {InteractiveTitle ? (
  27. <InteractiveTitle {...props} />
  28. ) : (
  29. <TextOverflow>{title}</TextOverflow>
  30. )}
  31. {isStarfishDBWidget && <FeatureBadge type={RELEASE_LEVEL} />}
  32. <MEPTag />
  33. {titleTooltip && (
  34. <QuestionTooltip position="top" size="sm" title={titleTooltip} />
  35. )}
  36. </StyledHeaderTitleLegend>
  37. {Subtitle ? <Subtitle {...props} /> : null}
  38. </TitleContainer>
  39. <HeaderActionsContainer>
  40. {HeaderActions && <HeaderActions {...props} />}
  41. </HeaderActionsContainer>
  42. </WidgetHeaderContainer>
  43. );
  44. }
  45. const StyledHeaderTitleLegend = styled(HeaderTitleLegend)`
  46. position: relative;
  47. z-index: initial;
  48. top: -${space(0.5)};
  49. ${FeatureBadge} {
  50. position: relative;
  51. top: -${space(0.25)};
  52. }
  53. `;
  54. const TitleContainer = styled('div')`
  55. display: flex;
  56. flex-direction: column;
  57. align-items: flex-start;
  58. `;
  59. const WidgetHeaderContainer = styled('div')`
  60. display: flex;
  61. justify-content: space-between;
  62. align-items: flex-start;
  63. gap: ${space(1)};
  64. `;
  65. const HeaderActionsContainer = styled('div')`
  66. display: flex;
  67. align-items: center;
  68. gap: ${space(1)};
  69. `;