-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[TS migration] Migrate 'User.js' lib to TypeScript #28695
[TS migration] Migrate 'User.js' lib to TypeScript #28695
Conversation
src/libs/actions/User.ts
Outdated
@@ -512,7 +498,7 @@ function subscribeToUserEvents() { | |||
previousUpdateID: Number(pushJSON.previousUpdateID || 0), | |||
}; | |||
if (!OnyxUpdates.doesClientNeedToBeUpdated(Number(pushJSON.previousUpdateID || 0))) { | |||
OnyxUpdates.apply(updates); | |||
OnyxUpdates.apply(updates as any); |
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.
Does this type match?
OnyxUpdates.apply(updates as any); | |
OnyxUpdates.apply(updates as OnyxUpdate[]); |
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.
needs to be as unknown as OnyxUpdate so kinda ugly cast
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.
Do you mean updates a kind of as unknown as OnyxUpdate[]
? Just to clarify:updates
- is an array of OnyxUpdate's?
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.
no type is not applicable to onyx update, that why it needs to be as unknown as OnyxUpdate
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.
First, lets type updates
object to be OnyxUpdatesFromServer
.
Then, I think we can remove these two lines from apply()
. They are not doing anything additional there and is causing issues here.
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.
Left comments.
@@ -2,9 +2,11 @@ import {OnyxUpdate} from 'react-native-onyx'; | |||
import Request from './Request'; | |||
import Response from './Response'; | |||
|
|||
type OnyxServerUpdate = OnyxUpdate & {shouldNotify?: boolean}; |
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.
Not sure about this update, maybe it makes sense to update OnyxUpdate
type in the onyx lib if we really need shouldNotify
field
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.
@fabioh8010 what do You think about it?
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.
@VickyStash If I remember correctly it was me that suggested to create this separate type. The reason for that is because the OnyxUpdate
from Onyx itself doesn't have shouldNotify
, but Expensify backend often sends Onyx updates with this property together, so that's why I advised @fvlvte to create a separate type.
src/libs/actions/User.ts
Outdated
key: ONYXKEYS.PERSONAL_DETAILS_LIST, | ||
value: { | ||
[currentUserAccountID]: { | ||
status: status.text, |
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.
Why did you change from status,
to status: status.text,
?
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.
Type mismatch, we use status as text in personal details list and CustomStatus is an object composed of text, emojiCode, expiresAt (according to JSDoc).
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 could cause regression, our type maybe was wrong? Either way let's test it @fvlvte
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've aligned types in Onyx, and aligned usage in Sidebar component.
It was mistyped in PersonalDetails and misused in Sidebar component as object treated as string.
I think this feature was bugged originally, now seems working fine.
@@ -2,9 +2,11 @@ import {OnyxUpdate} from 'react-native-onyx'; | |||
import Request from './Request'; | |||
import Response from './Response'; | |||
|
|||
type OnyxServerUpdate = OnyxUpdate & {shouldNotify?: boolean}; |
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.
@VickyStash If I remember correctly it was me that suggested to create this separate type. The reason for that is because the OnyxUpdate
from Onyx itself doesn't have shouldNotify
, but Expensify backend often sends Onyx updates with this property together, so that's why I advised @fvlvte to create a separate type.
# Conflicts: # src/libs/actions/User.ts
src/libs/actions/User.ts
Outdated
key: ONYXKEYS.PERSONAL_DETAILS_LIST, | ||
value: { | ||
[currentUserAccountID]: { | ||
status: status.text, |
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 could cause regression, our type maybe was wrong? Either way let's test it @fvlvte
Ops @fvlvte @fabioh8010 😅 |
Ye, reverting it right now |
85dafb7
to
4edce16
Compare
# Conflicts: # src/libs/actions/User.ts
@blazejkustra ready to re-review, answered and addressed to all comments i guess and fixed this custom status in sidebar :P |
@fvlvte I think we're still waiting for updated QA steps per your comment? Also would be good if you could upload the test videos. Thanks! |
Yes, im working on new steps and videos right now. |
Steps added and videos 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.
LGTM!
We did not find an internal engineer to review this PR, trying to assign a random engineer to #24924 as well as to this PR... Please reach out for help on Slack if no one gets assigned! |
PR review checklist updated! |
}, | ||
]; | ||
|
||
type CloseAccountParams = {message: 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.
NAB necessarily for this PR, but maybe worth a discussion ... this feels like it could be better. I'm not entirely sure what pattern we've followed so far, but I feel like the best pattern to follow would be to basically have a centralized APIParamMap
somewhere that define the params accepted by each API endpoint, and which ensures that the parameters passed to a specific endpoint match the type defined for that endpoint.
cc @fabioh8010 @blazejkustra what do you think? Long-term this could lend itself to some compile-time validation across the front-end and the API that ensures that the params expected by each API endpoint (defined in the API layer) are provided by the front-end (verified via TypeScript)
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.
Great thinking @roryabraham! 🙌
Actually this is our plan with @fabioh8010 to have a central point with an object with command names and params. We want to implement it in a separate PR once all libs are migrated to Typescript.
More context: That's why we decided to have these Params
types defined in the bodies of action functions, so it is easier to extract in the future.
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.
Ok, let's make an issue and start now and do the migration incrementally? Not going to block on this for this PR but let's discuss in slack.
*/ | ||
function clearDraftCustomStatus() { | ||
Onyx.merge(ONYXKEYS.CUSTOM_STATUS_DRAFT, {text: '', emojiCode: '', clearAfter: '', customDateTemporary: ''}); | ||
Onyx.merge(ONYXKEYS.CUSTOM_STATUS_DRAFT, {text: '', emojiCode: '', clearAfter: ''}); |
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.
Why was customDateTemporary
removed here?
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 not used anywhere and it's missing on our Onyx type, so removed it to get rid of type errors.
@roryabraham - PR updated and answered. |
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.
Done @roryabraham |
✋ 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/roryabraham in version: 1.4.23-0 🚀
|
🚀 Deployed to production by https://github.com/thienlnam in version: 1.4.23-4 🚀
|
Details
Migrated 'User.js' lib to TypeScript.
Fixed Issues
$ #24924
PROPOSAL: N/A
Tests
Offline tests
N/A
QA Steps
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
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
Android: Native
android-nt.mov
Android: mWeb Chrome
chrome-android.mov
iOS: Native
ios.mov
iOS: mWeb Safari
ios-web.mov
MacOS: Chrome / Safari
mac-web.mov
MacOS: Desktop
mac-desktop.mov