list.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import {Component, Fragment} 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. type State = {
  27. showAllItems: boolean;
  28. };
  29. class List extends Component<Props, State> {
  30. static defaultProps: DefaultProps = {
  31. filteredItems: [],
  32. };
  33. state: State = {
  34. showAllItems: false,
  35. };
  36. renderEmpty = () => (
  37. <Panel>
  38. <PanelBody>
  39. <EmptyStateWarning small withIcon={false}>
  40. {t('No issues with a similar stack trace have been found.')}
  41. </EmptyStateWarning>
  42. </PanelBody>
  43. </Panel>
  44. );
  45. handleShowAll = () => {
  46. this.setState({showAllItems: true});
  47. };
  48. render() {
  49. const {orgId, groupId, project, items, filteredItems, pageLinks, onMerge, v2} =
  50. this.props;
  51. const {showAllItems} = this.state;
  52. const hasHiddenItems = !!filteredItems.length;
  53. const hasResults = items.length > 0 || hasHiddenItems;
  54. const itemsWithFiltered = items.concat((showAllItems && filteredItems) || []);
  55. if (!hasResults) {
  56. return this.renderEmpty();
  57. }
  58. return (
  59. <Fragment>
  60. <Header>
  61. <SimilarSpectrum />
  62. </Header>
  63. <Panel>
  64. <Toolbar v2={v2} onMerge={onMerge} />
  65. <PanelBody>
  66. {itemsWithFiltered.map(item => (
  67. <Item
  68. key={item.issue.id}
  69. orgId={orgId}
  70. v2={v2}
  71. groupId={groupId}
  72. project={project}
  73. {...item}
  74. />
  75. ))}
  76. {hasHiddenItems && !showAllItems && (
  77. <Footer>
  78. <Button onClick={this.handleShowAll}>
  79. {t('Show %s issues below threshold', filteredItems.length)}
  80. </Button>
  81. </Footer>
  82. )}
  83. </PanelBody>
  84. </Panel>
  85. <Pagination pageLinks={pageLinks} />
  86. </Fragment>
  87. );
  88. }
  89. }
  90. export default List;
  91. const Header = styled('div')`
  92. display: flex;
  93. justify-content: flex-end;
  94. margin-bottom: ${space(1)};
  95. `;
  96. const Footer = styled('div')`
  97. display: flex;
  98. justify-content: center;
  99. padding: ${space(1.5)};
  100. `;