-
Notifications
You must be signed in to change notification settings - Fork 17
7093 add sort toggle to prevent report filter dropdowns overlapping #7406
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
7093 add sort toggle to prevent report filter dropdowns overlapping #7406
Conversation
Bundle size differenceComparing this PR to
|
sortDirection === value ? selectedStyles : undefined; | ||
|
||
const handleClick = (value: SortDirection) => { | ||
const newValue = sortDirection === value ? null : value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line with newValue
ensures that only one button can be selected at a time - deselecting the button if itβs already selected, or selecting it if itβs not. This is what the MUI ToggleButton propexclusive
achieves, whilst using common components we already have
<> | ||
<FlatButton | ||
label={t('report.ascending')} | ||
onClick={() => handleClick('asc')} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing in 'asc' as the value, as FlatButton does not have a value attribute. Works in this scenario where only two options exist
return null; | ||
} | ||
|
||
const selectedStyles = (theme: Theme) => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
custom styling for when the button is the selected option
@@ -26,8 +26,8 @@ | |||
}, | |||
"dir": { | |||
"description": "sort by dir", | |||
"type": "string", | |||
"enum": ["asc", "desc"] | |||
"type": ["string", "null"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Included 'null' here to prevent console errors when deselecting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -35,8 +35,8 @@ | |||
}, | |||
"dir": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tangentially I find it funny that we shorten this to dir, meanwhile having properties like "monthlyConsumptionLookBackPeriod". Also just curious is the "description" just for documenting in this JSON or is it shown somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that is quite a difference between the property names! It's not immediately obvious (at least to me) what 'dir' represents. I'd be happy to update that to 'direction'
The description is used for internal/documentation only atm, though it looks like another use case is for a Tooltip
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly the reason I even commented is it took me a second too - I was like wait directory
?
Nah maybe a refactor issue if anything heh.
Yea I thought description might be a tool tip, but then it'd need localisation! Maybe it should be regardless, but the use case isn't really obvious heh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Chris, I have raised in #7546
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. If I could request thinking about one thing, it's that this is pretty hard coded to the sorting use case. A more generic and flexible component could probably be made of this (perhaps in the future)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for bringing that up, I should have covered that in the PR!
I did consider this when creating it, and went with the most straight forward solution to fix the issue. With sorting direction only having two possible options, and without another use case in mind, it made sense to me to hardcode for this case
There is an existing forms pattern with 'options' like in the 'sort-by' dropdown below - to make that pattern work for a flexible toggle button setup it would need at least:
- logic in the toggle component to get the icon and render to correct icon/label pairing
- logic to get and set the 'value' as it is not built in to the FlatButton
- considerations for control over the number of options that could theoretically be added and/or new logic plus styling if able to add more than two (more like a multi-select)
open-msupply/standard_reports/item-usage/latest/argument_schemas/arguments_ui.json
Lines 31 to 46 in 35917ab
"options": { | |
"show": [ | |
["name", "T#report.item-name"], | |
["code", "T#label.code"], | |
["SOH", "T#report.stock-on-hand"], | |
["MOS", "T#report.months-cover"], | |
["monthConsumption", "T#report.consumption-month"], | |
["lastMonthConsumption", "T#report.consumption-last-month"], | |
["twoMonthsAgoConsumption", "T#report.consumption-two-months-ago"], | |
["expiringInSixMonths", "T#report.expiring-6-months"], | |
["expiringInTwelveMonths", "T#report.expiring-12-months"], | |
["stockOnOrder", "T#report.stock-on-order"], | |
["AMC12", "T#report.amc-12-months"], | |
["AMC24", "T#report.amc-24-months"] | |
] | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea with 1-3 short options (especially if icons and no text) toggle is good, <=~5 radio buttons (especially if text) and beyond that is combobox.
Sorting should be consistent now - it was a gotcha with state. Thanks for picking up on that! |
β¦msupply into 7093-report-filter-dropdowns-overlapping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed woo thanks
@@ -38,7 +38,7 @@ const UIComponent = (props: ControlProps) => { | |||
const handleClick = (value: SortDirection) => { | |||
const newValue = sortDirection === value ? null : value; | |||
setSortDirection(newValue); | |||
handleChange(path, sortDirection); | |||
handleChange(path, newValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh hahahaha ya that'd do it
Fixes #7093
π©π»βπ» What does this PR do?
Replaced the Sort Direction dropdown selection in report arguments with a new SortToggle component (Json forms component), which displays buttons for Ascending and Descending sorting

With some testing the original issue was found to be due to android defaults in relation to the keyboard:
When the keyboard is closed whilst a dropdown is open, the dropdown direction goes down. Then selecting another dropdown, the keyboard goes up. The dorwdowns then seen to get confused with the direction changes and overlap.
Rather than changing default behaviour of keyboards or dropdowns, I thought it would be a nicer user experience to have buttons for the sorting direction - it will only be one of two options, and is easier for the user to access. This also solves the overlapping - if there aren't two dropdowns next to each other, they can't overlap.
The selection behaviour is done through state, and selecting an already selected button will unselect it. I looked into the MUI ToggleButton as they use an
exclusive
prop - however didn't see any benefit to creating this component when they also used state to manage this.First go at the styling - can have another pass with suggestions. I used the flat button so it didn't visually compete with the dialog buttons, and as it is not performing an action visible immediately to the user that made more sense to me.
π Any notes for the reviewer?
This issue could still arise in the future if more dropdown fields are added to report arguments
This icon is the existing one for sorting (used in table headers). MUI doesn't have an icon in a similar design to the one suggested by Roxy - this could be looked at in future to either create custom SVGs or import icons from elsewhere
This icon also does not take a color - black and white only (Unless I missed something there).
The more I looked the more inconsistencies I found in the form alignments π’
π§ͺ Testing
cargo build
then run./target/debug/remote_server_cli build-reports && ./target/debug/remote_server_cli upsert-reports -o
π Documentation
π Reviewer Checklist
The PR Reviewer(s) should fill out this section before approving the PR
Breaking Changes
Issue Review
Tests Pass