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: command palette #1611

Merged
merged 21 commits into from
Nov 19, 2024
Merged

Conversation

d-rita
Copy link
Contributor

@d-rita d-rita commented Sep 27, 2024

Implements 351


Description

The command palette is a one stop search for all apps, commands and shortcuts. (backend implementation pending for the last two). This PR builds the UI (views) to support the execution of this functionality.

Implementation details:

For the implementation, the major building blocks I worked on are:

Views

  • Default (Home view): this is the view on launching the command palette. It contains 2 sections, i.e. a grid section of 8 apps, and an actions section with: a logout link, and conditionally rendered links to the full lists.
  • List view: this is the view for the full lists of apps, shortcuts, and commands. As well as the filtered search results.

Sections:

  • All the smaller components making up the views: search field, list item, back button, app item, etc

Hooks

  • useFilter: this hook makes use of the filterItemsArray function to return filtered results of the apps, commands and shortcuts
  • useAvailableActions: this hook computes which actions are available to the user depending on the number of apps, commands, shortcuts returned by their respective API endpoints.
  • useNavigation: this hook handles the keyboard navigation of the command palette. This includes:
    • highlighting an item and keeping track of its position inside the views using the arrow keys.
    • the closing and opening of the command palette with the keyboard.
    • switching back to the default view from the list view

Context

  • I added a CommandPaletteContext which contains states of the current view, filter, highlighted index, and active home view section, that are consumed and used by the different components within the command palette component to help with navigation, highlighting of items, filtering, and view selection.

Others:

  • Moved the previously implemented escapeRegExpCharacters into a utils directory.
  • Created a filterItemsArray utils function from this implementation to handle filtering of other items besides the apps.
  • Added unit tests for the command palette catering to different scenarios, including navigation, highlighting, search, (conditional) rendering of the components within the views.
  • Modified the header-bar cypress tests to accommodate the changes made in this component

How to test:

  • Pull and checkout the branch:
         git fetch origin LIBS-351/headerbar-apps-menu
         git checkout LIBS-351/headerbar-apps-menu
    
  • Go to http://localhost:5000/
  • Select the headerbar component.
  • Testing scenarios:
    • Open the command palette by:
      • Click on the headerbar icon
      • Pressing Cmd/Ctrl + /
    • Navigation by hovering or using the arrow keys
    • Search for existing and non-existent items,
    • Selecting items by clicking on them or pressing enter when they are highlighted,
    • Close command palette by:
      • Clicking outside the command palette
      • Pressing Cmd/Ctrl + /
      • Pressing Esc

Checklist

  • API docs are generated
  • Tests were added
  • Storybook demos were added

Screenshots

Home view

home view

Browse apps view

full list view

Search Results

search results

Empty Search

empty search

@d-rita d-rita changed the title Libs 351/headerbar apps menu feat: HeaderBar Apps Menu command palette Sep 27, 2024
@d-rita d-rita force-pushed the LIBS-351/headerbar-apps-menu branch from 3ddb8df to 1b2bac1 Compare September 29, 2024 01:43
@d-rita d-rita requested a review from amcgee October 1, 2024 05:31
@d-rita d-rita force-pushed the LIBS-351/headerbar-apps-menu branch from 1b2bac1 to a529dc0 Compare October 1, 2024 09:17
@d-rita d-rita changed the title feat: HeaderBar Apps Menu command palette feat: command palette Oct 1, 2024
@dhis2-bot
Copy link
Contributor

dhis2-bot commented Oct 1, 2024

🚀 Deployed on https://pr-1611--dhis2-ui.netlify.app

@dhis2-bot dhis2-bot temporarily deployed to netlify October 1, 2024 09:23 Inactive
@d-rita d-rita force-pushed the LIBS-351/headerbar-apps-menu branch from a529dc0 to 521abe3 Compare October 16, 2024 16:19
@d-rita d-rita force-pushed the LIBS-351/headerbar-apps-menu branch from 521abe3 to 150e231 Compare October 16, 2024 16:22
@dhis2-bot dhis2-bot temporarily deployed to netlify October 16, 2024 16:25 Inactive
@d-rita d-rita requested a review from a team October 17, 2024 08:57
@d-rita d-rita requested a review from cooper-joe October 18, 2024 11:21
@dhis2-bot dhis2-bot temporarily deployed to netlify October 21, 2024 14:09 Inactive
- update data-test ids and classes used to retrieve components
- update test titles/scenarios to account for apps, shortcuts and commands
@dhis2-bot dhis2-bot temporarily deployed to netlify October 25, 2024 07:58 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify October 25, 2024 08:29 Inactive
@d-rita d-rita force-pushed the LIBS-351/headerbar-apps-menu branch from 781510b to 0579262 Compare October 25, 2024 08:49
@dhis2-bot dhis2-bot temporarily deployed to netlify October 25, 2024 08:53 Inactive
@d-rita d-rita marked this pull request as ready for review October 30, 2024 13:04
@d-rita d-rita requested a review from a team as a code owner October 30, 2024 13:04
@dhis2-bot dhis2-bot temporarily deployed to netlify October 30, 2024 13:06 Inactive
setHighlightedIndex(0)
}, [setActiveSection, setCurrentView, setFilter, setHighlightedIndex])

const handleListViewNavigation = useCallback(
Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd be good to have a test for arrow navigation (focusing on edge cases, when list has only one item, when you're at the end of the list etc..)

const lastIndex = itemsArray.length - 1
switch (event.key) {
case 'ArrowDown':
setHighlightedIndex(
Copy link
Collaborator

Choose a reason for hiding this comment

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

are we sure we don't need preventDefault for ArrowDown and Up? (maybe ArrowDown scrolls the page?)

Copy link
Collaborator

@kabaros kabaros left a comment

Choose a reason for hiding this comment

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

lgtm - it'd be good to add tests for navigation with arrow keys (and decide where this will be merged until the backend for shortcuts and commands is implemented)

@cooper-joe
Copy link
Member

I noticed that the highlight position is carried over from a unfiltered state to the filtered state.
Example:

  1. Open command palette
  2. Move highlight to position 3 (the third app in the grid)
  3. Start typing to enter the filtered state
    Expectation: the highlight should be on the first item in the filtered state list
    Current outcome: the highlight is on the third item in the filtered state list (and is potentially hidden if there are < 3 items).

- Retrieve respective actions based on the availability of apps, shortcuts, and commands
- Track active index of the highlighted action from the dynamically rendered actions menu
- Only show and select grid as active section if apps are available
- Highlight first item in the list across all views, i.e. full lists, and search results
- Add tests for the Up and Down arrow key navigation in the list views
- Add tests for the Right and Left arrow key navigation in the app grid
- Add tests for the search and highlighting functionality in the command palette
@dhis2-bot dhis2-bot temporarily deployed to netlify November 6, 2024 00:45 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify November 6, 2024 17:06 Inactive
@d-rita d-rita self-assigned this Nov 6, 2024
@amcgee amcgee changed the base branch from master to feature-command-palette November 19, 2024 12:02
@amcgee
Copy link
Member

amcgee commented Nov 19, 2024

🎉 🎉 🎉

@amcgee
Copy link
Member

amcgee commented Nov 19, 2024

Merging this to a feature branch 👍

@amcgee amcgee merged commit 07931b9 into feature-command-palette Nov 19, 2024
20 checks passed
@amcgee amcgee deleted the LIBS-351/headerbar-apps-menu branch November 19, 2024 12:11
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.

5 participants