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): grid layout #1671

Open
wants to merge 26 commits into
base: feature-command-palette
Choose a base branch
from

Conversation

d-rita
Copy link
Contributor

@d-rita d-rita commented Feb 20, 2025

Addresses LIBS-752


Description

This PR adjusts the grid layout on the HomeView depending on the screen size.

  • For screens with a viewport width < 480, it shows a 2 * 4 grid (columns * rows).
  • For larger screens, a 4 * 2 grid is shown.

It also adjusts the layout and navigation accordingly depending on how many apps are available in the grid.


Checklist

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

Screenshots

  1. Full grid - small screens
full.grid.-.small.screen.mov
  1. Partial grid - small screens
partial.grid.-.small.screen.mov
  1. Partial Grid - Large screens
partial.grid.-.large.screens.mov

d-rita and others added 23 commits January 26, 2025 02:58
- use native dialog element for modal container
- separate modal logic to a useModal hook
- add a constants file for commonly used strings
- remove functionality creating focus on 2 items at once by keyboard and hovering
- update test simulating focus by hovering over an item
- add key press handlers for each arrow key
- add test to search for logout on home view
- add filterable_action type
- add actions to all items that can be filtered via the useFilter hook
- remove setup for commands
* feat: update esc, tab and backspace keydown logic

* feat: override default behaviour for cmd+k shortcut

* fix: input component import

* fix: open apps in same window
@d-rita d-rita requested review from cooper-joe and a team February 20, 2025 14:15
@d-rita d-rita requested a review from a team as a code owner February 20, 2025 14:15
@dhis2-bot
Copy link
Contributor

dhis2-bot commented Feb 20, 2025

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

@dhis2-bot dhis2-bot temporarily deployed to netlify February 20, 2025 14:19 Inactive
Copy link
Member

@amcgee amcgee left a comment

Choose a reason for hiding this comment

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

Made a few code cleanup suggestions - using useMemo is better than useEffect here because it avoids an additional re-render

Comment on lines 84 to 89
const apps = itemsArray?.filter((item) => item.type === APP)
const expectedGridSize = gridColumns * gridRows
const appsGridSize =
apps.length >= expectedGridSize
? expectedGridSize
: apps.length
Copy link
Member

Choose a reason for hiding this comment

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

This logic is repeated, perhaps it should be refactored or passed as an argument directly?

Comment on lines 40 to 69
useEffect(() => {
const columns =
gridLayout === 'desktop'
? GRID_COLUMNS_DESKTOP
: GRID_COLUMNS_MOBILE
const rows =
gridLayout === 'desktop' ? GRID_ROWS_DESKTOP : GRID_ROWS_MOBILE

const expectedGridSize = rows * columns
const availableApps =
apps?.length >= expectedGridSize ? expectedGridSize : apps.length

if (availableApps && availableApps < expectedGridSize) {
if (availableApps / columns < 1) {
setGridColumns(availableApps)
setGridRows(1)
} else {
if (availableApps % columns === 0) {
setGridColumns(columns)
setGridRows(availableApps / columns)
} else {
setGridColumns(columns)
setGridRows(Math.trunc(availableApps / columns + 1))
}
}
} else {
setGridColumns(columns)
setGridRows(rows)
}
}, [apps, gridLayout])
Copy link
Member

Choose a reason for hiding this comment

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

I think this can all be rewritten as a single useMemo instead of 2 additional state variables - the function takes apps and gridLayout (maybe with a different name?) and returns an object { rows: x, columns: y }

Then call it with a useMemo:

const rowsAndColumns = useMemo(() => getRowsAndColumns(apps, gridLayout), [apps, gridLayout])

Copy link
Member

Choose a reason for hiding this comment

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

I feel like gridLayout is actually a good name for the full rows/columns/totalCount object and maybe what's currently called gridLayout should instead be something like formFactor or isMobile or something? Not a huge issue

Copy link
Member

Choose a reason for hiding this comment

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

It might make sense to have a Grid class instead of a bunch of helper functions?

@dhis2-bot dhis2-bot temporarily deployed to netlify February 20, 2025 14:28 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify February 20, 2025 21:04 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify February 21, 2025 21:03 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify February 21, 2025 21:08 Inactive
Base automatically changed from refactor/modal-navigation to feature-command-palette February 24, 2025 15:12
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.

4 participants