previewTable.tsx 3.1 KB

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