header.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import {Theme} from '@emotion/react';
  2. import styled from '@emotion/styled';
  3. import ActivityAuthor from 'sentry/components/activity/author';
  4. import LinkWithConfirmation from 'sentry/components/links/linkWithConfirmation';
  5. import {Tooltip} from 'sentry/components/tooltip';
  6. import {t} from 'sentry/locale';
  7. import ConfigStore from 'sentry/stores/configStore';
  8. import {User} from 'sentry/types';
  9. import EditorTools from './editorTools';
  10. type Props = {
  11. authorName: string;
  12. onDelete: () => void;
  13. onEdit: () => void;
  14. user?: User;
  15. };
  16. const NoteHeader = ({authorName, user, onEdit, onDelete}: Props) => {
  17. const activeUser = ConfigStore.get('user');
  18. const canEdit = activeUser && (activeUser.isSuperuser || user?.id === activeUser.id);
  19. return (
  20. <div>
  21. <ActivityAuthor>{authorName}</ActivityAuthor>
  22. {canEdit && (
  23. <EditorTools>
  24. <Tooltip
  25. title={t('You can edit this comment due to your superuser status')}
  26. disabled={!activeUser.isSuperuser}
  27. >
  28. <Edit onClick={onEdit}>{t('Edit')}</Edit>
  29. </Tooltip>
  30. <Tooltip
  31. title={t('You can delete this comment due to your superuser status')}
  32. disabled={!activeUser.isSuperuser}
  33. >
  34. <LinkWithConfirmation
  35. title={t('Remove')}
  36. message={t('Are you sure you wish to delete this comment?')}
  37. onConfirm={onDelete}
  38. >
  39. <Remove>{t('Remove')}</Remove>
  40. </LinkWithConfirmation>
  41. </Tooltip>
  42. </EditorTools>
  43. )}
  44. </div>
  45. );
  46. };
  47. const getActionStyle = (p: {theme: Theme}) => `
  48. padding: 0 7px;
  49. color: ${p.theme.gray200};
  50. font-weight: normal;
  51. `;
  52. const Edit = styled('a')`
  53. ${getActionStyle};
  54. margin-left: 7px;
  55. &:hover {
  56. color: ${p => p.theme.gray300};
  57. }
  58. `;
  59. const Remove = styled('span')`
  60. ${getActionStyle};
  61. border-left: 1px solid ${p => p.theme.border};
  62. &:hover {
  63. color: ${p => p.theme.error};
  64. }
  65. `;
  66. export default NoteHeader;