-
Notifications
You must be signed in to change notification settings - Fork 5
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
Feature/improve sorting ux #1541 #1578
Merged
Merged
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
70a8178
Added shift+click sorting #1541
kaperoo d1294dd
Code cleanup #1541
kaperoo 88d2702
Sorting unit test fix #1541
kaperoo a28a6bd
Shift-click sorting for download tables #1541
kaperoo e03740d
Fixed sorting in card view #1541
kaperoo 374c857
changed the way shift is passed to onSort #1541
kaperoo 0586bd4
Fix issues with download e2e tests #1541
kaperoo ca20c22
changed the way shiftDown is passed in cardview #1541
kaperoo 52d0395
fix to the single column sort test in admin download #1541
kaperoo 72be066
Fixed dataview e2e tests #1541
kaperoo e94c94a
Fix dataview e2e tests 2 #1541
kaperoo 76f26b8
Improved code coverage #1541
kaperoo f86c192
Merge branch 'develop' into feature/improve-sorting-ux-#1541
kaperoo 79e4336
Adjusted + added e2e tests for multiple column sorting #1541
kaperoo 77f3972
fix e2e test for adminDownloadDtatus #1541
kaperoo c6bd356
Merge branch 'develop' into feature/improve-sorting-ux-#1541
kaperoo be9ef8b
Reduce code repetition
kaperoo c9162f3
add hover tooltips to sort indicators
kaperoo 7553763
Hopefully fixed failing tests
kaperoo 7492fb3
updated snapshots
kaperoo 95cf7fc
fix failing e2e test
kaperoo b6bca39
#1541 - use skipHover to avoid triggering sort tooltips in long tests
louise-davies 0043575
Merge branch 'feature/improve-sorting-ux-#1541' of https://github.com…
louise-davies 7fe8811
use skipHover to fix another test #1541
kaperoo 848d799
#1541 - add delay null to downloadStatusTable userEvent
louise-davies File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ import React from 'react'; | |
import { useTranslation } from 'react-i18next'; | ||
import AdvancedFilter from './advancedFilter.component'; | ||
import EntityCard, { EntityImageDetails } from './entityCard.component'; | ||
import AddIcon from '@mui/icons-material/Add'; | ||
|
||
const SelectedChips = styled('ul')(({ theme }) => ({ | ||
display: 'inline-flex', | ||
|
@@ -85,7 +86,8 @@ export interface CardViewProps { | |
onSort: ( | ||
sort: string, | ||
order: Order | null, | ||
updateMethod: UpdateMethod | ||
updateMethod: UpdateMethod, | ||
shiftDown?: boolean | ||
) => void; | ||
|
||
// Props to get title, description of the card | ||
|
@@ -189,6 +191,30 @@ const CardView = (props: CardViewProps): React.ReactElement => { | |
sort, | ||
} = props; | ||
|
||
const [shiftDown, setShiftDown] = React.useState(false); | ||
// add event listener to listen for shift key being pressed | ||
React.useEffect(() => { | ||
const handleKeyDown = (event: KeyboardEvent): void => { | ||
if (event.key === 'Shift') { | ||
setShiftDown(true); | ||
} | ||
}; | ||
|
||
const handleKeyUp = (event: KeyboardEvent): void => { | ||
if (event.key === 'Shift') { | ||
setShiftDown(false); | ||
} | ||
}; | ||
|
||
document.addEventListener('keydown', handleKeyDown); | ||
document.addEventListener('keyup', handleKeyUp); | ||
|
||
return (): void => { | ||
document.removeEventListener('keydown', handleKeyDown); | ||
document.removeEventListener('keyup', handleKeyUp); | ||
}; | ||
}, []); | ||
|
||
// Results options (by default it is 10, 20 and 30). | ||
const resOptions = React.useMemo( | ||
() => | ||
|
@@ -233,20 +259,20 @@ const CardView = (props: CardViewProps): React.ReactElement => { | |
//defaultSort has been provided | ||
React.useEffect(() => { | ||
if (title.defaultSort !== undefined && sort[title.dataKey] === undefined) | ||
onSort(title.dataKey, title.defaultSort, 'replace'); | ||
onSort(title.dataKey, title.defaultSort, 'replace', false); | ||
if ( | ||
description && | ||
description.defaultSort !== undefined && | ||
sort[description.dataKey] === undefined | ||
) | ||
onSort(description.dataKey, description.defaultSort, 'replace'); | ||
onSort(description.dataKey, description.defaultSort, 'replace', false); | ||
if (information) { | ||
information.forEach((element: CardViewDetails) => { | ||
if ( | ||
element.defaultSort !== undefined && | ||
sort[element.dataKey] === undefined | ||
) | ||
onSort(element.dataKey, element.defaultSort, 'replace'); | ||
onSort(element.dataKey, element.defaultSort, 'replace', false); | ||
}); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
|
@@ -593,11 +619,12 @@ const CardView = (props: CardViewProps): React.ReactElement => { | |
<ListItem | ||
key={i} | ||
button | ||
onClick={() => { | ||
onClick={(event) => { | ||
onSort( | ||
s.dataKey, | ||
nextSortDirection(s.dataKey), | ||
'push' | ||
'push', | ||
event.shiftKey | ||
); | ||
if (page !== 1) { | ||
onPageChange(1); | ||
|
@@ -615,14 +642,35 @@ const CardView = (props: CardViewProps): React.ReactElement => { | |
> | ||
<ListItemText primary={s.label} /> | ||
<ListItemIcon> | ||
<TableSortLabel | ||
active={s.dataKey in sort} | ||
direction={sort[s.dataKey]} | ||
// Set tabindex to -1 to prevent button focus | ||
tabIndex={-1} | ||
> | ||
{s.dataKey in sort && sort[s.dataKey]} | ||
</TableSortLabel> | ||
{s.dataKey in sort ? ( | ||
<TableSortLabel | ||
active={true} | ||
direction={sort[s.dataKey]} | ||
// Set tabindex to -1 to prevent button focus | ||
tabIndex={-1} | ||
> | ||
{s.dataKey in sort && sort[s.dataKey]} | ||
</TableSortLabel> | ||
) : shiftDown ? ( | ||
<TableSortLabel | ||
active={true} | ||
direction={sort[s.dataKey]} | ||
// Set tabindex to -1 to prevent button focus | ||
tabIndex={-1} | ||
IconComponent={AddIcon} | ||
> | ||
{s.dataKey in sort && sort[s.dataKey]} | ||
</TableSortLabel> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could simply & reduce code repetition here by removing the ternary checks and changing
|
||
) : ( | ||
<TableSortLabel | ||
active={false} | ||
direction={sort[s.dataKey]} | ||
// Set tabindex to -1 to prevent button focus | ||
tabIndex={-1} | ||
> | ||
{s.dataKey in sort && sort[s.dataKey]} | ||
</TableSortLabel> | ||
)} | ||
</ListItemIcon> | ||
</ListItem> | ||
))} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Minor comment, but since you specified
shiftDown?: boolean
as optional, you could leave out explicitly specifyingfalse
here. Would have meant less changes in the tests - but no point removing it now, just an observation