Files
Tom MoorandClaude 8192bc0514 chore: Audit and move inline actions to definitions (#13133)
* chore: Audit and move inline actions to definitions

* fix: Reuse existing smart-quote translation key in emoji delete dialog

Co-Authored-By: Claude <noreply@anthropic.com>

* Remove two usages of 'Link copied' translation

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-25 16:13:12 +00:00

85 lines
2.3 KiB
TypeScript

import { observer } from "mobx-react";
import { EditIcon } from "outline-icons";
import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import type Comment from "~/models/Comment";
import { DropdownMenu } from "~/components/Menu/DropdownMenu";
import { OverflowMenuButton } from "~/components/Menu/OverflowMenuButton";
import {
copyCommentLinkActionFactory,
deleteCommentActionFactory,
resolveCommentActionFactory,
unresolveCommentActionFactory,
viewCommentReactionsActionFactory,
} from "~/actions/definitions/comments";
import usePolicy from "~/hooks/usePolicy";
import { ActionSeparator, createAction } from "~/actions";
import { ActiveDocumentSection } from "~/actions/sections";
import { useMenuAction } from "~/hooks/useMenuAction";
type Props = {
/** The comment to associate with the menu */
comment: Comment;
/** CSS class name */
className?: string;
/** Callback when the "Edit" is selected in the menu */
onEdit: () => void;
/** Callback when the comment has been deleted */
onDelete: () => void;
/** Callback when the comment has been updated */
onUpdate: (attrs: { resolved: boolean }) => void;
};
function CommentMenu({
comment,
onEdit,
onDelete,
onUpdate,
className,
}: Props) {
const { t } = useTranslation();
const can = usePolicy(comment);
const actions = useMemo(
() => [
createAction({
name: `${t("Edit")}…`,
icon: <EditIcon />,
section: ActiveDocumentSection,
visible: can.update && !comment.isResolved,
perform: onEdit,
}),
resolveCommentActionFactory({
comment,
onResolve: () => onUpdate({ resolved: true }),
}),
unresolveCommentActionFactory({
comment,
onUnresolve: () => onUpdate({ resolved: false }),
}),
viewCommentReactionsActionFactory({
comment,
}),
copyCommentLinkActionFactory({ comment }),
ActionSeparator,
deleteCommentActionFactory({ comment, onDelete }),
],
[t, comment, can.update, onEdit, onUpdate, onDelete]
);
const rootAction = useMenuAction(actions);
return (
<DropdownMenu
action={rootAction}
align="end"
ariaLabel={t("Comment options")}
modal={false}
>
<OverflowMenuButton className={className} />
</DropdownMenu>
);
}
export default observer(CommentMenu);