relatedIssues.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 {trackAnalyticsEvent} 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. trackAnalyticsEvent({
  54. eventKey: 'performance_views.summary.open_issues',
  55. eventName: 'Performance Views: Open issues from transaction summary',
  56. organization_id: parseInt(organization.id, 10),
  57. });
  58. };
  59. renderEmptyMessage = () => {
  60. const {statsPeriod} = this.props;
  61. const selectedTimePeriod = statsPeriod && DEFAULT_RELATIVE_PERIODS[statsPeriod];
  62. const displayedPeriod = selectedTimePeriod
  63. ? selectedTimePeriod.toLowerCase()
  64. : t('given timeframe');
  65. return (
  66. <Panel>
  67. <PanelBody>
  68. <EmptyStateWarning>
  69. <p>
  70. {tct('No new issues for this transaction for the [timePeriod].', {
  71. timePeriod: displayedPeriod,
  72. })}
  73. </p>
  74. </EmptyStateWarning>
  75. </PanelBody>
  76. </Panel>
  77. );
  78. };
  79. render() {
  80. const {organization} = this.props;
  81. const {path, queryParams} = this.getIssuesEndpoint();
  82. const issueSearch = {
  83. pathname: `/organizations/${organization.slug}/issues/`,
  84. query: {referrer: 'performance-related-issues', ...queryParams},
  85. };
  86. return (
  87. <Fragment>
  88. <ControlsWrapper>
  89. <SectionHeading>{t('Related Issues')}</SectionHeading>
  90. <Button
  91. data-test-id="issues-open"
  92. size="xs"
  93. to={issueSearch}
  94. onClick={this.handleOpenClick}
  95. >
  96. {t('Open in Issues')}
  97. </Button>
  98. </ControlsWrapper>
  99. <TableWrapper>
  100. <GroupList
  101. orgId={organization.slug}
  102. endpointPath={path}
  103. queryParams={queryParams}
  104. query=""
  105. canSelectGroups={false}
  106. renderEmptyMessage={this.renderEmptyMessage}
  107. withChart={false}
  108. withPagination={false}
  109. source="performance-related-issues"
  110. />
  111. </TableWrapper>
  112. </Fragment>
  113. );
  114. }
  115. }
  116. const ControlsWrapper = styled('div')`
  117. display: flex;
  118. align-items: center;
  119. justify-content: space-between;
  120. margin-bottom: ${space(1)};
  121. `;
  122. const TableWrapper = styled('div')`
  123. margin-bottom: ${space(4)};
  124. ${Panel} {
  125. /* smaller space between table and pagination */
  126. margin-bottom: -${space(1)};
  127. }
  128. `;
  129. export default RelatedIssues;