Skip to content
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

feat: Add a keyboard shortcut to move focus to search #4796

Merged
merged 1 commit into from Dec 1, 2020

Conversation

chetan-rns
Copy link
Member

Pressing "/" will move the focus to the search bar on the applications page

Fixes: #4700
Signed-off-by: Chetan Banavikalmutt chetanrns1997@gmail.com

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • Optional. My organization is added to USERS.md.
  • [x ] I've signed the CLA and my build is green (troubleshooting builds).

Copy link
Member

@jannfis jannfis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, although / is bound to a useful Firefox shortcut as well (quick find in page). In this case, overriding the FF shortcut would add value for me tho.

IMHO, it would be nice to have more keyboard shortcuts for the UI, but I feel we should generally think about the shortcuts and their integration a little, before randomly introducing them, ensuring a consistent user experience (also across browsers).

@@ -40,6 +40,16 @@ const APP_FIELDS = [
const APP_LIST_FIELDS = ['metadata.resourceVersion', ...APP_FIELDS.map(field => `items.${field}`)];
const APP_WATCH_FIELDS = ['result.type', ...APP_FIELDS.map(field => `result.application.${field}`)];

document.onkeypress = e => {
if (e.keyCode === 47) {
const searchBar = document.getElementById('search-bar');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as #4801 (comment) . Please use React.useRef instead of document.getElementById('search-bar')

@alexmt alexmt self-assigned this Nov 16, 2020
@@ -40,6 +40,16 @@ const APP_FIELDS = [
const APP_LIST_FIELDS = ['metadata.resourceVersion', ...APP_FIELDS.map(field => `items.${field}`)];
const APP_WATCH_FIELDS = ['result.type', ...APP_FIELDS.map(field => `result.application.${field}`)];

document.onkeypress = e => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overriding onkeypress might be unpleasant if we add a key press handler in another component.
Please use useEffect hook to add handler with document.addEventListener and remove listener in hook cleanup. E.g.

useEffect(() => {
    const handleKeyPress = (e) => {
       ...
    }
    document.addEventListener('keypress', handleKeyPress);
    return () => {
      document.removeEventListener('keypress', handleKeyPress);
    };
  });

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the code to use React.useEffect

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use / while adding the git repository in the application create form. We shouldn't consider / as a special shortcut when the Application form is opened.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexmt I've added a check to disable this shortcut when the new application form is opened.

@chetan-rns chetan-rns force-pushed the keyboard-shortcut branch 2 times, most recently from 8ba161c to b5344fa Compare November 23, 2020 16:31
Copy link
Collaborator

@alexmt alexmt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexmt
Copy link
Collaborator

alexmt commented Dec 1, 2020

@chetan-rns , can you please resolve merge conflicts?

Fixes: argoproj#4700
Signed-off-by: Chetan Banavikalmutt <chetanrns1997@gmail.com>
@codecov-io
Copy link

Codecov Report

Merging #4796 (309fa17) into master (b89639e) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4796   +/-   ##
=======================================
  Coverage   41.13%   41.13%           
=======================================
  Files         129      129           
  Lines       17875    17875           
=======================================
  Hits         7353     7353           
  Misses       9459     9459           
  Partials     1063     1063           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b89639e...309fa17. Read the comment docs.

@alexmt alexmt merged commit 6095fc5 into argoproj:master Dec 1, 2020
rbreeze pushed a commit that referenced this pull request Jan 12, 2021
Fixes: #4700
Signed-off-by: Chetan Banavikalmutt <chetanrns1997@gmail.com>
Signed-off-by: Remington Breeze <remington@breeze.software>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add / keyboard shortcut to move focus to search in UI
4 participants