previewTable.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import styled from '@emotion/styled';
  2. import {indexMembersByProject} from 'sentry/actionCreators/members';
  3. import EmptyStateWarning from 'sentry/components/emptyStateWarning';
  4. import GroupListHeader from 'sentry/components/issues/groupListHeader';
  5. import LoadingIndicator from 'sentry/components/loadingIndicator';
  6. import Pagination, {CursorHandler} from 'sentry/components/pagination';
  7. import Panel from 'sentry/components/panels/panel';
  8. import PanelBody from 'sentry/components/panels/panelBody';
  9. import IssuesReplayCountProvider from 'sentry/components/replays/issuesReplayCountProvider';
  10. import StreamGroup from 'sentry/components/stream/group';
  11. import {t, tct} from 'sentry/locale';
  12. import GroupStore from 'sentry/stores/groupStore';
  13. import {Group, Member} from 'sentry/types';
  14. type Props = {
  15. error: string | null;
  16. issueCount: number;
  17. loading: boolean;
  18. members: Member[] | undefined;
  19. onCursor: CursorHandler;
  20. page: number;
  21. pageLinks: string;
  22. previewGroups: string[] | null;
  23. };
  24. function PreviewTable({
  25. previewGroups,
  26. members,
  27. pageLinks,
  28. onCursor,
  29. issueCount,
  30. page,
  31. loading,
  32. error,
  33. }: Props) {
  34. const renderBody = () => {
  35. if (loading) {
  36. return <LoadingIndicator />;
  37. }
  38. if (error || !members) {
  39. return (
  40. <EmptyStateWarning>
  41. <p>{error ? error : t('No preview available')}</p>
  42. </EmptyStateWarning>
  43. );
  44. }
  45. if (issueCount === 0) {
  46. return (
  47. <EmptyStateWarning>
  48. <p>{t("We couldn't find any issues that would've triggered your rule")}</p>
  49. </EmptyStateWarning>
  50. );
  51. }
  52. const memberList = indexMembersByProject(members);
  53. return previewGroups?.map((id, index) => {
  54. const group = GroupStore.get(id) as Group | undefined;
  55. return (
  56. <StreamGroup
  57. index={index}
  58. key={id}
  59. id={id}
  60. hasGuideAnchor={false}
  61. memberList={group?.project ? memberList[group.project.slug] : undefined}
  62. displayReprocessingLayout={false}
  63. useFilteredStats
  64. withChart={false}
  65. canSelect={false}
  66. showLastTriggered
  67. />
  68. );
  69. });
  70. };
  71. const renderCaption = () => {
  72. if (loading || error || !previewGroups) {
  73. return null;
  74. }
  75. const pageIssues = page * 5 + previewGroups.length;
  76. return tct(`Showing [pageIssues] of [issueCount] issues`, {pageIssues, issueCount});
  77. };
  78. const renderPagination = () => {
  79. if (error) {
  80. return null;
  81. }
  82. return (
  83. <StyledPagination
  84. pageLinks={pageLinks}
  85. onCursor={onCursor}
  86. caption={renderCaption()}
  87. disabled={loading}
  88. />
  89. );
  90. };
  91. return (
  92. <IssuesReplayCountProvider groupIds={previewGroups || []}>
  93. <Panel>
  94. <GroupListHeader
  95. withChart={false}
  96. withColumns={['assignee', 'event', 'lastTriggered', 'users']}
  97. />
  98. <PanelBody>{renderBody()}</PanelBody>
  99. </Panel>
  100. {renderPagination()}
  101. </IssuesReplayCountProvider>
  102. );
  103. }
  104. const StyledPagination = styled(Pagination)`
  105. margin-top: 0;
  106. `;
  107. export default PreviewTable;