|
| 1 | +import * as React from 'react'; |
| 2 | +import { FormattedMessage } from 'react-intl'; |
| 3 | +import TetherComponent from 'react-tether'; |
| 4 | + |
| 5 | +import Checkmark16 from '../../../../../icon/line/Checkmark16'; |
| 6 | +import DeleteConfirmation from '../../common/delete-confirmation'; |
| 7 | +import Media from '../../../../../components/media'; |
| 8 | +import Pencil16 from '../../../../../icon/line/Pencil16'; |
| 9 | +import Trash16 from '../../../../../icon/line/Trash16'; |
| 10 | +import X16 from '../../../../../icon/fill/X16'; |
| 11 | +import { MenuItem } from '../../../../../components/menu'; |
| 12 | + |
| 13 | +import { ACTIVITY_TARGETS } from '../../../../common/interactionTargets'; |
| 14 | +import { COMMENT_STATUS_OPEN, COMMENT_STATUS_RESOLVED } from '../../../../../constants'; |
| 15 | + |
| 16 | +import messages from '../messages'; |
| 17 | + |
| 18 | +import type { FeedItemStatus } from '../../../../../common/types/feed'; |
| 19 | + |
| 20 | +import './BaseCommentMenu.scss'; |
| 21 | + |
| 22 | +export interface BaseCommentMenuProps { |
| 23 | + canDelete: boolean; |
| 24 | + canEdit: boolean; |
| 25 | + canResolve: boolean; |
| 26 | + handleDeleteCancel: () => void; |
| 27 | + handleDeleteClick: () => void; |
| 28 | + handleDeleteConfirm: () => void; |
| 29 | + handleEditClick: () => void; |
| 30 | + handleMenuClose: () => void; |
| 31 | + handleStatusUpdate: (selectedStatus: FeedItemStatus) => void; |
| 32 | + isConfirmingDelete: boolean; |
| 33 | + isResolved: boolean; |
| 34 | + onSelect: (isSelected: boolean) => void; |
| 35 | +} |
| 36 | + |
| 37 | +export const BaseCommentMenu = ({ |
| 38 | + canDelete, |
| 39 | + canEdit, |
| 40 | + canResolve, |
| 41 | + handleDeleteCancel, |
| 42 | + handleDeleteClick, |
| 43 | + handleDeleteConfirm, |
| 44 | + handleEditClick, |
| 45 | + handleMenuClose, |
| 46 | + handleStatusUpdate, |
| 47 | + isConfirmingDelete, |
| 48 | + isResolved, |
| 49 | + onSelect, |
| 50 | +}: BaseCommentMenuProps) => { |
| 51 | + return ( |
| 52 | + <TetherComponent |
| 53 | + // @ts-expect-error Awaiting proper types from @types/react-tether |
| 54 | + attachment="top right" |
| 55 | + className="bcs-Comment-deleteConfirmationModal" |
| 56 | + constraints={[{ to: 'scrollParent', attachment: 'together' }]} |
| 57 | + targetAttachment="bottom right" |
| 58 | + > |
| 59 | + <Media.Menu |
| 60 | + className="bcs-BaseCommentMenu" |
| 61 | + data-testid="comment-actions-menu" |
| 62 | + dropdownProps={{ |
| 63 | + onMenuClose: handleMenuClose, |
| 64 | + onMenuOpen: () => onSelect(true), |
| 65 | + }} |
| 66 | + isDisabled={isConfirmingDelete} |
| 67 | + menuProps={{ |
| 68 | + 'data-resin-component': ACTIVITY_TARGETS.COMMENT_OPTIONS, |
| 69 | + }} |
| 70 | + > |
| 71 | + {canResolve && isResolved && ( |
| 72 | + <MenuItem |
| 73 | + className="bcs-Comment-unresolveComment" |
| 74 | + data-resin-target={ACTIVITY_TARGETS.COMMENT_OPTIONS_EDIT} |
| 75 | + data-testid="unresolve-comment" |
| 76 | + onClick={() => handleStatusUpdate(COMMENT_STATUS_OPEN)} |
| 77 | + > |
| 78 | + <X16 /> |
| 79 | + <FormattedMessage {...messages.commentUnresolveMenuItem} /> |
| 80 | + </MenuItem> |
| 81 | + )} |
| 82 | + {canResolve && !isResolved && ( |
| 83 | + <MenuItem |
| 84 | + data-resin-target={ACTIVITY_TARGETS.COMMENT_OPTIONS_EDIT} |
| 85 | + data-testid="resolve-comment" |
| 86 | + onClick={() => handleStatusUpdate(COMMENT_STATUS_RESOLVED)} |
| 87 | + > |
| 88 | + <Checkmark16 /> |
| 89 | + <FormattedMessage {...messages.commentResolveMenuItem} /> |
| 90 | + </MenuItem> |
| 91 | + )} |
| 92 | + {canEdit && ( |
| 93 | + <MenuItem |
| 94 | + data-resin-target={ACTIVITY_TARGETS.COMMENT_OPTIONS_EDIT} |
| 95 | + data-testid="edit-comment" |
| 96 | + onClick={handleEditClick} |
| 97 | + > |
| 98 | + <Pencil16 /> |
| 99 | + <FormattedMessage {...messages.commentEditMenuItem} /> |
| 100 | + </MenuItem> |
| 101 | + )} |
| 102 | + {canDelete && ( |
| 103 | + <MenuItem |
| 104 | + aria-label={messages.commentDeleteMenuItem.defaultMessage} |
| 105 | + data-resin-target={ACTIVITY_TARGETS.COMMENT_OPTIONS_DELETE} |
| 106 | + data-testid="delete-comment" |
| 107 | + onClick={handleDeleteClick} |
| 108 | + > |
| 109 | + <Trash16 /> |
| 110 | + <FormattedMessage {...messages.commentDeleteMenuItem} /> |
| 111 | + </MenuItem> |
| 112 | + )} |
| 113 | + </Media.Menu> |
| 114 | + {isConfirmingDelete && ( |
| 115 | + <DeleteConfirmation |
| 116 | + data-resin-component={ACTIVITY_TARGETS.COMMENT_OPTIONS} |
| 117 | + isOpen={isConfirmingDelete} |
| 118 | + message={messages.commentDeletePrompt} |
| 119 | + onDeleteCancel={handleDeleteCancel} |
| 120 | + onDeleteConfirm={handleDeleteConfirm} |
| 121 | + /> |
| 122 | + )} |
| 123 | + </TetherComponent> |
| 124 | + ); |
| 125 | +}; |
0 commit comments