mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Added data-member-uuid attribute to each comment
closes https://linear.app/ghost/issue/PLG-268 - allows for external scripts to more easily decorate individual comments
This commit is contained in:
parent
27e79a3a3d
commit
ab2058ee1d
2 changed files with 26 additions and 3 deletions
|
@ -38,6 +38,28 @@ describe('<CommentComponent>', function () {
|
||||||
|
|
||||||
expect(screen.getByText('First reply')).toBeInTheDocument();
|
expect(screen.getByText('First reply')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('outputs member uuid data attribute for published comments', function () {
|
||||||
|
const comment = buildComment({
|
||||||
|
status: 'published',
|
||||||
|
member: {uuid: '123'}
|
||||||
|
});
|
||||||
|
const appContext = {comments: [comment]};
|
||||||
|
|
||||||
|
const {container} = contextualRender(<CommentComponent comment={comment} />, {appContext});
|
||||||
|
expect(container.querySelector('[data-member-uuid="123"]')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not output member uuid data attribute for unpublished comments', function () {
|
||||||
|
const comment = buildComment({
|
||||||
|
status: 'hidden',
|
||||||
|
member: {uuid: '123'}
|
||||||
|
});
|
||||||
|
const appContext = {comments: [comment]};
|
||||||
|
|
||||||
|
const {container} = contextualRender(<CommentComponent comment={comment} />, {appContext});
|
||||||
|
expect(container.querySelector('[data-member-uuid="123"]')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('<RepliedToSnippet>', function () {
|
describe('<RepliedToSnippet>', function () {
|
||||||
|
|
|
@ -126,7 +126,7 @@ const PublishedComment: React.FC<PublishedCommentProps> = ({comment, parent, ope
|
||||||
const avatar = (<Avatar comment={comment} />);
|
const avatar = (<Avatar comment={comment} />);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CommentLayout avatar={avatar} className={hiddenClass} hasReplies={hasReplies}>
|
<CommentLayout avatar={avatar} className={hiddenClass} hasReplies={hasReplies} memberUuid={comment.member?.uuid}>
|
||||||
<div>
|
<div>
|
||||||
{isInEditMode ? (
|
{isInEditMode ? (
|
||||||
<>
|
<>
|
||||||
|
@ -419,10 +419,11 @@ type CommentLayoutProps = {
|
||||||
avatar: React.ReactNode;
|
avatar: React.ReactNode;
|
||||||
hasReplies: boolean;
|
hasReplies: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
memberUuid?: string;
|
||||||
}
|
}
|
||||||
const CommentLayout: React.FC<CommentLayoutProps> = ({children, avatar, hasReplies, className = ''}) => {
|
const CommentLayout: React.FC<CommentLayoutProps> = ({children, avatar, hasReplies, className = '', memberUuid = ''}) => {
|
||||||
return (
|
return (
|
||||||
<div className={`flex w-full flex-row ${hasReplies === true ? 'mb-0' : 'mb-7'}`} data-testid="comment-component">
|
<div className={`flex w-full flex-row ${hasReplies === true ? 'mb-0' : 'mb-7'}`} data-member-uuid={memberUuid} data-testid="comment-component">
|
||||||
<div className="mr-2 flex flex-col items-center justify-start sm:mr-3">
|
<div className="mr-2 flex flex-col items-center justify-start sm:mr-3">
|
||||||
<div className={`flex-0 mb-3 sm:mb-4 ${className}`}>
|
<div className={`flex-0 mb-3 sm:mb-4 ${className}`}>
|
||||||
{avatar}
|
{avatar}
|
||||||
|
|
Loading…
Reference in a new issue