-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[No QA] [TS migration] Migrate 'useKeyboardShortcut.js' hook to TypeScript #29226
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
[No QA] [TS migration] Migrate 'useKeyboardShortcut.js' hook to TypeScript #29226
Conversation
…s-migration/useKeyboardShortcut/hook
…s-migration/useKeyboardShortcut/hook
| callback: () => void, | ||
| descriptionKey: string, | ||
| modifiers: string[] = ['shift'], | ||
| modifiers: ShortcutModifiers = ['CTRL'], |
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.
@kubabutkiewicz Why did you change the default value?
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 Because modifiers are declared here and there is no shortcut with only shift key modifier so it doesn't make sense to default it to that key
src/libs/KeyboardShortcut/index.ts
Outdated
| priority = 0, | ||
| shouldPreventDefault = true, | ||
| excludedNodes = [], | ||
| excludedNodes: string[] | readonly never[] = [], |
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.
@kubabutkiewicz Could you please clarify why readonly never[] is necessary?
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 It because of that

we are setting default value which comes from CONST and its basically an empty array but kt comes from CONST thats why its need to be typed as readonly never[]
| excludedNodes, | ||
| ); | ||
|
|
||
| return () => { |
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 return unsubscribe;
also i think taht should work - little bit shorter version
return KeyboardShortcut.subscribe(
shortcut.shortcutKey,
callback,
shortcut.descriptionKey ?? '',
shortcut.modifiers,
captureOnInputs,
shouldBubble,
priority,
shouldPreventDefault,
excludedNodes,
);
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 prefer no changing it to be sure to not introduce regressions, theoretically there shouldn't be be we never know 😅
blazejkustra
left a comment
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.
Only small remarks! LGTM
src/libs/KeyboardShortcut/index.ts
Outdated
| priority = 0, | ||
| shouldPreventDefault = true, | ||
| excludedNodes = [], | ||
| excludedNodes: string[] | readonly never[] = [], |
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.
| excludedNodes: string[] | readonly never[] = [], | |
| excludedNodes: string[] = [], |
src/libs/KeyboardShortcut/index.ts
Outdated
| shouldPreventDefault, | ||
| shouldBubble, | ||
| excludedNodes, | ||
| excludedNodes: [...excludedNodes], |
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.
| excludedNodes: [...excludedNodes], | |
| excludedNodes, |
| } | ||
|
|
||
| const platformModifiers = CONST.PLATFORM_SPECIFIC_KEYS[key as keyof typeof CONST.PLATFORM_SPECIFIC_KEYS]; | ||
| const platformModifiers = CONST.PLATFORM_SPECIFIC_KEYS[key]; |
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 one 👍
src/hooks/useKeyboardShortcut.ts
Outdated
| shouldBubble, | ||
| priority, | ||
| shouldPreventDefault, | ||
| excludedNodes, |
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.
| excludedNodes, | |
| excludedNodes as string[], |
src/hooks/useKeyboardShortcut.ts
Outdated
| /** | ||
| * Register a keyboard shortcut handler. | ||
| * Recommendation: To ensure stability, wrap the `callback` function with the useCallback hook before using it with this hook. | ||
| * |
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.
| * |
…s-migration/useKeyboardShortcut/hook
|
@chiragsalian Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
…s-migration/useKeyboardShortcut/hook
chiragsalian
left a comment
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.
Code LGTM, but would you be able to investigate the failed perf-tests GH action.
…s-migration/useKeyboardShortcut/hook
|
@chiragsalian perf test now passing |
|
✋ 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 production by https://github.com/puneetlath in version: 1.3.97-7 🚀
|
|
🚀 Deployed to staging by https://github.com/chiragsalian in version: 1.3.98-0 🚀
|
|
🚀 Deployed to production by https://github.com/roryabraham in version: 1.3.98-5 🚀
|
| // Hence the use of CONST.EMPTY_ARRAY. | ||
| excludedNodes = CONST.EMPTY_ARRAY, | ||
| isActive = true, | ||
| shouldStopPropagation = false, |
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.
Coming from #31689:
There was bad merge. This property was missing in new TS file.
Here's fix: https://github.com/Expensify/App/pull/32176/files
Details
Fixed Issues
$ #24942
Tests
Offline tests
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mp4
MacOS: Desktop
desktop.mp4