previewTable.tsx 2.9 KB

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