App icon indicating copy to clipboard operation
App copied to clipboard

[HOLD for payment 2021-12-13] $500 New Feature - Add a modal with the existing keyboard shortcuts - issue by @akshayasalvi

Open isagoico opened this issue 5 years ago • 50 comments

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

View all open jobs on GitHub

isagoico avatar Sep 29 '21 18:09 isagoico

Triggered auto assignment to @lschurr (AutoAssignerTriage), see https://stackoverflow.com/c/expensify/questions/4749 for more details.

MelvinBot avatar Sep 29 '21 18:09 MelvinBot

Triggered auto assignment to @roryabraham (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

MelvinBot avatar Sep 29 '21 18:09 MelvinBot

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.

roryabraham avatar Sep 29 '21 19:09 roryabraham

Sure. Is there any reference or way to find existing keyboard shortcuts @roryabraham? So that I can propose a solution.

akshayasalvi avatar Sep 29 '21 19:09 akshayasalvi

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.

rushatgabhane avatar Sep 30 '21 02:09 rushatgabhane

Okay thank you @rushatgabhane

@mallenexpensify Then per your suggestion we should add a some more keyboard shortcuts as well.

akshayasalvi avatar Sep 30 '21 05:09 akshayasalvi

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.

roryabraham avatar Oct 01 '21 06:10 roryabraham

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:

  1. In /settings/about as a new list item saying Keyboard Shortcuts

  2. On desktop, a new application menu item saying View Keyboard Shortcuts

    image

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.

roryabraham avatar Oct 01 '21 06:10 roryabraham

Those suggestions sound good to me Rory. I think for OldDot, you can type a question mark to launch the shortcut menu as well: image

shawnborton avatar Oct 01 '21 08:10 shawnborton

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 😬

roryabraham avatar Oct 01 '21 17:10 roryabraham

Proposal

I am adding a proposal that covers everything except for few alignment and color changes.

  1. 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);


  1. In ScreenWrapper we 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} />

  1. 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;
}

  1. Update the KeyboardShortcut.subscribe calls with relevant description keys
  2. Add translations in en and es
  3. Add the noop handling in .native. Will have to check how it works with desktop

Questions/Clarifications:

  1. Can I get the colors and dimensions of the modal?
  2. I've used a View to create a table. Do we have any other Table components or this is fine
  3. A personal opinion, I feel the shortcut should be Cmd + ?
  4. I have not added screen/module-wise shortcuts support as Slack does.
  5. Should I add support for Enter for forms and Arrow keys? then I'll have to update the KeyboardShortcutMap with default values.

Also, I feel, can we bump the budget by 100$ for this implementation?

akshayasalvi avatar Oct 04 '21 13:10 akshayasalvi

@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.

roryabraham avatar Oct 04 '21 21:10 roryabraham

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.

akshayasalvi avatar Oct 05 '21 15:10 akshayasalvi

Is this still on hold?

akshayasalvi avatar Oct 13 '21 17:10 akshayasalvi

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.

roryabraham avatar Oct 13 '21 20:10 roryabraham

Triggered auto assignment to @laurenreidexpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

MelvinBot avatar Oct 13 '21 20:10 MelvinBot

https://www.upwork.com/jobs/~01d43ff8f129f849ab

laurenreidexpensify avatar Oct 14 '21 10:10 laurenreidexpensify

Thanks @laurenreidexpensify, I've applied to the Upwork post.

akshayasalvi avatar Oct 14 '21 15:10 akshayasalvi

Hired in Upwork - @akshayasalvi at least I had the link correct on this one 🙃

laurenreidexpensify avatar Oct 14 '21 16:10 laurenreidexpensify

Haha. Thanks @laurenreidexpensify :)

akshayasalvi avatar Oct 14 '21 16:10 akshayasalvi