list.tsx 3.7 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. 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. <Header>
  71. {!hasSimilarityEmbeddingsFeature && (
  72. <SimilarSpectrum
  73. highSpectrumLabel={t('Similar')}
  74. lowSpectrumLabel={t('Not Similar')}
  75. />
  76. )}
  77. {hasSimilarityEmbeddingsFeature && (
  78. <SimilarSpectrum
  79. highSpectrumLabel={t('Most Similar')}
  80. lowSpectrumLabel={t('Less Similar')}
  81. />
  82. )}
  83. </Header>
  84. <Panel>
  85. <Toolbar
  86. onMerge={onMerge}
  87. groupId={groupId}
  88. project={project}
  89. organization={organization}
  90. itemsWouldGroup={itemsWouldGroup}
  91. location={location}
  92. />
  93. <PanelBody>
  94. {itemsWithFiltered.map(item => (
  95. <Item
  96. key={item.issue.id}
  97. orgId={orgId}
  98. groupId={groupId}
  99. project={project}
  100. location={location}
  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. `;