relatedIssues.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import {Component, Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import Button from 'app/components/button';
  4. import {SectionHeading} from 'app/components/charts/styles';
  5. import EmptyStateWarning from 'app/components/emptyStateWarning';
  6. import GroupList from 'app/components/issues/groupList';
  7. import {Panel, PanelBody} from 'app/components/panels';
  8. import Tooltip from 'app/components/tooltip';
  9. import {IconInfo} from 'app/icons';
  10. import {t} from 'app/locale';
  11. import space from 'app/styles/space';
  12. import {OrganizationSummary, Project} from 'app/types';
  13. import {DATASET_EVENT_TYPE_FILTERS} from 'app/views/alerts/incidentRules/constants';
  14. import {IncidentRule} from 'app/views/alerts/incidentRules/types';
  15. import {TimePeriodType} from './constants';
  16. type Props = {
  17. organization: OrganizationSummary;
  18. rule: IncidentRule;
  19. projects: Project[];
  20. timePeriod: TimePeriodType;
  21. };
  22. class RelatedIssues extends Component<Props> {
  23. renderEmptyMessage = () => {
  24. return (
  25. <Panel>
  26. <PanelBody>
  27. <EmptyStateWarning small withIcon={false}>
  28. {t('No issues for this alert rule')}
  29. </EmptyStateWarning>
  30. </PanelBody>
  31. </Panel>
  32. );
  33. };
  34. render() {
  35. const {rule, projects, organization, timePeriod} = this.props;
  36. const {start, end} = timePeriod;
  37. const path = `/organizations/${organization.slug}/issues/`;
  38. const queryParams = {
  39. start,
  40. end,
  41. groupStatsPeriod: 'auto',
  42. limit: 5,
  43. ...(rule.environment ? {environment: rule.environment} : {}),
  44. sort: rule.aggregate === 'count_unique(user)' ? 'user' : 'freq',
  45. query: [
  46. rule.query,
  47. rule.eventTypes?.length
  48. ? `event.type:[${rule.eventTypes.join(`, `)}]`
  49. : DATASET_EVENT_TYPE_FILTERS[rule.dataset],
  50. ].join(' '),
  51. project: projects.map(project => project.id),
  52. };
  53. const issueSearch = {
  54. pathname: `/organizations/${organization.slug}/issues/`,
  55. query: queryParams,
  56. };
  57. return (
  58. <Fragment>
  59. <ControlsWrapper>
  60. <StyledSectionHeading>
  61. {t('Related Issues')}
  62. <Tooltip title={t('Top issues containing events matching the metric.')}>
  63. <IconInfo size="xs" color="gray200" />
  64. </Tooltip>
  65. </StyledSectionHeading>
  66. <Button data-test-id="issues-open" size="small" to={issueSearch}>
  67. {t('Open in Issues')}
  68. </Button>
  69. </ControlsWrapper>
  70. <TableWrapper>
  71. <GroupList
  72. orgId={organization.slug}
  73. endpointPath={path}
  74. queryParams={queryParams}
  75. query={`start=${start}&end=${end}&groupStatsPeriod=auto`}
  76. canSelectGroups={false}
  77. renderEmptyMessage={this.renderEmptyMessage}
  78. withChart
  79. withPagination={false}
  80. useFilteredStats
  81. customStatsPeriod={timePeriod}
  82. useTintRow={false}
  83. />
  84. </TableWrapper>
  85. </Fragment>
  86. );
  87. }
  88. }
  89. const StyledSectionHeading = styled(SectionHeading)`
  90. display: flex;
  91. align-items: center;
  92. `;
  93. const ControlsWrapper = styled('div')`
  94. display: flex;
  95. align-items: center;
  96. justify-content: space-between;
  97. margin-bottom: ${space(1)};
  98. `;
  99. const TableWrapper = styled('div')`
  100. margin-bottom: ${space(4)};
  101. ${Panel} {
  102. /* smaller space between table and pagination */
  103. margin-bottom: -${space(1)};
  104. }
  105. `;
  106. export default RelatedIssues;