groupListBody.tsx 3.4 KB

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