toolbar.tsx 4.5 KB

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