-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix QR image show OldDot avatar for a moment after profile avatar being removed #19521
Conversation
src/libs/ReportUtils.js
Outdated
function getNewDotDefaultAvatar(login = '') { | ||
if (login === CONST.EMAIL.CONCIERGE) { | ||
return CONST.CONCIERGE_ICON_URL; | ||
} | ||
|
||
// There are 24 possible new dot default avatars, so we choose which one this user has based | ||
// on a simple hash of their login. Note that Avatar count starts at 1. | ||
const loginHashBucket = hashLogin(login, CONST.DEFAULT_AVATAR_COUNT) + 1; | ||
|
||
return `${CONST.CLOUDFRONT_URL}/images/avatars/default-avatar_${loginHashBucket}.png`; | ||
} |
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.
@hoangzinh This helper function looks same as getOldDotDefaultAvatar
, the only diff is the url part default-
. To maintain DRY code, maybe we should:
- Rename
getOldDotDefaultAvatar
togetDefaultAvatarURL
- Include new parameter ,
isNewDot
and update code accordingly
function getDefaultAvatarURL(login = '',isNewDot=false) {
if (login === CONST.EMAIL.CONCIERGE) {
return CONST.CONCIERGE_ICON_URL;
}
// There are 8 possible old dot default avatars, so we choose which one this user has based
// on a simple hash of their login. Note that Avatar count starts at 1.
const loginHashBucket = hashLogin(login, CONST.OLD_DEFAULT_AVATAR_COUNT) + 1;
return `${CONST.CLOUDFRONT_URL}/images/avatars/${isNewDot?'default-':''}avatar_${loginHashBucket}.png`;
}
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.
It's also diff with number of possible default avatars too. CONST.OLD_DEFAULT_AVATAR_COUNT
vs CONST.DEFAULT_AVATAR_COUNT
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.
It's reason I decided to make a new method for it. Code will be easier to read w/out branching conditions.
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.
It's also diff with number of possible default avatars too. CONST.OLD_DEFAULT_AVATAR_COUNT vs CONST.DEFAULT_AVATAR_COUNT
hmm , it could be extracted as well to a new variable
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.
Good idea. Let me update the PR
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 have updated PR for those default avatar methods. Please you help me review it again. Thanks @fedirjh
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.
Looks good, left minor improvement
src/libs/ReportUtils.js
Outdated
// We choose default avatar this user has based on a simple hash of their login. | ||
// Note that Avatar count starts at 1. | ||
const loginHashBucket = hashLogin(login, isNewDot ? CONST.DEFAULT_AVATAR_COUNT : CONST.OLD_DEFAULT_AVATAR_COUNT) + 1; | ||
const defaultAvatar = isNewDot ? `default-avatar_${loginHashBucket}` : `avatar_${loginHashBucket}`; |
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.
const defaultAvatar = isNewDot ? `default-avatar_${loginHashBucket}` : `avatar_${loginHashBucket}`; | |
const avatarPrefix = isNewDot ? `default-avatar` : `avatar`; |
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 updated PR according to above suggestion.
src/libs/ReportUtils.js
Outdated
|
||
return `${CONST.CLOUDFRONT_URL}/images/avatars/avatar_${loginHashBucket}.png`; | ||
return `${CONST.CLOUDFRONT_URL}/images/avatars/${defaultAvatar}.png`; |
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.
return `${CONST.CLOUDFRONT_URL}/images/avatars/${defaultAvatar}.png`; | |
return `${CONST.CLOUDFRONT_URL}/images/avatars/${avatarPrefix}_${loginHashBucket}.png`; |
Reviewer Checklist
Screenshots/VideosWebWeb.movMobile Web - ChromeChrome.movMobile Web - SafariSafari.movDesktopDektop.moviOSIOS.movAndroidAndroid.mov |
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.
LGTM and test well.
cc @tgolen
src/libs/ReportUtils.js
Outdated
* | ||
* @param {String} [avatarURL] - the avatar source from user's personalDetails | ||
* @param {String} [login] - the email of the user | ||
* @returns {String|Function} |
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.
How does this return a function? According to JSDocs, avatarURL
is a string and getDefaultAvatarURL()
returns a string.
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.
Sorry @tgolen copy/paste mistake.
src/libs/ReportUtils.js
Outdated
isDefaultAvatar, | ||
getOldDotDefaultAvatar, | ||
getDefaultAvatarURL, |
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.
IMO these methods are in the wrong file. Can you move all of the avatar-related functions (that have nothing to do with reports) to UserUtils.js
please?
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.
Nice suggestion btw. I will update it in next commit
Co-authored-by: Tim Golen <[email protected]>
Co-authored-by: Tim Golen <[email protected]>
Co-authored-by: Tim Golen <[email protected]>
Given the fact that, it will require a bit of effort & touching to multiple files. To avoid it will be getting conflict with other PR touching same LOC, please help me review this PR ASAP. Thanks |
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.
Oh wow, I didn't realize there we so many. Thanks for moving those 🎉
src/libs/ReportUtils.js
Outdated
@@ -8,7 +8,7 @@ import ONYXKEYS from '../ONYXKEYS'; | |||
import CONST from '../CONST'; | |||
import * as Localize from './Localize'; | |||
import * as Expensicons from '../components/Icon/Expensicons'; | |||
import hashCode from './hashCode'; | |||
import hashLogin from './hashLogin'; |
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 wonder why this was import and exported ? maybe we can remove it and update it's usage here , it's only used once in StyleUtils
Line 165 in 0f33e2c
const colorHash = ReportUtils.hashLogin(workspaceName.trim(), workspaceColorOptions.length); |
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.
Or it can be moved to userUtils
as well and exported from there. What do you think @tgolen ?
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.
UserUtils makes sense to me 👍
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.
Nice catch @fedirjh I think we can put this method in UserUtils. I updated PR for this suggestion
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.
LGTM and tests well
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.
Sorry, one last thing... I wonder if you agree.
@@ -162,7 +162,7 @@ function getAvatarBorderStyle(size, type) { | |||
* @returns {Object} | |||
*/ | |||
function getDefaultWorkspaceAvatarColor(workspaceName) { | |||
const colorHash = ReportUtils.hashLogin(workspaceName.trim(), workspaceColorOptions.length); | |||
const colorHash = UserUtils.hashLogin(workspaceName.trim(), workspaceColorOptions.length); |
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.
This really begs the question if we need this to be in a lib at all. It's one line of code that is only used in one spot. Let's just define it here and keep it out of the utils entirely. This is a good reminder of over-engineering things :D (not you, I'm not sure who originally wrote this).
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.
Hmm it's used in UserUtils
as well
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.
@tgolen bump for comment above ^
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.
Ah, OK. I missed that, thanks.
Quick bump on it ^ |
@hoangzinh you have a lint error |
@fedirjh all checks is green now. |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by https://github.com/tgolen in version: 1.3.20-0 🚀
|
🚀 Deployed to production by https://github.com/Julesssss in version: 1.3.20-5 🚀
|
Details
Fixed Issues
$ #19211
PROPOSAL: #19211 (comment)
Tests
On Web/mWeb:
Offline tests
Same as above
QA Steps
Same as above
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Web
Screen.Recording.2023-05-24.at.21.27.17.-.web.mp4
Mobile Web - Chrome
Screen.Recording.2023-05-24.at.22.17.48.-.android.chrome.mp4
Mobile Web - Safari
Screen.Recording.2023-05-24.at.22.25.27.mp4
Desktop
Screen.Recording.2023-05-24.at.21.45.59.-.desktop.mp4
iOS
Screen.Recording.2023-05-24.at.22.29.36.-.ios.mp4
Android
Screen.Recording.2023-05-24.at.22.20.36.-.android.mp4