list.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. items: Array<SimilarItem>;
  24. location: Location;
  25. onMerge: () => void;
  26. orgId: Organization['id'];
  27. pageLinks: string | null;
  28. project: Project;
  29. } & DefaultProps;
  30. function Empty() {
  31. return (
  32. <Panel>
  33. <PanelBody>
  34. <EmptyStateWarning small withIcon={false}>
  35. {t('No issues with a similar stack trace have been found.')}
  36. </EmptyStateWarning>
  37. </PanelBody>
  38. </Panel>
  39. );
  40. }
  41. function List({
  42. orgId,
  43. groupId,
  44. project,
  45. items,
  46. filteredItems = [],
  47. pageLinks,
  48. onMerge,
  49. location,
  50. }: Props) {
  51. const [showAllItems, setShowAllItems] = useState(false);
  52. const hasHiddenItems = !!filteredItems.length;
  53. const hasResults = items.length > 0 || hasHiddenItems;
  54. const itemsWithFiltered = items.concat(showAllItems ? filteredItems : []);
  55. const hasSimilarityEmbeddingsFeature =
  56. project.features.includes('similarity-embeddings') ||
  57. location.query.similarityEmbeddings === '1';
  58. const organization = useOrganization();
  59. const itemsWouldGroup = hasSimilarityEmbeddingsFeature
  60. ? itemsWithFiltered.map(item => ({
  61. id: item.issue.id,
  62. shouldBeGrouped: item.aggregate?.shouldBeGrouped,
  63. }))
  64. : undefined;
  65. if (!hasResults) {
  66. return <Empty />;
  67. }
  68. return (
  69. <Fragment>
  70. {!hasSimilarityEmbeddingsFeature && (
  71. <Header>
  72. <SimilarSpectrum />
  73. </Header>
  74. )}
  75. {hasSimilarityEmbeddingsFeature && (
  76. <LegendSmall>-1 = Not Similar, 1 = Similar</LegendSmall>
  77. )}
  78. <Panel>
  79. <Toolbar
  80. onMerge={onMerge}
  81. groupId={groupId}
  82. project={project}
  83. organization={organization}
  84. itemsWouldGroup={itemsWouldGroup}
  85. location={location}
  86. />
  87. <PanelBody>
  88. {itemsWithFiltered.map(item => (
  89. <Item
  90. key={item.issue.id}
  91. orgId={orgId}
  92. groupId={groupId}
  93. project={project}
  94. location={location}
  95. {...item}
  96. />
  97. ))}
  98. {hasHiddenItems && !showAllItems && !hasSimilarityEmbeddingsFeature && (
  99. <Footer>
  100. <Button onClick={() => setShowAllItems(true)}>
  101. {t('Show %s issues below threshold', filteredItems.length)}
  102. </Button>
  103. </Footer>
  104. )}
  105. </PanelBody>
  106. </Panel>
  107. <Pagination pageLinks={pageLinks} />
  108. </Fragment>
  109. );
  110. }
  111. export default List;
  112. const Header = styled('div')`
  113. display: flex;
  114. justify-content: flex-end;
  115. margin-bottom: ${space(1)};
  116. `;
  117. const LegendSmall = styled('div')`
  118. display: flex;
  119. justify-content: flex-end;
  120. margin-bottom: ${space(1)};
  121. font-size: ${p => p.theme.fontSizeSmall};
  122. `;
  123. const Footer = styled('div')`
  124. display: flex;
  125. justify-content: center;
  126. padding: ${space(1.5)};
  127. `;