list.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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, PanelBody} from 'sentry/components/panels';
  7. import SimilarSpectrum from 'sentry/components/similarSpectrum';
  8. import {t} from 'sentry/locale';
  9. import type {SimilarItem} from 'sentry/stores/groupingStore';
  10. import {space} from 'sentry/styles/space';
  11. import type {Organization, Project} from 'sentry/types';
  12. import Item from './item';
  13. import Toolbar from './toolbar';
  14. type DefaultProps = {
  15. filteredItems: Array<SimilarItem>;
  16. };
  17. type Props = {
  18. groupId: string;
  19. items: Array<SimilarItem>;
  20. onMerge: () => void;
  21. orgId: Organization['id'];
  22. pageLinks: string | null;
  23. project: Project;
  24. v2: boolean;
  25. } & DefaultProps;
  26. function Empty() {
  27. return (
  28. <Panel>
  29. <PanelBody>
  30. <EmptyStateWarning small withIcon={false}>
  31. {t('No issues with a similar stack trace have been found.')}
  32. </EmptyStateWarning>
  33. </PanelBody>
  34. </Panel>
  35. );
  36. }
  37. function List({
  38. orgId,
  39. groupId,
  40. project,
  41. items,
  42. filteredItems = [],
  43. pageLinks,
  44. onMerge,
  45. v2,
  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. if (!hasResults) {
  52. return <Empty />;
  53. }
  54. return (
  55. <Fragment>
  56. <Header>
  57. <SimilarSpectrum />
  58. </Header>
  59. <Panel>
  60. <Toolbar v2={v2} onMerge={onMerge} />
  61. <PanelBody>
  62. {itemsWithFiltered.map(item => (
  63. <Item
  64. key={item.issue.id}
  65. orgId={orgId}
  66. v2={v2}
  67. groupId={groupId}
  68. project={project}
  69. {...item}
  70. />
  71. ))}
  72. {hasHiddenItems && !showAllItems && (
  73. <Footer>
  74. <Button onClick={() => setShowAllItems(true)}>
  75. {t('Show %s issues below threshold', filteredItems.length)}
  76. </Button>
  77. </Footer>
  78. )}
  79. </PanelBody>
  80. </Panel>
  81. <Pagination pageLinks={pageLinks} />
  82. </Fragment>
  83. );
  84. }
  85. export default List;
  86. const Header = styled('div')`
  87. display: flex;
  88. justify-content: flex-end;
  89. margin-bottom: ${space(1)};
  90. `;
  91. const Footer = styled('div')`
  92. display: flex;
  93. justify-content: center;
  94. padding: ${space(1.5)};
  95. `;