toolbar.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import {Component, Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import Button from 'sentry/components/button';
  4. import Confirm from 'sentry/components/confirm';
  5. import {PanelHeader} from 'sentry/components/panels';
  6. import ToolbarHeader from 'sentry/components/toolbarHeader';
  7. import {t} from 'sentry/locale';
  8. import GroupingStore from 'sentry/stores/groupingStore';
  9. import space from 'sentry/styles/space';
  10. import {callIfFunction} from 'sentry/utils/callIfFunction';
  11. type Props = {
  12. onMerge: () => void;
  13. v2: boolean;
  14. };
  15. const initialState = {
  16. mergeCount: 0,
  17. };
  18. type State = typeof initialState;
  19. class SimilarToolbar extends Component<Props, State> {
  20. state: State = initialState;
  21. componentWillUnmount() {
  22. callIfFunction(this.listener);
  23. }
  24. onGroupChange = ({mergeList}) => {
  25. if (!mergeList?.length) {
  26. return;
  27. }
  28. if (mergeList.length !== this.state.mergeCount) {
  29. this.setState({mergeCount: mergeList.length});
  30. }
  31. };
  32. listener = GroupingStore.listen(this.onGroupChange, undefined);
  33. render() {
  34. const {onMerge, v2} = this.props;
  35. const {mergeCount} = this.state;
  36. return (
  37. <PanelHeader hasButtons>
  38. <Confirm
  39. disabled={mergeCount === 0}
  40. message={t('Are you sure you want to merge these issues?')}
  41. onConfirm={onMerge}
  42. >
  43. <Button size="sm" title={t('Merging %s issues', mergeCount)}>
  44. {t('Merge %s', `(${mergeCount || 0})`)}
  45. </Button>
  46. </Confirm>
  47. <Columns>
  48. <StyledToolbarHeader>{t('Events')}</StyledToolbarHeader>
  49. {v2 ? (
  50. <StyledToolbarHeader>{t('Score')}</StyledToolbarHeader>
  51. ) : (
  52. <Fragment>
  53. <StyledToolbarHeader>{t('Exception')}</StyledToolbarHeader>
  54. <StyledToolbarHeader>{t('Message')}</StyledToolbarHeader>
  55. </Fragment>
  56. )}
  57. </Columns>
  58. </PanelHeader>
  59. );
  60. }
  61. }
  62. export default SimilarToolbar;
  63. const Columns = styled('div')`
  64. display: flex;
  65. align-items: center;
  66. flex-shrink: 0;
  67. min-width: 300px;
  68. width: 300px;
  69. `;
  70. const StyledToolbarHeader = styled(ToolbarHeader)`
  71. flex: 1;
  72. flex-shrink: 0;
  73. display: flex;
  74. justify-content: center;
  75. padding: ${space(0.5)} 0;
  76. `;