toolbar.tsx 2.0 KB

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