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

Feature/improve sorting ux #1541 #1578

Merged
merged 25 commits into from
Oct 25, 2023
Merged

Conversation

kaperoo
Copy link
Contributor

@kaperoo kaperoo commented Sep 1, 2023

Improved sorting UX

This PR implements improved sorting UX.
Changes/ New features:

  • Each sortable (but not sorted) column now has an 'SortIcon' icon so users know it is clickable.

  • When shift key is pressed (for multi sort), all Sort Icons change to Add Icons
    2023-09-11-16-04-50

  • Single column sort is now the default
    single sort

  • Multi column sort is applied when columns are clicked with shift key down
    2023-09-11-16-22-20

  • Sorting in the card view works in a similar way to table view, except it doesn't display 'SortIcon' (please let me know if it should).
    2023-09-11-16-29-44

Testing instructions

Had to modify multiple existing unit and e2e tests to account for new way of multi column sorting.
Additionally, added tests checking for icon changes.

Agile board tracking

connect to #1541

@kaperoo kaperoo linked an issue Sep 1, 2023 that may be closed by this pull request
3 tasks
@codecov
Copy link

codecov bot commented Sep 1, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (48e434d) 96.19% compared to head (848d799) 96.26%.
Report is 17 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1578      +/-   ##
===========================================
+ Coverage    96.19%   96.26%   +0.06%     
===========================================
  Files          161      161              
  Lines         6863     6989     +126     
  Branches      2135     2179      +44     
===========================================
+ Hits          6602     6728     +126     
  Misses         240      240              
  Partials        21       21              
Flag Coverage Δ
common 95.61% <100.00%> (+0.09%) ⬆️
dataview 96.94% <ø> (+0.08%) ⬆️
download 96.34% <100.00%> (+0.02%) ⬆️
search 96.47% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
packages/datagateway-common/src/api/index.tsx 96.73% <100.00%> (+0.02%) ⬆️
...datagateway-common/src/card/cardView.component.tsx 71.62% <100.00%> (+2.35%) ⬆️
...src/table/headerRenderers/dataHeader.component.tsx 97.56% <100.00%> (+1.56%) ⬆️
...s/datagateway-common/src/table/table.component.tsx 94.69% <100.00%> (+0.57%) ⬆️
...d/src/downloadCart/downloadCartTable.component.tsx 94.52% <100.00%> (+0.07%) ⬆️
...nloadStatus/adminDownloadStatusTable.component.tsx 99.32% <100.00%> (+<0.01%) ⬆️
...c/downloadStatus/downloadStatusTable.component.tsx 94.70% <100.00%> (+0.07%) ⬆️

... and 26 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kaperoo kaperoo marked this pull request as ready for review September 12, 2023 08:22
@louise-davies
Copy link
Member

@kevinphippsstfc do you have any thoughts about the sort icon?

@@ -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);
Copy link
Member

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 specifying false here. Would have meant less changes in the tests - but no point removing it now, just an observation

Comment on lines 646 to 663
<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>
Copy link
Member

Choose a reason for hiding this comment

The 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 to:

<TableSortLabel
   active={s.dataKey in sort}
   direction={sort[s.dataKey]}
   // Set tabindex to -1 to prevent button focus
   tabIndex={-1}
   IconComponent={!(s.dataKey in sort) && shiftDown ? AddIcon : undefined}
>
   {s.dataKey in sort && sort[s.dataKey]}
</TableSortLabel>

Comment on lines 75 to 103
dataKey in sort ? (
<TableSortLabel
className={'tour-dataview-sort'}
active={true}
direction={currSortDirection}
onClick={(event) =>
onSort(dataKey, nextSortDirection, 'push', event.shiftKey)
}
>
<Typography noWrap sx={{ fontSize: 'inherit', lineHeight: 'inherit' }}>
{label}
</Typography>
</TableSortLabel>
) : (
<TableSortLabel
className={'tour-dataview-sort'}
active={true}
direction={'desc'}
onClick={(event) => {
onSort(dataKey, nextSortDirection, 'push', event.shiftKey);
setHover(false);
}}
onMouseEnter={() => setHover(true)}
onMouseLeave={() => setHover(false)}
IconComponent={hover ? ArrowUpwardIcon : shiftDown ? AddIcon : SortIcon}
sx={{
transition: 'opacity 0.5s',
opacity: hover ? 0.7 : 1,
}}
Copy link
Member

Choose a reason for hiding this comment

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

Again, some code repetition here. We can reduce this by only adding the extra props when dataKey in sort is false, e.g.

<TableSortLabel
  className={'tour-dataview-sort'}
  active={true}
  direction={!(dataKey in sort) ? 'desc' : currSortDirection}
  onClick={(event) => {
    onSort(dataKey, nextSortDirection, 'push', event.shiftKey);
    if (!(dataKey in sort)) setHover(false);
  }}
  {...(!(dataKey in sort)
    ? {
        onMouseEnter: () => setHover(true),
        onMouseLeave: () => setHover(false),
        IconComponent: hover
          ? ArrowUpwardIcon
          : shiftDown
          ? AddIcon
          : SortIcon,
        sx: {
          transition: 'opacity 0.5s',
          opacity: hover ? 0.7 : 1,
        },
      }
    : {})}
>
  <Typography noWrap sx={{ fontSize: 'inherit', lineHeight: 'inherit' }}>
    {label}
  </Typography>
</TableSortLabel>

Copy link
Member

@louise-davies louise-davies left a comment

Choose a reason for hiding this comment

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

Works well, just some minor code styling comments. I like that pressing shift changes the sort buttons to add buttons to represent the different action possible :)

Copy link
Member

@louise-davies louise-davies left a comment

Choose a reason for hiding this comment

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

Comments have been addressed - just want to wait for @kevinphippsstfc to take a look before we merge

Copy link
Member

@louise-davies louise-davies left a comment

Choose a reason for hiding this comment

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

Kevin suggested we add hover tooltips to the sort indicators to be explicit that they're prompting the users to sort :)

@kaperoo
Copy link
Contributor Author

kaperoo commented Oct 11, 2023

Added requested hover tooltips to sort indicators.

When hovered:
image

When hovered with shift down:
image

Let me know if the tooltips should be more descriptive (i.e. "Sort asc") :)

Copy link
Member

@louise-davies louise-davies left a comment

Choose a reason for hiding this comment

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

LGTM and Kevin was happy with the UI & the tooltips are working well

@kaperoo kaperoo merged commit 6923aca into develop Oct 25, 2023
9 checks passed
@louise-davies louise-davies deleted the feature/improve-sorting-ux-#1541 branch November 3, 2023 10:37
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.

Improve sorting UX
2 participants