-
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
[No QA] [TS migration] Migrate 'useKeyboardShortcut.js' hook to TypeScript #29226
[No QA] [TS migration] Migrate 'useKeyboardShortcut.js' hook to TypeScript #29226
Conversation
…s-migration/useKeyboardShortcut/hook
…s-migration/useKeyboardShortcut/hook
@@ -130,12 +132,12 @@ function subscribe( | |||
key: string, | |||
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
captureOnInputs = false, | ||
shouldBubble = false, | ||
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 😅
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
captureOnInputs = false, | ||
shouldBubble = false, | ||
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
@@ -151,7 +153,7 @@ function subscribe( | |||
captureOnInputs, | |||
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, |
return keys.map((key) => { | ||
if (!(key in CONST.PLATFORM_SPECIFIC_KEYS)) { | ||
return key; | ||
} | ||
|
||
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
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 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
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mp4
MacOS: Desktop
desktop.mp4