index.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import AsyncComponent from 'sentry/components/asyncComponent';
  4. import Button from 'sentry/components/button';
  5. import EventDataSection from 'sentry/components/events/eventDataSection';
  6. import {FeatureFeedback} from 'sentry/components/featureFeedback';
  7. import LoadingIndicator from 'sentry/components/loadingIndicator';
  8. import {t} from 'sentry/locale';
  9. import space from 'sentry/styles/space';
  10. import {EventGroupInfo, Organization} from 'sentry/types';
  11. import {Event} from 'sentry/types/event';
  12. import withOrganization from 'sentry/utils/withOrganization';
  13. import {groupingFeedbackTypes} from 'sentry/views/organizationGroupDetails/grouping/grouping';
  14. import GroupingConfigSelect from './groupingConfigSelect';
  15. import GroupVariant from './groupingVariant';
  16. type Props = AsyncComponent['props'] & {
  17. event: Event;
  18. organization: Organization;
  19. projectId: string;
  20. showGroupingConfig: boolean;
  21. };
  22. type State = AsyncComponent['state'] & {
  23. configOverride: string | null;
  24. groupInfo: EventGroupInfo;
  25. isOpen: boolean;
  26. };
  27. class EventGroupingInfo extends AsyncComponent<Props, State> {
  28. getEndpoints(): ReturnType<AsyncComponent['getEndpoints']> {
  29. const {organization, event, projectId} = this.props;
  30. let path = `/projects/${organization.slug}/${projectId}/events/${event.id}/grouping-info/`;
  31. if (this.state?.configOverride) {
  32. path = `${path}?config=${this.state.configOverride}`;
  33. }
  34. return [['groupInfo', path]];
  35. }
  36. getDefaultState() {
  37. return {
  38. ...super.getDefaultState(),
  39. isOpen: false,
  40. configOverride: null,
  41. };
  42. }
  43. toggle = () => {
  44. this.setState(state => ({
  45. isOpen: !state.isOpen,
  46. configOverride: state.isOpen ? null : state.configOverride,
  47. }));
  48. };
  49. handleConfigSelect = selection => {
  50. this.setState({configOverride: selection.value}, () => this.reloadData());
  51. };
  52. renderGroupInfoSummary() {
  53. const {groupInfo} = this.state;
  54. if (!groupInfo) {
  55. return null;
  56. }
  57. const groupedBy = Object.values(groupInfo)
  58. .filter(variant => variant.hash !== null && variant.description !== null)
  59. .map(variant => variant.description)
  60. .sort((a, b) => a!.toLowerCase().localeCompare(b!.toLowerCase()))
  61. .join(', ');
  62. return (
  63. <SummaryGroupedBy data-test-id="loaded-grouping-info">{`(${t('grouped by')} ${
  64. groupedBy || t('nothing')
  65. })`}</SummaryGroupedBy>
  66. );
  67. }
  68. renderGroupConfigSelect() {
  69. const {configOverride} = this.state;
  70. const {event} = this.props;
  71. const configId = configOverride ?? event.groupingConfig.id;
  72. return (
  73. <GroupingConfigSelect
  74. eventConfigId={event.groupingConfig.id}
  75. configId={configId}
  76. onSelect={this.handleConfigSelect}
  77. />
  78. );
  79. }
  80. renderGroupInfo() {
  81. const {groupInfo, loading} = this.state;
  82. const {showGroupingConfig} = this.props;
  83. const variants = groupInfo
  84. ? Object.values(groupInfo).sort((a, b) =>
  85. a.hash && !b.hash
  86. ? -1
  87. : a.description
  88. ?.toLowerCase()
  89. .localeCompare(b.description?.toLowerCase() ?? '') ?? 1
  90. )
  91. : [];
  92. return (
  93. <Fragment>
  94. <ConfigHeader>
  95. <div>{showGroupingConfig && this.renderGroupConfigSelect()}</div>
  96. <FeatureFeedback
  97. featureName="grouping"
  98. feedbackTypes={groupingFeedbackTypes}
  99. buttonProps={{size: 'sm'}}
  100. />
  101. </ConfigHeader>
  102. {loading ? (
  103. <LoadingIndicator />
  104. ) : (
  105. variants.map((variant, index) => (
  106. <Fragment key={variant.key}>
  107. <GroupVariant variant={variant} showGroupingConfig={showGroupingConfig} />
  108. {index < variants.length - 1 && <VariantDivider />}
  109. </Fragment>
  110. ))
  111. )}
  112. </Fragment>
  113. );
  114. }
  115. renderLoading() {
  116. return this.renderBody();
  117. }
  118. renderBody() {
  119. const {isOpen} = this.state;
  120. const title = (
  121. <Fragment>
  122. {t('Event Grouping Information')}
  123. {!isOpen && this.renderGroupInfoSummary()}
  124. </Fragment>
  125. );
  126. const actions = (
  127. <ToggleButton onClick={this.toggle} priority="link">
  128. {isOpen ? t('Hide Details') : t('Show Details')}
  129. </ToggleButton>
  130. );
  131. return (
  132. <EventDataSection type="grouping-info" title={title} actions={actions}>
  133. {isOpen && this.renderGroupInfo()}
  134. </EventDataSection>
  135. );
  136. }
  137. }
  138. const SummaryGroupedBy = styled('small')`
  139. @media (max-width: ${p => p.theme.breakpoints.small}) {
  140. display: block;
  141. margin: 0 !important;
  142. }
  143. `;
  144. const ConfigHeader = styled('div')`
  145. display: flex;
  146. align-items: center;
  147. justify-content: space-between;
  148. gap: ${space(1)};
  149. margin-bottom: ${space(2)};
  150. `;
  151. const ToggleButton = styled(Button)`
  152. font-weight: 700;
  153. color: ${p => p.theme.subText};
  154. &:hover,
  155. &:focus {
  156. color: ${p => p.theme.textColor};
  157. }
  158. `;
  159. export const GroupingConfigItem = styled('span')<{
  160. isActive?: boolean;
  161. isHidden?: boolean;
  162. }>`
  163. font-family: ${p => p.theme.text.familyMono};
  164. opacity: ${p => (p.isHidden ? 0.5 : null)};
  165. font-weight: ${p => (p.isActive ? 'bold' : null)};
  166. font-size: ${p => p.theme.fontSizeSmall};
  167. `;
  168. const VariantDivider = styled('hr')`
  169. padding-top: ${space(1)};
  170. border-top: 1px solid ${p => p.theme.border};
  171. `;
  172. export default withOrganization(EventGroupingInfo);