toolbar.tsx 2.2 KB

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