previewTable.tsx 3.0 KB

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