list.tsx 3.5 KB

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