list.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. if (!hasResults) {
  56. return <Empty />;
  57. }
  58. return (
  59. <Fragment>
  60. {!hasSimilarityEmbeddingsFeature && (
  61. <Header>
  62. <SimilarSpectrum />
  63. </Header>
  64. )}
  65. {hasSimilarityEmbeddingsFeature && (
  66. <LegendSmall>0 = Not Similar, 1 = Similar</LegendSmall>
  67. )}
  68. <Panel>
  69. <Toolbar
  70. onMerge={onMerge}
  71. groupId={groupId}
  72. project={project}
  73. organization={organization}
  74. />
  75. <PanelBody>
  76. {itemsWithFiltered.map(item => (
  77. <Item
  78. key={item.issue.id}
  79. orgId={orgId}
  80. groupId={groupId}
  81. project={project}
  82. {...item}
  83. />
  84. ))}
  85. {hasHiddenItems && !showAllItems && !hasSimilarityEmbeddingsFeature && (
  86. <Footer>
  87. <Button onClick={() => setShowAllItems(true)}>
  88. {t('Show %s issues below threshold', filteredItems.length)}
  89. </Button>
  90. </Footer>
  91. )}
  92. </PanelBody>
  93. </Panel>
  94. <Pagination pageLinks={pageLinks} />
  95. </Fragment>
  96. );
  97. }
  98. export default List;
  99. const Header = styled('div')`
  100. display: flex;
  101. justify-content: flex-end;
  102. margin-bottom: ${space(1)};
  103. `;
  104. const LegendSmall = styled('div')`
  105. display: flex;
  106. justify-content: flex-end;
  107. margin-bottom: ${space(1)};
  108. font-size: ${p => p.theme.fontSizeSmall};
  109. `;
  110. const Footer = styled('div')`
  111. display: flex;
  112. justify-content: center;
  113. padding: ${space(1.5)};
  114. `;