[HOLD for payment 2021-12-13] $500 New Feature - Add a modal with the existing keyboard shortcuts - issue by @akshayasalvi
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel! https://www.upwork.com/jobs/~01d43ff8f129f849ab
Action Performed:
N/A
Expected Result:
There should be a list in-app with the existing keyboard shortcuts
Actual Result:
There's no list or information about the existing keyboard shortcuts.
Workaround:
N/A
Platform:
Where is this issue occurring?
- Web
- Desktop App
Version Number: N/A
Reproducible in staging?: yes Reproducible in production?: yes
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation
Expensify/Expensify Issue URL:
Issue reported by: @akshayasalvi Slack conversation: https://expensify.slack.com/archives/C01GTK53T8Q/p1632925571244200
Triggered auto assignment to @lschurr (AutoAssignerTriage), see https://stackoverflow.com/c/expensify/questions/4749 for more details.
Triggered auto assignment to @roryabraham (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.
This will end up being external, but I'm going to make it a weekly and sit on it for now because of the N6 hold.
Sure. Is there any reference or way to find existing keyboard shortcuts @roryabraham? So that I can propose a solution.
Sure. Is there any reference or way to find existing keyboard shortcuts
Cmd + K (Search) Cmd + Shift + K (New group) Escape (Close) Enter, Tab, Arrow keys (for navigation?)
Cltr instead of Cmd for Win/Linux. I think that's about it.
Okay thank you @rushatgabhane
@mallenexpensify Then per your suggestion we should add a some more keyboard shortcuts as well.
Then per your suggestion we should add a some more keyboard shortcuts as well.
@akshayasalvi I think this is out-of-scope for this issue.
Any thoughts on how this modal should be accessible in-product? Note that it would only be accessible on web/desktop, and right now it seems like the best places would be:
-
In
/settings/aboutas a new list item sayingKeyboard Shortcuts
-
On desktop, a new application menu item saying
View Keyboard Shortcuts
In the future maybe we could make keyboard shortcuts customizable then add a preferences menu where the user can adjust them as they please. But again, that's definitely out of scope for this issue and not a priority.
Those suggestions sound good to me Rory. I think for OldDot, you can type a question mark to launch the shortcut menu as well:

I think for OldDot, you can type a question mark to launch the shortcut menu as well:
I like this! As long as it doesn't happen when a text input is focused 😬
Proposal
I am adding a proposal that covers everything except for few alignment and color changes.
- We'll add a
KeyboardShortcutModal, which will look something like this.
import React from 'react';
import {View, Text} from 'react-native';
import _ from 'underscore';
import HeaderWithCloseButton from './HeaderWithCloseButton';
import Modal from './Modal';
import CONST from '../CONST';
import styles from '../styles/styles';
import withWindowDimensions from './withWindowDimensions';
import withLocalize from './withLocalize';
import compose from '../libs/compose';
import KeyboardShortcut from '../libs/KeyboardShortcut';
const KeyboardShortcutsModal = ({
isOpen, toggleKeyboardShortcutModal, isSmallScreenWidth, translate,
}) => {
const viewStyles = isSmallScreenWidth
? [styles.imageModalImageCenterContainer]
: [styles.imageModalImageCenterContainer, {width: 650}];
const shortcutMap = KeyboardShortcut.getKeyboardShortcutMap();
const shortcuts = [];
_.each(shortcutMap, (descriptionKey, key) => {
shortcuts.push({key, descriptionKey});
});
const renderRow = shortcut => (
<View style={[styles.flex1, styles.alignSelfStretch, styles.flexRow, {borderColor: 'grey', borderWidth: 1}]} key={shortcut.key}>
<View style={[styles.flex1, styles.p2, {width: '30%', backgroundColor: '#efefef'}]}>
<Text>{shortcut.key}</Text>
</View>
<View style={[styles.flex1, styles.p2, styles.alignSelfStretch]}>
<Text>{translate(`keyboardShortCutModal.shortcuts.${shortcut.descriptionKey}`)}</Text>
</View>
</View>
);
return (
<Modal isVisible={isOpen} modalType={CONST.MODAL.MODAL_TYPE.CENTERED} onClose={() => toggleKeyboardShortcutModal(false)}>
<View style={viewStyles}>
<HeaderWithCloseButton title="Keyboard Shortcuts" onCloseButtonPress={() => toggleKeyboardShortcutModal(false)} />
<Text>Sub title</Text>
<View style={[styles.flex1, styles.alignItemsCenter, styles.justifyContentCenter, {
width: '100%', borderColor: 'grey', borderRadius: 8, borderWidth: 1,
}]}
>
{shortcuts.map(shortcut => (renderRow(shortcut)))}
</View>
</View>
</Modal>
);
};
export default compose(
withWindowDimensions,
withLocalize,
)(KeyboardShortcutsModal);
- In
ScreenWrapperwe update the following:
// In constructor
this.state = {
didScreenTransitionEnd: false,
isKeyboardShortcutsModalOpen: false,
};
this.toggleKeyboardShortcutModal = this.toggleKeyboardShortcutModal.bind(this);
// in componentDidMount
this.unsubscribeShortCutModal = KeyboardShortcut.subscribe('?', () => {
this.toggleKeyboardShortcutModal(true);
}, [], false, 'openShortcutDialog');
// in componentWillUnmount
if (this.unsubscribeShortCutModal) {
this.unsubscribeShortCutModal();
}
// Add a function
toggleKeyboardShortcutModal(flag) {
this.setState({isKeyboardShortcutsModalOpen: flag});
}
// and in render method add the modal component
<KeyboardShortcutsModal toggleKeyboardShortcutModal={this.toggleKeyboardShortcutModal} isOpen={this.state.isKeyboardShortcutsModalOpen} />
- For listing the shortcuts, I was wondering if we should make it a static list or add it to the map whenever it is subscribed. I've gone ahead with the latter (concerned about unsubscribed method though).
In KeyboardShortcut/index.js,
// Add a map and a getter
const KeyboardShortcutMap = {};
function getKeyboardShortcutMap() {
return KeyboardShortcutMap;
}
// Update the subscribe function
function subscribe(key, callback, modifiers = 'shift', captureOnInputs = false, description) {
const keyCode = getKeyCode(key);
addKeyToMap(key, modifiers, description);
// Add to keycode map
case '?':
return 191;
// Add function to update the map
function addKeyToMap(key, modifiers, description) {
let shortcutKey = [key];
if (typeof modifiers === 'string') {
shortcutKey.unshift(modifiers);
} else if (Array.isArray(modifiers)) {
shortcutKey = [...modifiers, ...shortcutKey];
}
shortcutKey = shortcutKey.join(' + ');
KeyboardShortcutMap[shortcutKey] = description;
}
- Update the
KeyboardShortcut.subscribecalls with relevant description keys - Add translations in
enandes - Add the noop handling in
.native.Will have to check how it works with desktop
Questions/Clarifications:
- Can I get the colors and dimensions of the modal?
- I've used a View to create a table. Do we have any other Table components or this is fine
- A personal opinion, I feel the shortcut should be
Cmd + ? - I have not added screen/module-wise shortcuts support as Slack does.
- Should I add support for
Enterfor forms and Arrow keys? then I'll have to update theKeyboardShortcutMapwith default values.
Also, I feel, can we bump the budget by 100$ for this implementation?
@akshayasalvi Thanks for your detailed proposal, it looks pretty good. However, as stated above this issue is still on hold at this time. You'll be first in line when this issue is exported.
Some feedback to keep in mind in the future is that when you have too much low-level detail or code in a proposal, then it makes it much more difficult for someone to review the proposal at a high level. It's better to explain the solution in plain English with enough detail to show that you understand the problem and solution, rather than mostly implementing your solution and showing all the code from that exploration. You can always provide more detail where things are non-obvious or if asked by your reviewer.
I've used a View to create a table. Do we have any other Table components or this is fine
Using a View is fine.
A personal opinion, I feel the shortcut should be
Cmd + ?
I agree 👍
I have not added screen/module-wise shortcuts support as Slack does.
Do you mean that the keyboard shortcuts exist globally and not on a per-screen basis? As far as I know, the existing keyboard shortcuts only work in the AuthScreens stack navigator, so it stands to reason that the keyboard shortcut modal should only be accessible from AuthScreens stack navigator. If we ensure that, then we don't need to worry about screen/module-wise shortcuts.
Should I add support for Enter for forms and Arrow keys? then I'll have to update the KeyboardShortcutMap with default values.
No, I think that's pretty standard and self-explanatory. Let's just include the very application-specific shortcuts in this modal.
Thanks for the detailed feedback @roryabraham. I'll keep these pointers for the next proposals. I've looked at other issues where contributors post solutions + videos as well. Thank you for your clarifying.
If we ensure that, then we don't need to worry about screen/module-wise shortcuts.
Noted.
Is this still on hold?
Hello @akshayasalvi this is still on hold, but I think at this point we can get an Upwork job created for it so you can get started. That way you might have a PR ready and pre-reviewed once the hold is lifted.
Triggered auto assignment to @laurenreidexpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.
https://www.upwork.com/jobs/~01d43ff8f129f849ab
Thanks @laurenreidexpensify, I've applied to the Upwork post.
Hired in Upwork - @akshayasalvi at least I had the link correct on this one 🙃
Haha. Thanks @laurenreidexpensify :)