Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cases] Show "removed comment" user action in the UI #123352

Merged
merged 3 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ describe('createCommentUserActionBuilder', () => {
expect(screen.getByText('edited comment')).toBeInTheDocument();
});

it('renders correctly when deleting a comment', async () => {
const userAction = getUserAction('comment', Actions.delete);
const builder = createCommentUserActionBuilder({
...builderArgs,
userAction,
});

const createdUserAction = builder.build();
render(
<TestProviders>
<EuiCommentList comments={createdUserAction} />
</TestProviders>
);

expect(screen.getByText('removed comment')).toBeInTheDocument();
});

it('renders correctly a user comment', async () => {
const userAction = getUserAction('comment', Actions.create, {
commentId: basicCase.comments[0].id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ import { createAlertAttachmentUserActionBuilder } from './alert';
import { createActionAttachmentUserActionBuilder } from './actions';

const getUpdateLabelTitle = () => `${i18n.EDITED_FIELD} ${i18n.COMMENT.toLowerCase()}`;
const getDeleteLabelTitle = () => `${i18n.REMOVED_FIELD} ${i18n.COMMENT.toLowerCase()}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: considering you will unlikely reuse this function, you can simply inline the string concatenation in the line 28 where you use it.


const getDeleteCommentUserAction = ({
userAction,
handleOutlineComment,
}: {
userAction: UserActionResponse<CommentUserAction>;
} & Pick<UserActionBuilderArgs, 'handleOutlineComment'>): EuiCommentProps[] => {
const label = getDeleteLabelTitle();
const commonBuilder = createCommonUpdateUserActionBuilder({
userAction,
handleOutlineComment,
label,
icon: 'cross',
});

return commonBuilder.build();
};

const getCreateCommentUserAction = ({
userAction,
Expand Down Expand Up @@ -101,8 +119,12 @@ export const createCommentUserActionBuilder: UserActionBuilder = ({
}) => ({
build: () => {
const commentUserAction = userAction as UserActionResponse<CommentUserAction>;
const comment = caseData.comments.find((c) => c.id === commentUserAction.commentId);

if (commentUserAction.action === Actions.delete) {
return getDeleteCommentUserAction({ userAction: commentUserAction, handleOutlineComment });
}

const comment = caseData.comments.find((c) => c.id === commentUserAction.commentId);
if (comment == null) {
return [];
}
Expand Down