relatedIssues.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import {Component, Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Location} from 'history';
  4. import pick from 'lodash/pick';
  5. import {Button} from 'sentry/components/button';
  6. import {SectionHeading} from 'sentry/components/charts/styles';
  7. import EmptyStateWarning from 'sentry/components/emptyStateWarning';
  8. import GroupList from 'sentry/components/issues/groupList';
  9. import {Panel, PanelBody} from 'sentry/components/panels';
  10. import {DEFAULT_RELATIVE_PERIODS} from 'sentry/constants';
  11. import {URL_PARAM} from 'sentry/constants/pageFilters';
  12. import {t, tct} from 'sentry/locale';
  13. import {space} from 'sentry/styles/space';
  14. import {OrganizationSummary} from 'sentry/types';
  15. import {trackAnalytics} from 'sentry/utils/analytics';
  16. import {decodeScalar} from 'sentry/utils/queryString';
  17. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  18. import {removeTracingKeysFromSearch} from '../../utils';
  19. type Props = {
  20. location: Location;
  21. organization: OrganizationSummary;
  22. transaction: string;
  23. end?: string;
  24. start?: string;
  25. statsPeriod?: string | null;
  26. };
  27. class RelatedIssues extends Component<Props> {
  28. getIssuesEndpoint() {
  29. const {transaction, organization, start, end, statsPeriod, location} = this.props;
  30. const queryParams = {
  31. start,
  32. end,
  33. statsPeriod,
  34. limit: 5,
  35. sort: 'new',
  36. ...pick(location.query, [...Object.values(URL_PARAM), 'cursor']),
  37. };
  38. const currentFilter = new MutableSearch(decodeScalar(location.query.query, ''));
  39. removeTracingKeysFromSearch(currentFilter);
  40. currentFilter
  41. .addFreeText('is:unresolved')
  42. .setFilterValues('transaction', [transaction]);
  43. return {
  44. path: `/organizations/${organization.slug}/issues/`,
  45. queryParams: {
  46. ...queryParams,
  47. query: currentFilter.formatString(),
  48. },
  49. };
  50. }
  51. handleOpenClick = () => {
  52. const {organization} = this.props;
  53. trackAnalytics('performance_views.summary.open_issues', {
  54. organization: organization.id,
  55. });
  56. };
  57. renderEmptyMessage = () => {
  58. const {statsPeriod} = this.props;
  59. const selectedTimePeriod = statsPeriod && DEFAULT_RELATIVE_PERIODS[statsPeriod];
  60. const displayedPeriod = selectedTimePeriod
  61. ? selectedTimePeriod.toLowerCase()
  62. : t('given timeframe');
  63. return (
  64. <Panel>
  65. <PanelBody>
  66. <EmptyStateWarning>
  67. <p>
  68. {tct('No new issues for this transaction for the [timePeriod].', {
  69. timePeriod: displayedPeriod,
  70. })}
  71. </p>
  72. </EmptyStateWarning>
  73. </PanelBody>
  74. </Panel>
  75. );
  76. };
  77. render() {
  78. const {organization} = this.props;
  79. const {path, queryParams} = this.getIssuesEndpoint();
  80. const issueSearch = {
  81. pathname: `/organizations/${organization.slug}/issues/`,
  82. query: {referrer: 'performance-related-issues', ...queryParams},
  83. };
  84. return (
  85. <Fragment>
  86. <ControlsWrapper>
  87. <SectionHeading>{t('Related Issues')}</SectionHeading>
  88. <Button
  89. data-test-id="issues-open"
  90. size="xs"
  91. to={issueSearch}
  92. onClick={this.handleOpenClick}
  93. >
  94. {t('Open in Issues')}
  95. </Button>
  96. </ControlsWrapper>
  97. <TableWrapper>
  98. <GroupList
  99. orgId={organization.slug}
  100. endpointPath={path}
  101. queryParams={queryParams}
  102. query=""
  103. canSelectGroups={false}
  104. renderEmptyMessage={this.renderEmptyMessage}
  105. withChart={false}
  106. withPagination={false}
  107. source="performance-related-issues"
  108. />
  109. </TableWrapper>
  110. </Fragment>
  111. );
  112. }
  113. }
  114. const ControlsWrapper = styled('div')`
  115. display: flex;
  116. align-items: center;
  117. justify-content: space-between;
  118. margin-bottom: ${space(1)};
  119. `;
  120. const TableWrapper = styled('div')`
  121. margin-bottom: ${space(4)};
  122. ${Panel} {
  123. /* smaller space between table and pagination */
  124. margin-bottom: -${space(1)};
  125. }
  126. `;
  127. export default RelatedIssues;