-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Conversation
group-income Run #3496
Run Properties:
|
Project |
group-income
|
Branch Review |
sebin/task/#2429-file-should-show-size
|
Run status |
Passed #3496
|
Run duration | 08m 45s |
Commit |
25250c931b ℹ️: Merge b638fce3a4832b83eaef9d43cebd123a4d6661b4 into 3996fa4e2e984e26b48fa3f94756...
|
Committer | Sebin Song |
View all properties for this run ↗︎ |
Test results | |
---|---|
Failures |
0
|
Flaky |
0
|
Pending |
10
|
Skipped |
0
|
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)), |
There was a problem hiding this comment.
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 68optional
, 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 valueNumber.MAX_SAFE_INTEGER
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review ready!
frontend/views/utils/filters.js
Outdated
@@ -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' } |
There was a problem hiding this comment.
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'
frontend/views/utils/filters.js
Outdated
export const formatBytesDecimal = (bytes: number, decimals: number = 2): string => { | ||
if (bytes === 0) { return '0 Bytes' } | ||
|
||
const k = 1000 // Decimal base |
There was a problem hiding this comment.
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)), |
There was a problem hiding this comment.
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.
… sebin/task/#2429-file-should-show-size
…le-should-show-size
Updated the PR again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work @SebinSong!
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.