toolbar.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import {Component, Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {Location} from 'history';
  4. import {addSuccessMessage} from 'sentry/actionCreators/indicator';
  5. import {Button} from 'sentry/components/button';
  6. import Confirm from 'sentry/components/confirm';
  7. import PanelHeader from 'sentry/components/panels/panelHeader';
  8. import ToolbarHeader from 'sentry/components/toolbarHeader';
  9. import {t} from 'sentry/locale';
  10. import GroupingStore from 'sentry/stores/groupingStore';
  11. import {space} from 'sentry/styles/space';
  12. import type {Organization} from 'sentry/types/organization';
  13. import type {Project} from 'sentry/types/project';
  14. import {trackAnalytics} from 'sentry/utils/analytics';
  15. type Props = {
  16. location: Location;
  17. onMerge: () => void;
  18. groupId?: string;
  19. itemsWouldGroup?: Array<{id: string; shouldBeGrouped: string | undefined}> | undefined;
  20. organization?: Organization;
  21. project?: Project;
  22. };
  23. const initialState = {
  24. mergeCount: 0,
  25. mergeList: [] as string[],
  26. };
  27. type State = typeof initialState;
  28. class SimilarToolbar extends Component<Props, State> {
  29. state: State = initialState;
  30. componentWillUnmount() {
  31. this.listener?.();
  32. }
  33. onGroupChange = ({mergeList}) => {
  34. if (!mergeList?.length) {
  35. this.setState({mergeCount: 0});
  36. return;
  37. }
  38. if (mergeList.length !== this.state.mergeCount) {
  39. this.setState({mergeCount: mergeList.length, mergeList});
  40. }
  41. };
  42. listener = GroupingStore.listen(this.onGroupChange, undefined);
  43. handleSimilarityEmbeddings = (value: string) => {
  44. if (
  45. this.state.mergeList.length === 0 ||
  46. !this.props.organization ||
  47. !this.props.groupId
  48. ) {
  49. return;
  50. }
  51. for (const parentGroupId of this.state.mergeList) {
  52. const itemWouldGroup = this.props.itemsWouldGroup?.find(
  53. item => item.id === parentGroupId
  54. );
  55. trackAnalytics(
  56. 'issue_details.similar_issues.similarity_embeddings_feedback_recieved',
  57. {
  58. organization: this.props.organization,
  59. projectId: this.props.project?.id,
  60. parentGroupId,
  61. groupId: this.props.groupId,
  62. value,
  63. wouldGroup: itemWouldGroup?.shouldBeGrouped,
  64. }
  65. );
  66. }
  67. addSuccessMessage('Sent analytic for similarity embeddings grouping');
  68. };
  69. render() {
  70. const {onMerge, project, location} = this.props;
  71. const {mergeCount} = this.state;
  72. const hasSimilarityEmbeddingsFeature =
  73. project?.features.includes('similarity-embeddings') ||
  74. location.query.similarityEmbeddings === '1';
  75. return (
  76. <PanelHeader hasButtons>
  77. <ButtonPanel>
  78. <Confirm
  79. disabled={mergeCount === 0}
  80. message={t('Are you sure you want to merge these issues?')}
  81. onConfirm={onMerge}
  82. >
  83. <Button size="xs" title={t('Merging %s issues', mergeCount)}>
  84. {t('Merge %s', `(${mergeCount || 0})`)}
  85. </Button>
  86. </Confirm>
  87. {hasSimilarityEmbeddingsFeature && (
  88. <Fragment>
  89. <Button
  90. disabled={mergeCount === 0}
  91. size="xs"
  92. title={t('Agree with the grouping of %s issues', mergeCount)}
  93. onClick={() => {
  94. this.handleSimilarityEmbeddings('Yes');
  95. }}
  96. >
  97. {t('Agree %s', `(${mergeCount || 0})`)}
  98. </Button>
  99. <Button
  100. disabled={mergeCount === 0}
  101. size="xs"
  102. title={t('Disagree with the grouping of %s issues', mergeCount)}
  103. onClick={() => {
  104. this.handleSimilarityEmbeddings('No');
  105. }}
  106. >
  107. {t('Disagree %s', `(${mergeCount || 0})`)}
  108. </Button>
  109. </Fragment>
  110. )}
  111. </ButtonPanel>
  112. <Columns>
  113. <StyledToolbarHeader>{t('Events')}</StyledToolbarHeader>
  114. <StyledToolbarHeader>{t('Exception')}</StyledToolbarHeader>
  115. <StyledToolbarHeader>{t('Message')}</StyledToolbarHeader>
  116. {hasSimilarityEmbeddingsFeature && (
  117. <StyledToolbarHeader>{t('Would Group')}</StyledToolbarHeader>
  118. )}
  119. </Columns>
  120. </PanelHeader>
  121. );
  122. }
  123. }
  124. export default SimilarToolbar;
  125. const Columns = styled('div')`
  126. display: flex;
  127. align-items: center;
  128. flex-shrink: 0;
  129. min-width: 350px;
  130. width: 350px;
  131. `;
  132. const StyledToolbarHeader = styled(ToolbarHeader)`
  133. flex: 1;
  134. flex-shrink: 0;
  135. display: flex;
  136. justify-content: center;
  137. padding: ${space(0.5)} 0;
  138. `;
  139. const ButtonPanel = styled('div')`
  140. display: flex;
  141. align-items: left;
  142. gap: ${space(1)};
  143. `;