list.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. pageLinks: string | null;
  24. project: Project;
  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. }: Props) {
  46. const [showAllItems, setShowAllItems] = useState(false);
  47. const hasHiddenItems = !!filteredItems.length;
  48. const hasResults = items.length > 0 || hasHiddenItems;
  49. const itemsWithFiltered = items.concat(showAllItems ? filteredItems : []);
  50. if (!hasResults) {
  51. return <Empty />;
  52. }
  53. return (
  54. <Fragment>
  55. <Header>
  56. <SimilarSpectrum />
  57. </Header>
  58. <Panel>
  59. <Toolbar onMerge={onMerge} />
  60. <PanelBody>
  61. {itemsWithFiltered.map(item => (
  62. <Item
  63. key={item.issue.id}
  64. orgId={orgId}
  65. groupId={groupId}
  66. project={project}
  67. {...item}
  68. />
  69. ))}
  70. {hasHiddenItems && !showAllItems && (
  71. <Footer>
  72. <Button onClick={() => setShowAllItems(true)}>
  73. {t('Show %s issues below threshold', filteredItems.length)}
  74. </Button>
  75. </Footer>
  76. )}
  77. </PanelBody>
  78. </Panel>
  79. <Pagination pageLinks={pageLinks} />
  80. </Fragment>
  81. );
  82. }
  83. export default List;
  84. const Header = styled('div')`
  85. display: flex;
  86. justify-content: flex-end;
  87. margin-bottom: ${space(1)};
  88. `;
  89. const Footer = styled('div')`
  90. display: flex;
  91. justify-content: center;
  92. padding: ${space(1.5)};
  93. `;