chartPanel.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import styled from '@emotion/styled';
  2. import {openInsightChartModal} from 'sentry/actionCreators/modal';
  3. import {Button} from 'sentry/components/button';
  4. import Panel from 'sentry/components/panels/panel';
  5. import {IconExpand} from 'sentry/icons';
  6. import {t} from 'sentry/locale';
  7. import {space} from 'sentry/styles/space';
  8. import {Subtitle} from 'sentry/views/performance/landing/widgets/widgets/singleFieldAreaWidget';
  9. export type AlertConfig = {
  10. aggregate: string;
  11. name?: string;
  12. query?: string;
  13. };
  14. type Props = {
  15. children: React.ReactNode;
  16. alertConfigs?: AlertConfig[];
  17. button?: JSX.Element;
  18. className?: string;
  19. subtitle?: React.ReactNode;
  20. title?: React.ReactNode;
  21. };
  22. export default function ChartPanel({
  23. title,
  24. children,
  25. button,
  26. subtitle,
  27. className,
  28. }: Props) {
  29. return (
  30. <PanelWithNoPadding className={className}>
  31. <PanelBody>
  32. {title && (
  33. <Header data-test-id="chart-panel-header">
  34. {title && (
  35. <ChartLabel>
  36. {typeof title === 'string' ? (
  37. <TextTitleContainer>{title}</TextTitleContainer>
  38. ) : (
  39. title
  40. )}
  41. </ChartLabel>
  42. )}
  43. <MenuContainer>
  44. {button}
  45. <Button
  46. aria-label={t('Expand Insight Chart')}
  47. borderless
  48. size="xs"
  49. icon={<IconExpand />}
  50. onClick={() => {
  51. openInsightChartModal({title, children});
  52. }}
  53. />
  54. </MenuContainer>
  55. </Header>
  56. )}
  57. {subtitle && (
  58. <SubtitleContainer>
  59. <Subtitle>{subtitle}</Subtitle>
  60. </SubtitleContainer>
  61. )}
  62. {children}
  63. </PanelBody>
  64. </PanelWithNoPadding>
  65. );
  66. }
  67. const PanelWithNoPadding = styled(Panel)`
  68. margin-bottom: 0;
  69. `;
  70. const TextTitleContainer = styled('div')`
  71. padding: 1px 0;
  72. `;
  73. const SubtitleContainer = styled('div')`
  74. padding-top: ${space(0.5)};
  75. `;
  76. const ChartLabel = styled('div')`
  77. ${p => p.theme.text.cardTitle}
  78. `;
  79. const PanelBody = styled('div')`
  80. padding: ${space(2)};
  81. `;
  82. const Header = styled('div')`
  83. width: 100%;
  84. display: flex;
  85. align-items: center;
  86. justify-content: space-between;
  87. `;
  88. const MenuContainer = styled('span')`
  89. display: flex;
  90. `;