relatedIssues.tsx 4.1 KB

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