querycard.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import {PureComponent} from 'react';
  2. import styled from '@emotion/styled';
  3. import ActivityAvatar from 'sentry/components/activity/item/avatar';
  4. import Card from 'sentry/components/card';
  5. import ErrorBoundary from 'sentry/components/errorBoundary';
  6. import Link from 'sentry/components/links/link';
  7. import {t} from 'sentry/locale';
  8. import space from 'sentry/styles/space';
  9. import {User} from 'sentry/types';
  10. import {callIfFunction} from 'sentry/utils/callIfFunction';
  11. type Props = {
  12. renderGraph: () => React.ReactNode;
  13. to: object;
  14. createdBy?: User | undefined;
  15. dateStatus?: React.ReactNode;
  16. onEventClick?: () => void;
  17. queryDetail?: string;
  18. renderContextMenu?: () => React.ReactNode;
  19. subtitle?: string;
  20. title?: string;
  21. };
  22. class QueryCard extends PureComponent<Props> {
  23. handleClick = () => {
  24. const {onEventClick} = this.props;
  25. callIfFunction(onEventClick);
  26. };
  27. render() {
  28. const {
  29. title,
  30. subtitle,
  31. queryDetail,
  32. renderContextMenu,
  33. renderGraph,
  34. createdBy,
  35. dateStatus,
  36. } = this.props;
  37. return (
  38. <Link data-test-id={`card-${title}`} onClick={this.handleClick} to={this.props.to}>
  39. <StyledQueryCard interactive>
  40. <QueryCardHeader>
  41. <QueryCardContent>
  42. <QueryTitle>{title}</QueryTitle>
  43. <QueryDetail>{queryDetail}</QueryDetail>
  44. </QueryCardContent>
  45. <AvatarWrapper>
  46. {createdBy ? (
  47. <ActivityAvatar type="user" user={createdBy} size={34} />
  48. ) : (
  49. <ActivityAvatar type="system" size={34} />
  50. )}
  51. </AvatarWrapper>
  52. </QueryCardHeader>
  53. <QueryCardBody>
  54. <StyledErrorBoundary mini>{renderGraph()}</StyledErrorBoundary>
  55. </QueryCardBody>
  56. <QueryCardFooter>
  57. <DateSelected>
  58. {subtitle}
  59. {dateStatus ? (
  60. <DateStatus>
  61. {t('Edited')} {dateStatus}
  62. </DateStatus>
  63. ) : null}
  64. </DateSelected>
  65. {renderContextMenu && renderContextMenu()}
  66. </QueryCardFooter>
  67. </StyledQueryCard>
  68. </Link>
  69. );
  70. }
  71. }
  72. const AvatarWrapper = styled('span')`
  73. border: 3px solid ${p => p.theme.border};
  74. border-radius: 50%;
  75. height: min-content;
  76. `;
  77. const QueryCardContent = styled('div')`
  78. flex-grow: 1;
  79. overflow: hidden;
  80. margin-right: ${space(1)};
  81. `;
  82. const StyledQueryCard = styled(Card)`
  83. justify-content: space-between;
  84. height: 100%;
  85. &:focus,
  86. &:hover {
  87. top: -1px;
  88. }
  89. `;
  90. const QueryCardHeader = styled('div')`
  91. display: flex;
  92. padding: ${space(1.5)} ${space(2)};
  93. `;
  94. const QueryTitle = styled('div')`
  95. ${p => p.theme.text.cardTitle};
  96. color: ${p => p.theme.headingColor};
  97. ${p => p.theme.overflowEllipsis};
  98. font-weight: initial;
  99. `;
  100. const QueryDetail = styled('div')`
  101. font-family: ${p => p.theme.text.familyMono};
  102. font-size: ${p => p.theme.fontSizeSmall};
  103. color: ${p => p.theme.gray300};
  104. line-height: 1.5;
  105. ${p => p.theme.overflowEllipsis};
  106. `;
  107. const QueryCardBody = styled('div')`
  108. background: ${p => p.theme.backgroundSecondary};
  109. max-height: 150px;
  110. height: 100%;
  111. overflow: hidden;
  112. `;
  113. const QueryCardFooter = styled('div')`
  114. display: flex;
  115. justify-content: space-between;
  116. align-items: center;
  117. padding: ${space(1)} ${space(2)};
  118. `;
  119. const DateSelected = styled('div')`
  120. font-size: ${p => p.theme.fontSizeSmall};
  121. display: grid;
  122. grid-column-gap: ${space(1)};
  123. ${p => p.theme.overflowEllipsis};
  124. color: ${p => p.theme.textColor};
  125. `;
  126. const DateStatus = styled('span')`
  127. color: ${p => p.theme.subText};
  128. padding-left: ${space(1)};
  129. `;
  130. const StyledErrorBoundary = styled(ErrorBoundary)`
  131. margin-bottom: 100px;
  132. `;
  133. export default QueryCard;