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

Communication: Allow users to paste images from the clipboard #9637

Merged
merged 13 commits into from
Nov 3, 2024

Conversation

pzdr7
Copy link
Contributor

@pzdr7 pzdr7 commented Oct 30, 2024

Checklist

General

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data (e.g. using paging).
  • I strictly followed the client coding and design guidelines.
  • I added multiple integration tests (Jest) related to the features (with a high test coverage), while following the test guidelines.
  • I documented the TypeScript code using JSDoc style.
  • I added multiple screenshots/screencasts of my UI changes.

Motivation and Context

It's currently not possible to (like on GitHub) paste images into the Markdown editor using the keyboard shortcut CTRL+V/Cmd+V.

Description

Added a paste listener that checks for images (and only images) in the clipboard and embeds them in the editor. Also, added some basic tests to improve the coverage.

Steps for Testing

Prerequisites:

  • 1 Student
  • 1 Course with communication enabled
  1. Take a screenshot of something, ensuring that the result is in your clipboard after.
  2. Navigate to the communication page of your course and open a channel.
  3. Write a message and paste an image into the Markdown editor by using CTRL+V (if you are on MacOS: Cmd+V). Note that your browser may prompt you once for clipboard access. Firefox will always prompt you.
  4. Send the message and ensure the image was embedded.
  5. Paste some regular text as well with CTRL+V / Cmd+V and ensure that it still works

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Client

Class/File Line Coverage Confirmation (assert/expect)
markdown-editor-monaco.component.ts 97.47%
monaco-text-editor.adapter.ts 96%
file-uploader.service.ts 100% ✅ (file not modified)
attachment.action.ts 100%

Screenshots

Screencast.from.29.10.2024.14_41_19.webm

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced file upload capabilities in the Markdown editor, allowing users to upload files directly and receive feedback on upload status.
    • Added functionality to handle paste events, enabling users to register actions when text is pasted into the editor.
  • Bug Fixes

    • Improved error handling during file uploads, providing alerts for failed uploads.
  • Tests

    • Expanded test coverage for file uploads and paste actions, ensuring robust functionality and user feedback in various scenarios.

@github-actions github-actions bot added tests client Pull requests that update TypeScript code. (Added Automatically!) labels Oct 30, 2024
Copy link

@HanyangXu0508 HanyangXu0508 left a comment

Choose a reason for hiding this comment

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

Every thing works well.

Copy link
Contributor

@coolchock coolchock left a comment

Choose a reason for hiding this comment

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

code LGTM

@HanyangXu0508 HanyangXu0508 self-requested a review November 3, 2024 11:59
Copy link

@HanyangXu0508 HanyangXu0508 left a comment

Choose a reason for hiding this comment

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

tested locally and works as expected

Copy link

@JanaNF JanaNF left a comment

Choose a reason for hiding this comment

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

Manual tested on TS2 in Chrome. Worked as expected

Copy link

@Feras797 Feras797 left a comment

Choose a reason for hiding this comment

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

Tested on TS1, everything works as described
image

Copy link
Contributor

@florian-glombik florian-glombik left a comment

Choose a reason for hiding this comment

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

Approve code

I left 2 comments that could be addressed, however, I have no hard feelings there and it might be a matter of taste anyways

Comment on lines +44 to +54
for (const clipboardItem of clipboardItems) {
for (const type of clipboardItem.types) {
if (type.startsWith('image/')) {
// Map image type to extension.
const extension = type.replace('image/', '');
const blob = await clipboardItem.getType(type);
files.push(new File([blob], `image.${extension}`, { type }));
break;
}
}
}
Copy link
Contributor

@florian-glombik florian-glombik Nov 3, 2024

Choose a reason for hiding this comment

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

I think that this should be a method on its own, from my point of view it would make the method easier to understand if it was a method with a descriptive name

export class MockClipboardItem {
types: string[];

getType(_type: string): Promise<Blob> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this might be worth adding a comment in the code here as well 😅

@krusche krusche merged commit 9a4f832 into develop Nov 3, 2024
120 of 122 checks passed
@krusche krusche deleted the chore/communication/paste-images branch November 3, 2024 18:39
@github-actions github-actions bot added deployment-error Added by deployment workflows if an error occured and removed deploy:artemis-test2 labels Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Pull requests that update TypeScript code. (Added Automatically!) deployment-error Added by deployment workflows if an error occured ready for review ready to merge tests
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

9 participants