dashboardCard.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import * as React 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 Link from 'sentry/components/links/link';
  6. import {t} from 'sentry/locale';
  7. import overflowEllipsis from 'sentry/styles/overflowEllipsis';
  8. import space from 'sentry/styles/space';
  9. import {User} from 'sentry/types';
  10. type Props = {
  11. title: string;
  12. detail: React.ReactNode;
  13. to: React.ComponentProps<typeof Link>['to'];
  14. renderWidgets: () => React.ReactNode;
  15. createdBy?: User;
  16. dateStatus?: React.ReactNode;
  17. onEventClick?: () => void;
  18. renderContextMenu?: () => void;
  19. };
  20. function DashboardCard({
  21. title,
  22. detail,
  23. createdBy,
  24. renderWidgets,
  25. dateStatus,
  26. to,
  27. onEventClick,
  28. renderContextMenu,
  29. }: Props) {
  30. function onClick() {
  31. onEventClick?.();
  32. }
  33. return (
  34. <Link data-test-id={`card-${title}`} onClick={onClick} to={to}>
  35. <StyledDashboardCard interactive>
  36. <CardHeader>
  37. <CardContent>
  38. <Title>{title}</Title>
  39. <Detail>{detail}</Detail>
  40. </CardContent>
  41. <AvatarWrapper>
  42. {createdBy ? (
  43. <ActivityAvatar type="user" user={createdBy} size={34} />
  44. ) : (
  45. <ActivityAvatar type="system" size={34} />
  46. )}
  47. </AvatarWrapper>
  48. </CardHeader>
  49. <CardBody>{renderWidgets()}</CardBody>
  50. <CardFooter>
  51. <DateSelected>
  52. {dateStatus ? (
  53. <DateStatus>
  54. {t('Created')} {dateStatus}
  55. </DateStatus>
  56. ) : (
  57. <DateStatus />
  58. )}
  59. </DateSelected>
  60. {renderContextMenu && renderContextMenu()}
  61. </CardFooter>
  62. </StyledDashboardCard>
  63. </Link>
  64. );
  65. }
  66. const AvatarWrapper = styled('span')`
  67. border: 3px solid ${p => p.theme.border};
  68. border-radius: 50%;
  69. height: min-content;
  70. `;
  71. const CardContent = styled('div')`
  72. flex-grow: 1;
  73. overflow: hidden;
  74. margin-right: ${space(1)};
  75. `;
  76. const StyledDashboardCard = styled(Card)`
  77. justify-content: space-between;
  78. height: 100%;
  79. &:focus,
  80. &:hover {
  81. top: -1px;
  82. }
  83. `;
  84. const CardHeader = styled('div')`
  85. display: flex;
  86. padding: ${space(1.5)} ${space(2)};
  87. `;
  88. const Title = styled('div')`
  89. ${p => p.theme.text.cardTitle};
  90. color: ${p => p.theme.headingColor};
  91. ${overflowEllipsis};
  92. `;
  93. const Detail = styled('div')`
  94. font-family: ${p => p.theme.text.familyMono};
  95. font-size: ${p => p.theme.fontSizeSmall};
  96. color: ${p => p.theme.gray300};
  97. ${overflowEllipsis};
  98. line-height: 1.5;
  99. `;
  100. const CardBody = styled('div')`
  101. background: ${p => p.theme.gray100};
  102. padding: ${space(1.5)} ${space(2)};
  103. max-height: 150px;
  104. min-height: 150px;
  105. overflow: hidden;
  106. `;
  107. const CardFooter = styled('div')`
  108. display: flex;
  109. justify-content: space-between;
  110. align-items: center;
  111. padding: ${space(1)} ${space(2)};
  112. `;
  113. const DateSelected = styled('div')`
  114. font-size: ${p => p.theme.fontSizeSmall};
  115. display: grid;
  116. grid-column-gap: ${space(1)};
  117. color: ${p => p.theme.textColor};
  118. ${overflowEllipsis};
  119. `;
  120. const DateStatus = styled('span')`
  121. color: ${p => p.theme.purple300};
  122. padding-left: ${space(1)};
  123. `;
  124. export default DashboardCard;