relatedIssues.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 {LinkButton} 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 {Organization} from 'sentry/types/organization';
  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: Organization;
  23. transaction: string;
  24. end?: string;
  25. start?: string;
  26. statsPeriod?: string | null;
  27. };
  28. class RelatedIssues extends Component<Props> {
  29. getIssuesEndpointQueryParams() {
  30. const {transaction, start, end, statsPeriod, location} = this.props;
  31. const queryParams = {
  32. start,
  33. end,
  34. statsPeriod,
  35. limit: 5,
  36. sort: 'trends',
  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. 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 {queryParams} = this.getIssuesEndpointQueryParams();
  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. <LinkButton
  89. data-test-id="issues-open"
  90. size="xs"
  91. to={issueSearch}
  92. onClick={this.handleOpenClick}
  93. >
  94. {t('Open in Issues')}
  95. </LinkButton>
  96. </ControlsWrapper>
  97. <TableWrapper>
  98. <GroupList
  99. orgSlug={organization.slug}
  100. queryParams={queryParams}
  101. canSelectGroups={false}
  102. renderEmptyMessage={this.renderEmptyMessage}
  103. withChart={false}
  104. withPagination={false}
  105. source="performance-related-issues"
  106. />
  107. </TableWrapper>
  108. </Fragment>
  109. );
  110. }
  111. }
  112. const ControlsWrapper = styled('div')`
  113. display: flex;
  114. align-items: center;
  115. justify-content: space-between;
  116. margin-bottom: ${space(1)};
  117. `;
  118. const TableWrapper = styled('div')`
  119. margin-bottom: ${space(4)};
  120. ${Panel} {
  121. /* smaller space between table and pagination */
  122. margin-bottom: -${space(1)};
  123. }
  124. `;
  125. export default RelatedIssues;