noteDropdown.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. user?: User | null;
  10. };
  11. function NoteDropdown({user, onDelete, ...props}: Props & Partial<DropdownMenuProps>) {
  12. const activeUser = useUser();
  13. const canEdit = activeUser && (activeUser.isSuperuser || user?.id === activeUser.id);
  14. if (!canEdit) {
  15. return null;
  16. }
  17. return (
  18. <DropdownMenu
  19. offset={4}
  20. size="sm"
  21. triggerProps={{
  22. size: 'zero',
  23. showChevron: false,
  24. borderless: true,
  25. icon: <IconEllipsis />,
  26. 'aria-label': t('Comment Actions'),
  27. }}
  28. items={[
  29. {
  30. key: 'delete',
  31. label: t('Remove'),
  32. priority: 'danger',
  33. onAction: () =>
  34. openConfirmModal({
  35. message: (
  36. <strong>{t('Are you sure you want to remove this comment?')}</strong>
  37. ),
  38. confirmText: t('Remove comment'),
  39. onConfirm: onDelete,
  40. }),
  41. tooltip: activeUser.isSuperuser
  42. ? t('You can delete this comment due to your superuser status')
  43. : undefined,
  44. },
  45. ]}
  46. {...props}
  47. />
  48. );
  49. }
  50. export {NoteDropdown};