groupListBody.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import {IndexedMembersByProject} from 'sentry/actionCreators/members';
  2. import LoadingError from 'sentry/components/loadingError';
  3. import LoadingIndicator from 'sentry/components/loadingIndicator';
  4. import PanelBody from 'sentry/components/panels/panelBody';
  5. import IssuesReplayCountProvider from 'sentry/components/replays/issuesReplayCountProvider';
  6. import StreamGroup from 'sentry/components/stream/group';
  7. import GroupStore from 'sentry/stores/groupStore';
  8. import {Group} from 'sentry/types';
  9. import theme from 'sentry/utils/theme';
  10. import useApi from 'sentry/utils/useApi';
  11. import useMedia from 'sentry/utils/useMedia';
  12. import useOrganization from 'sentry/utils/useOrganization';
  13. import {useSyncedLocalStorageState} from 'sentry/utils/useSyncedLocalStorageState';
  14. import NoGroupsHandler from './noGroupsHandler';
  15. import {IssueSortOptions, SAVED_SEARCHES_SIDEBAR_OPEN_LOCALSTORAGE_KEY} from './utils';
  16. type GroupListBodyProps = {
  17. displayReprocessingLayout: boolean;
  18. error: string | null;
  19. groupIds: string[];
  20. groupStatsPeriod: string;
  21. loading: boolean;
  22. memberList: IndexedMembersByProject;
  23. query: string;
  24. refetchGroups: () => void;
  25. selectedProjectIds: number[];
  26. sort: string;
  27. };
  28. type GroupListProps = {
  29. displayReprocessingLayout: boolean;
  30. groupIds: string[];
  31. groupStatsPeriod: string;
  32. memberList: IndexedMembersByProject;
  33. query: string;
  34. sort: string;
  35. };
  36. function GroupListBody({
  37. groupIds,
  38. memberList,
  39. query,
  40. sort,
  41. displayReprocessingLayout,
  42. groupStatsPeriod,
  43. loading,
  44. error,
  45. refetchGroups,
  46. selectedProjectIds,
  47. }: GroupListBodyProps) {
  48. const api = useApi();
  49. const organization = useOrganization();
  50. if (loading) {
  51. return <LoadingIndicator hideMessage />;
  52. }
  53. if (error) {
  54. return <LoadingError message={error} onRetry={refetchGroups} />;
  55. }
  56. if (!groupIds.length) {
  57. return (
  58. <NoGroupsHandler
  59. api={api}
  60. organization={organization}
  61. query={query}
  62. selectedProjectIds={selectedProjectIds}
  63. groupIds={groupIds}
  64. />
  65. );
  66. }
  67. return (
  68. <IssuesReplayCountProvider groupIds={groupIds}>
  69. <GroupList
  70. groupIds={groupIds}
  71. memberList={memberList}
  72. query={query}
  73. sort={sort}
  74. displayReprocessingLayout={displayReprocessingLayout}
  75. groupStatsPeriod={groupStatsPeriod}
  76. />
  77. </IssuesReplayCountProvider>
  78. );
  79. }
  80. function GroupList({
  81. groupIds,
  82. memberList,
  83. query,
  84. sort,
  85. displayReprocessingLayout,
  86. groupStatsPeriod,
  87. }: GroupListProps) {
  88. const [isSavedSearchesOpen] = useSyncedLocalStorageState(
  89. SAVED_SEARCHES_SIDEBAR_OPEN_LOCALSTORAGE_KEY,
  90. false
  91. );
  92. const topIssue = groupIds[0];
  93. const showInboxTime = sort === IssueSortOptions.INBOX;
  94. const canSelect = !useMedia(
  95. `(max-width: ${
  96. isSavedSearchesOpen ? theme.breakpoints.large : theme.breakpoints.small
  97. })`
  98. );
  99. return (
  100. <PanelBody>
  101. {groupIds.map((id, index) => {
  102. const hasGuideAnchor = id === topIssue;
  103. const group = GroupStore.get(id) as Group | undefined;
  104. return (
  105. <StreamGroup
  106. index={index}
  107. key={id}
  108. id={id}
  109. statsPeriod={groupStatsPeriod}
  110. query={query}
  111. hasGuideAnchor={hasGuideAnchor}
  112. memberList={group?.project ? memberList[group.project.slug] : undefined}
  113. displayReprocessingLayout={displayReprocessingLayout}
  114. useFilteredStats
  115. showInboxTime={showInboxTime}
  116. canSelect={canSelect}
  117. narrowGroups={isSavedSearchesOpen}
  118. />
  119. );
  120. })}
  121. </PanelBody>
  122. );
  123. }
  124. export default GroupListBody;