header.tsx 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. import {useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import Color from 'color';
  4. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  5. import {Button} from 'sentry/components/button';
  6. import Count from 'sentry/components/count';
  7. import EventOrGroupTitle from 'sentry/components/eventOrGroupTitle';
  8. import EventMessage from 'sentry/components/events/eventMessage';
  9. import ParticipantList from 'sentry/components/group/streamlinedParticipantList';
  10. import Link from 'sentry/components/links/link';
  11. import {IconChevron, IconPanel} from 'sentry/icons';
  12. import {t} from 'sentry/locale';
  13. import {space} from 'sentry/styles/space';
  14. import type {Event} from 'sentry/types/event';
  15. import type {Group, TeamParticipant, UserParticipant} from 'sentry/types/group';
  16. import type {Project} from 'sentry/types/project';
  17. import {useLocation} from 'sentry/utils/useLocation';
  18. import useOrganization from 'sentry/utils/useOrganization';
  19. import {useSyncedLocalStorageState} from 'sentry/utils/useSyncedLocalStorageState';
  20. import {useUser} from 'sentry/utils/useUser';
  21. import GroupActions from 'sentry/views/issueDetails/actions/index';
  22. import {Divider} from 'sentry/views/issueDetails/divider';
  23. import GroupPriority from 'sentry/views/issueDetails/groupPriority';
  24. import {GroupHeaderAssigneeSelector} from 'sentry/views/issueDetails/streamline/assigneeSelector';
  25. import {AttachmentsBadge} from 'sentry/views/issueDetails/streamline/attachmentsBadge';
  26. import {ReplayBadge} from 'sentry/views/issueDetails/streamline/replayBadge';
  27. import {UserFeedbackBadge} from 'sentry/views/issueDetails/streamline/userFeedbackBadge';
  28. import {useIssueDetailsHeader} from 'sentry/views/issueDetails/useIssueDetailsHeader';
  29. import type {ReprocessingStatus} from 'sentry/views/issueDetails/utils';
  30. interface GroupHeaderProps {
  31. baseUrl: string;
  32. event: Event | null;
  33. group: Group;
  34. groupReprocessingStatus: ReprocessingStatus;
  35. project: Project;
  36. }
  37. export default function StreamlinedGroupHeader({
  38. group,
  39. project,
  40. baseUrl,
  41. groupReprocessingStatus,
  42. event,
  43. }: GroupHeaderProps) {
  44. const activeUser = useUser();
  45. const location = useLocation();
  46. const organization = useOrganization();
  47. const {sort: _sort, ...query} = location.query;
  48. const {count: eventCount, userCount} = group;
  49. const [sidebarOpen, setSidebarOpen] = useSyncedLocalStorageState(
  50. 'issue-details-sidebar-open',
  51. true
  52. );
  53. const {message, eventRoute, disableActions, shortIdBreadcrumb} = useIssueDetailsHeader({
  54. group,
  55. groupReprocessingStatus,
  56. baseUrl,
  57. project,
  58. });
  59. const {userParticipants, teamParticipants, displayUsers} = useMemo(() => {
  60. return {
  61. userParticipants: group.participants.filter(
  62. (p): p is UserParticipant => p.type === 'user'
  63. ),
  64. teamParticipants: group.participants.filter(
  65. (p): p is TeamParticipant => p.type === 'team'
  66. ),
  67. displayUsers: group.seenBy.filter(user => activeUser.id !== user.id),
  68. };
  69. }, [group, activeUser.id]);
  70. return (
  71. <Header>
  72. <StyledBreadcrumbs
  73. crumbs={[
  74. {
  75. label: 'Issues',
  76. to: {
  77. pathname: `/organizations/${organization.slug}/issues/`,
  78. query: query,
  79. },
  80. },
  81. {label: shortIdBreadcrumb},
  82. ]}
  83. />
  84. <HeadingGrid>
  85. <Heading>
  86. <TitleHeading>
  87. <TitleWrapper>
  88. <StyledEventOrGroupTitle data={group} />
  89. </TitleWrapper>
  90. </TitleHeading>
  91. <MessageWrapper>
  92. <EventMessage
  93. data={group}
  94. message={message}
  95. type={group.type}
  96. level={group.level}
  97. showUnhandled={group.isUnhandled}
  98. levelIndicatorSize={'10px'}
  99. />
  100. <AttachmentsBadge group={group} />
  101. <UserFeedbackBadge group={group} project={project} />
  102. <ReplayBadge group={group} project={project} />
  103. </MessageWrapper>
  104. </Heading>
  105. <AllStats>
  106. <Stat>
  107. <Label data-test-id="all-event-count">{t('All Events')}</Label>
  108. <Link disabled={disableActions} to={eventRoute}>
  109. <StatCount value={eventCount} />
  110. </Link>
  111. </Stat>
  112. <Stat>
  113. <Label>{t('All Users')}</Label>
  114. <Link disabled={disableActions} to={`${baseUrl}tags/user/${location.search}`}>
  115. <StatCount value={userCount} />
  116. </Link>
  117. </Stat>
  118. </AllStats>
  119. </HeadingGrid>
  120. <StyledBreak />
  121. <InfoWrapper
  122. isResolvedOrIgnored={group.status === 'resolved' || group.status === 'ignored'}
  123. >
  124. <GroupActions
  125. group={group}
  126. project={project}
  127. disabled={disableActions}
  128. event={event}
  129. query={location.query}
  130. />
  131. <SidebarWorkflowWrapper>
  132. <WorkflowWrapper>
  133. <Wrapper>
  134. {t('Priority')}
  135. <GroupPriority group={group} />
  136. </Wrapper>
  137. <Wrapper>
  138. {t('Assignee')}
  139. <GroupHeaderAssigneeSelector
  140. group={group}
  141. project={project}
  142. event={event}
  143. />
  144. </Wrapper>
  145. {group.participants.length > 0 && (
  146. <Wrapper>
  147. {t('Participants')}
  148. <ParticipantList users={userParticipants} teams={teamParticipants} />
  149. </Wrapper>
  150. )}
  151. {displayUsers.length > 0 && (
  152. <Wrapper>
  153. {t('Viewers')}
  154. <ParticipantList users={displayUsers} />
  155. </Wrapper>
  156. )}
  157. </WorkflowWrapper>
  158. <CollapseSidebarWrapper>
  159. <Divider />
  160. <Button
  161. icon={
  162. sidebarOpen ? (
  163. <IconChevron direction="right" />
  164. ) : (
  165. <IconPanel direction="right" />
  166. )
  167. }
  168. title={sidebarOpen ? t('Close Sidebar') : t('Open Sidebar')}
  169. aria-label={sidebarOpen ? t('Close Sidebar') : t('Open Sidebar')}
  170. size="sm"
  171. borderless
  172. onClick={() => setSidebarOpen(!sidebarOpen)}
  173. />
  174. </CollapseSidebarWrapper>
  175. </SidebarWorkflowWrapper>
  176. </InfoWrapper>
  177. </Header>
  178. );
  179. }
  180. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  181. font-size: inherit;
  182. align-items: baseline;
  183. `;
  184. const HeadingGrid = styled('div')`
  185. display: grid;
  186. grid-template-columns: minmax(0, 1fr) auto;
  187. gap: ${space(2)};
  188. align-items: center;
  189. `;
  190. const Heading = styled('div')``;
  191. const AllStats = styled('div')`
  192. display: flex;
  193. gap: ${space(4)};
  194. padding-top: ${space(0.25)};
  195. `;
  196. const Stat = styled('div')`
  197. display: flex;
  198. flex-direction: column;
  199. gap: ${space(1)};
  200. font-size: ${p => p.theme.fontSizeSmall};
  201. `;
  202. const Label = styled('div')`
  203. font-size: ${p => p.theme.fontSizeSmall};
  204. font-weight: ${p => p.theme.fontWeightBold};
  205. color: ${p => p.theme.subText};
  206. `;
  207. const StatCount = styled(Count)`
  208. font-size: ${p => p.theme.fontSizeExtraLarge};
  209. display: block;
  210. line-height: 1;
  211. `;
  212. const TitleWrapper = styled('h3')`
  213. font-size: 20px;
  214. margin: 0;
  215. padding-bottom: 2px;
  216. text-overflow: ellipsis;
  217. white-space: nowrap;
  218. overflow: hidden;
  219. color: ${p => p.theme.headingColor};
  220. & em {
  221. font-weight: ${p => p.theme.fontWeightNormal};
  222. color: ${p => p.theme.textColor};
  223. font-size: ${p => p.theme.fontSizeLarge};
  224. }
  225. `;
  226. const TitleHeading = styled('div')`
  227. display: flex;
  228. line-height: 2;
  229. gap: ${space(1)};
  230. `;
  231. const StyledBreak = styled('hr')`
  232. margin-top: ${space(1.5)};
  233. margin-bottom: 0;
  234. margin-right: 0;
  235. border-color: ${p => p.theme.border};
  236. `;
  237. const MessageWrapper = styled('div')`
  238. display: flex;
  239. color: ${p => p.theme.gray300};
  240. gap: ${space(1)};
  241. `;
  242. const InfoWrapper = styled('div')<{isResolvedOrIgnored: boolean}>`
  243. display: flex;
  244. justify-content: space-between;
  245. gap: ${space(1)};
  246. background: ${p =>
  247. p.isResolvedOrIgnored
  248. ? `linear-gradient(to right, ${p.theme.background}, ${Color(p.theme.success).lighten(0.5).alpha(0.15).string()})`
  249. : p.theme.background};
  250. color: ${p => p.theme.gray300};
  251. padding: ${space(0.5)} 24px;
  252. margin-right: 0;
  253. margin-left: 0;
  254. flex-wrap: wrap;
  255. `;
  256. const SidebarWorkflowWrapper = styled('div')`
  257. display: flex;
  258. gap: ${space(0.5)};
  259. align-items: center;
  260. `;
  261. const WorkflowWrapper = styled('div')`
  262. display: flex;
  263. column-gap: ${space(2)};
  264. flex-wrap: wrap;
  265. `;
  266. const Wrapper = styled('div')`
  267. display: flex;
  268. align-items: center;
  269. gap: ${space(0.5)};
  270. `;
  271. const Header = styled('div')`
  272. background-color: ${p => p.theme.background};
  273. display: flex;
  274. flex-direction: column;
  275. border-bottom: 1px solid ${p => p.theme.border};
  276. > * {
  277. margin-right: 24px;
  278. margin-left: 24px;
  279. }
  280. `;
  281. const StyledBreadcrumbs = styled(Breadcrumbs)`
  282. margin-top: ${space(2)};
  283. `;
  284. const CollapseSidebarWrapper = styled('div')`
  285. display: flex;
  286. gap: ${space(0.5)};
  287. align-items: center;
  288. @media (max-width: ${p => p.theme.breakpoints.large}) {
  289. display: none;
  290. }
  291. `;