noteDropdown.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {openConfirmModal} from 'sentry/components/confirm';
  2. import {DropdownMenu, type DropdownMenuProps} from 'sentry/components/dropdownMenu';
  3. import {IconEllipsis} from 'sentry/icons';
  4. import {t} from 'sentry/locale';
  5. import type {User} from 'sentry/types/user';
  6. import {useUser} from 'sentry/utils/useUser';
  7. type Props = {
  8. onDelete: () => void;
  9. onEdit: () => void;
  10. user?: User | null;
  11. };
  12. function NoteDropdown({
  13. user,
  14. onDelete,
  15. onEdit,
  16. ...props
  17. }: Props & Partial<DropdownMenuProps>) {
  18. const activeUser = useUser();
  19. const canEdit = activeUser && (activeUser.isSuperuser || user?.id === activeUser.id);
  20. if (!canEdit) {
  21. return null;
  22. }
  23. return (
  24. <DropdownMenu
  25. offset={4}
  26. size="sm"
  27. triggerProps={{
  28. size: 'zero',
  29. showChevron: false,
  30. borderless: true,
  31. icon: <IconEllipsis />,
  32. 'aria-label': t('Comment Actions'),
  33. }}
  34. items={[
  35. {
  36. key: 'edit',
  37. label: t('Edit'),
  38. onAction: onEdit,
  39. tooltip: activeUser.isSuperuser
  40. ? t('You can edit this comment due to your superuser status')
  41. : undefined,
  42. },
  43. {
  44. key: 'delete',
  45. label: t('Remove'),
  46. priority: 'danger',
  47. onAction: () =>
  48. openConfirmModal({
  49. message: (
  50. <strong>{t('Are you sure you want to remove this comment?')}</strong>
  51. ),
  52. confirmText: t('Remove comment'),
  53. onConfirm: onDelete,
  54. }),
  55. tooltip: activeUser.isSuperuser
  56. ? t('You can delete this comment due to your superuser status')
  57. : undefined,
  58. },
  59. ]}
  60. {...props}
  61. />
  62. );
  63. }
  64. export {NoteDropdown};