toolbar.tsx 4.2 KB

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