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

#2429 - File attachment in chat should show the size #2435

Merged
merged 19 commits into from
Dec 3, 2024

Conversation

SebinSong
Copy link
Collaborator

works on #2429
There are currently two UIs for files attached to a message:

[case 1] General one - size is displayed next to the file format.


[case 2] Image preview - size is displayed as part of the tooltip text when hovered over the download button.

But please let me know if you have different ideas for them.

@SebinSong SebinSong self-assigned this Nov 27, 2024
Copy link

cypress bot commented Nov 27, 2024

group-income    Run #3496

Run Properties:  status check passed Passed #3496  •  git commit 25250c931b ℹ️: Merge b638fce3a4832b83eaef9d43cebd123a4d6661b4 into 3996fa4e2e984e26b48fa3f94756...
Project group-income
Branch Review sebin/task/#2429-file-should-show-size
Run status status check passed Passed #3496
Run duration 08m 45s
Commit git commit 25250c931b ℹ️: Merge b638fce3a4832b83eaef9d43cebd123a4d6661b4 into 3996fa4e2e984e26b48fa3f94756...
Committer Sebin Song
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 10
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 111
View all changes introduced in this branch ↗︎

@@ -67,6 +68,7 @@ export const messageType: any = objectMaybeOf({
attachments: arrayOf(objectOf({
name: string,
mimeType: string,
size: optional(numberRange(1, CHAT_ATTACHMENT_SIZE_LIMIT)),
Copy link
Member

Choose a reason for hiding this comment

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

Some observations:

  • Not all messages have attachments, but all attachments have a file size, right? So I think maybe it makes sense to make the arrayOf on line 68 optional, and make this size here mandatory.
  • Since CHAT_ATTACHMENT_SIZE_LIMIT could change in the future and even be an admin configurable value, let's make this value Number.MAX_SAFE_INTEGER instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right. updated.

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

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

Review ready!

@@ -15,6 +15,17 @@ export const getFileType = (
return mimeType.match('image/') ? 'image' : 'non-image'
}

export const formatBytesDecimal = (bytes: number, decimals: number = 2): string => {
if (bytes === 0) { return '0 Bytes' }
Copy link
Member

Choose a reason for hiding this comment

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

I would add some other checks here:

if (bytes < 0 || !Number.isFinite(bytes)) return 'Invalid size'

export const formatBytesDecimal = (bytes: number, decimals: number = 2): string => {
if (bytes === 0) { return '0 Bytes' }

const k = 1000 // Decimal base
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be 1024, as 1024 bytes = 1KB

arrayOf(objectOf({
name: string,
mimeType: string,
size: optional(numberRange(1, Number.MAX_SAFE_INTEGER)),
Copy link
Member

Choose a reason for hiding this comment

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

Can you check if we always provide this size info now? If so, this should probably no longer be optional.

@SebinSong
Copy link
Collaborator Author

Updated the PR again

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

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

Excellent work @SebinSong!

@taoeffect taoeffect merged commit c9c47d6 into master Dec 3, 2024
4 checks passed
@taoeffect taoeffect deleted the sebin/task/#2429-file-should-show-size branch December 3, 2024 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants