list.tsx 3.4 KB

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