toolbar.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. this.setState({mergeCount: 0});
  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} = 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="xs" title={t('Merging %s issues', mergeCount)}>
  43. {t('Merge %s', `(${mergeCount || 0})`)}
  44. </Button>
  45. </Confirm>
  46. <Columns>
  47. <StyledToolbarHeader>{t('Events')}</StyledToolbarHeader>
  48. <StyledToolbarHeader>{t('Exception')}</StyledToolbarHeader>
  49. <StyledToolbarHeader>{t('Message')}</StyledToolbarHeader>
  50. </Columns>
  51. </PanelHeader>
  52. );
  53. }
  54. }
  55. export default SimilarToolbar;
  56. const Columns = styled('div')`
  57. display: flex;
  58. align-items: center;
  59. flex-shrink: 0;
  60. min-width: 300px;
  61. width: 300px;
  62. `;
  63. const StyledToolbarHeader = styled(ToolbarHeader)`
  64. flex: 1;
  65. flex-shrink: 0;
  66. display: flex;
  67. justify-content: center;
  68. padding: ${space(0.5)} 0;
  69. `;