list.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 Item from './item';
  14. import Toolbar from './toolbar';
  15. type DefaultProps = {
  16. filteredItems: Array<SimilarItem>;
  17. };
  18. type Props = {
  19. groupId: string;
  20. items: Array<SimilarItem>;
  21. onMerge: () => void;
  22. orgId: Organization['id'];
  23. organization: Organization;
  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. organization,
  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 = organization?.features?.includes(
  53. 'issues-similarity-embeddings'
  54. );
  55. if (!hasResults) {
  56. return <Empty />;
  57. }
  58. return (
  59. <Fragment>
  60. {!hasSimilarityEmbeddingsFeature && (
  61. <Header>
  62. <SimilarSpectrum />
  63. </Header>
  64. )}
  65. <Panel>
  66. <Toolbar onMerge={onMerge} />
  67. <PanelBody>
  68. {itemsWithFiltered.map(item => (
  69. <Item
  70. key={item.issue.id}
  71. orgId={orgId}
  72. groupId={groupId}
  73. project={project}
  74. organization={organization}
  75. {...item}
  76. />
  77. ))}
  78. {hasHiddenItems && !showAllItems && !hasSimilarityEmbeddingsFeature && (
  79. <Footer>
  80. <Button onClick={() => setShowAllItems(true)}>
  81. {t('Show %s issues below threshold', filteredItems.length)}
  82. </Button>
  83. </Footer>
  84. )}
  85. </PanelBody>
  86. </Panel>
  87. <Pagination pageLinks={pageLinks} />
  88. </Fragment>
  89. );
  90. }
  91. export default List;
  92. const Header = styled('div')`
  93. display: flex;
  94. justify-content: flex-end;
  95. margin-bottom: ${space(1)};
  96. `;
  97. const Footer = styled('div')`
  98. display: flex;
  99. justify-content: center;
  100. padding: ${space(1.5)};
  101. `;