list.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import {Fragment, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {Location} from 'history';
  4. import {Button} from 'sentry/components/button';
  5. import EmptyStateWarning from 'sentry/components/emptyStateWarning';
  6. import Pagination from 'sentry/components/pagination';
  7. import Panel from 'sentry/components/panels/panel';
  8. import PanelBody from 'sentry/components/panels/panelBody';
  9. import SimilarSpectrum from 'sentry/components/similarSpectrum';
  10. import {t} from 'sentry/locale';
  11. import type {SimilarItem} from 'sentry/stores/groupingStore';
  12. import {space} from 'sentry/styles/space';
  13. import type {Organization} from 'sentry/types/organization';
  14. import type {Project} from 'sentry/types/project';
  15. import useOrganization from 'sentry/utils/useOrganization';
  16. import Item from './item';
  17. import Toolbar from './toolbar';
  18. type DefaultProps = {
  19. filteredItems: Array<SimilarItem>;
  20. };
  21. type Props = {
  22. groupId: string;
  23. hasSimilarityEmbeddingsFeature: boolean;
  24. items: Array<SimilarItem>;
  25. location: Location;
  26. onMerge: () => void;
  27. orgId: Organization['id'];
  28. pageLinks: string | null;
  29. project: Project;
  30. } & DefaultProps;
  31. function Empty() {
  32. return (
  33. <Panel>
  34. <PanelBody>
  35. <EmptyStateWarning small withIcon={false}>
  36. {t('No issues with a similar stack trace have been found.')}
  37. </EmptyStateWarning>
  38. </PanelBody>
  39. </Panel>
  40. );
  41. }
  42. function List({
  43. orgId,
  44. groupId,
  45. project,
  46. items,
  47. filteredItems = [],
  48. pageLinks,
  49. onMerge,
  50. location,
  51. hasSimilarityEmbeddingsFeature,
  52. }: Props) {
  53. const [showAllItems, setShowAllItems] = useState(false);
  54. const hasHiddenItems = !!filteredItems.length;
  55. const hasResults = items.length > 0 || hasHiddenItems;
  56. const itemsWithFiltered = items.concat(showAllItems ? filteredItems : []);
  57. const organization = useOrganization();
  58. const itemsWouldGroup = hasSimilarityEmbeddingsFeature
  59. ? itemsWithFiltered.map(item => ({
  60. id: item.issue.id,
  61. shouldBeGrouped: item.aggregate?.shouldBeGrouped,
  62. }))
  63. : undefined;
  64. if (!hasResults) {
  65. return <Empty />;
  66. }
  67. return (
  68. <Fragment>
  69. <Header>
  70. {!hasSimilarityEmbeddingsFeature && (
  71. <SimilarSpectrum
  72. highSpectrumLabel={t('Similar')}
  73. lowSpectrumLabel={t('Not Similar')}
  74. />
  75. )}
  76. {hasSimilarityEmbeddingsFeature && (
  77. <SimilarSpectrum
  78. highSpectrumLabel={t('Most Similar')}
  79. lowSpectrumLabel={t('Less Similar')}
  80. />
  81. )}
  82. </Header>
  83. <Panel>
  84. <Toolbar
  85. onMerge={onMerge}
  86. groupId={groupId}
  87. project={project}
  88. organization={organization}
  89. itemsWouldGroup={itemsWouldGroup}
  90. hasSimilarityEmbeddingsFeature={hasSimilarityEmbeddingsFeature}
  91. />
  92. <PanelBody>
  93. {itemsWithFiltered.map(item => (
  94. <Item
  95. key={item.issue.id}
  96. orgId={orgId}
  97. groupId={groupId}
  98. project={project}
  99. location={location}
  100. hasSimilarityEmbeddingsFeature={hasSimilarityEmbeddingsFeature}
  101. {...item}
  102. />
  103. ))}
  104. {hasHiddenItems && !showAllItems && !hasSimilarityEmbeddingsFeature && (
  105. <Footer>
  106. <Button onClick={() => setShowAllItems(true)}>
  107. {t('Show %s issues below threshold', filteredItems.length)}
  108. </Button>
  109. </Footer>
  110. )}
  111. </PanelBody>
  112. </Panel>
  113. <Pagination pageLinks={pageLinks} />
  114. </Fragment>
  115. );
  116. }
  117. export default List;
  118. const Header = styled('div')`
  119. display: flex;
  120. justify-content: flex-end;
  121. margin-bottom: ${space(1)};
  122. `;
  123. const Footer = styled('div')`
  124. display: flex;
  125. justify-content: center;
  126. padding: ${space(1.5)};
  127. `;