-
Notifications
You must be signed in to change notification settings - Fork 78
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(table): add multi-sort columns to table #2336
Conversation
✔️ Deploy Preview for ai-apps-pal-angular ready! 🔨 Explore the source changes: e383c54 🔍 Inspect the deploy log: https://app.netlify.com/sites/ai-apps-pal-angular/deploys/60ca03e0aa98ed0008d45666 😎 Browse the preview: https://deploy-preview-2336--ai-apps-pal-angular.netlify.app |
✔️ Deploy Preview for carbon-addons-iot-react ready! 🔨 Explore the source changes: e383c54 🔍 Inspect the deploy log: https://app.netlify.com/sites/carbon-addons-iot-react/deploys/60ca03e0c2b7290007ff12ee 😎 Browse the preview: https://deploy-preview-2336--carbon-addons-iot-react.netlify.app/iframe |
sort.forEach(({ columnId, direction }) => { | ||
const customSortFn = getCustomColumnSort(columns, columnId); | ||
if (customSortFn) { | ||
const sortedValues = customSortFn({ data: searchedData, columnId, direction }).map( |
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.
I think it's worth discussing a breaking change in V3 here, so that the customSort function is just a comparator instead of a method that takes the data, column, and direction. It would be much easier (and more efficient) to handle sorting related issues without having to maintain this backwards compatibility. Unless this method was chosen for a specific reason that I'm unaware of.
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.
Don't know, here is the old PR for that so you can have a look
#843
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.
I think it was a functions so you can sort things that are not comparable like an error icon.
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.
🤔 Wouldn't that still be possible with a comparator? They can use the renderDataFunction
to render the icon, and then sortFunction
could still just be a comparator as used here. It seems like the only thing the full function is accomplishing to me is cloning to not mutate the original array.
…em/carbon-addons-iot-react into 1376-table-multi-sort
packages/react/src/components/Table/TableMultiSortModal/TableMultiSortModal.jsx
Show resolved
Hide resolved
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.
The choice to use an overflow that pops up a dialog seems like an odd behaviour (but, I see that is coming straight from PAL, so I guess that is good). At the very least, IF I have to select the triple dot menu and select multi-sort, then it should open the dialog and configure the entry such that it selects the column that opened the dialog, so that all I need to do is press +. If existing sorts exist, and I click the triple dot on a column that is not already sorted then it should add a new row and set that selected column in the dropdown.
I see a couple of behavioural issues that PAL design does not address.
1). It would seem that once I create a sort, then clicking a table column will remove ALL sorts. This does not feel right. I would expect that clicking a table column that is sorted would just invert the sort of that table column, and not remove all the sorts from the table. Perhaps if I clicked a table column that is NOT sorted it might remove all other sorts, although I expect that customers would likely expect that action to just add another sorted column automatically.
2). The modal should allow the sorted columns to be reordered.
3). The modal should have a clear/remove all option, no?
@lukefirth do you have any comments on the behaviours here?
@dianatran18 do you have any feedback for @stuckless comments above? |
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.
Modal in RTL is not correct. X is in the wrong location and the input components are not aligned correctly.
If I add more than 4 items it blows out of the dialog.
On a small screen if I open the dropdown in the dialog I can't select all the items, and keyboard navigation appears to now work either. Not sure if it's a dropdown issue or a dialog issue.
@@ -153,6 +153,7 @@ | |||
"react-visibility-sensor": "^5.0.2", | |||
"scroll-into-view-if-needed": "^2.2.26", | |||
"styled-components": "^4.1.3", | |||
"thenby": "^1.3.4", |
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.
do we really need a new 28k library to just sort data?
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.
It's only 28K unpacked. It's a 2K module, and yeah, it simplifies the experience significantly when sorting in various directions and orders.
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.
I would be very conservative about adding new libraries. I'm not saying, don't, but you should verify that this library is "blessed". ie, it in the IBM open source list of approved libraries (you can check the wicked system). When you add a new library, it has to get legal approval eventually. That is why I question importing a library to do a sorting, when that seems pretty trivial.
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.
our OM is looking into what is happening with our code scans we are supposed to have for teams to use. We will hopefully have an answer soon on when we can expect them.
packages/react/src/components/Table/TableMultiSortModal/TableMultiSortModal.jsx
Outdated
Show resolved
Hide resolved
I can provide some feedback, but just a note that the pattern defined here was from the original EDS/IoT PAL, so I wasn't involved in the original pattern/nor have I thoroughly looked into the multi-sort pattern myself.
I briefly spoke with the the PAL team on this, and I think it's fine that if you click to sort on an already sorted column, it would invert the sort, and not remove all sorts from the table. And agreed that if you clicked on a column that is not already sorted, then it would remove all other sorts.
Again I'm not deeply familiar with the pattern defined, but these statements make sense to me. I'm fine moving forward with this so we can close this out, but I would ask that the teams that will be implementing this in their products to get feedback on their users on what the expected behavior is for everything listed above. |
@stuckless @dianatran18
I've fixed the alignment, but the X we will tackle with another issue, as that's in the ComposedModal component not directly related to this feature. #2396
This has been addressed. We had to resort to using
Keyboard navigation was working, but the modal wasn't grabbing focus, so you had to tab through all the items on the table in the background to get to the modal. The save button now grabs focus when the modal opens, so keyboard navigation is easier. I also added testIds to the select menus and to the modal itself. Clicking on the sort button (for a column that's selected for multi-sort) will now invert the sort for that column, but clicking sort on a new column not included in multi-sort will reset the sort and only use that single column. The modal window now also has a "Clear sorting" button to wipe it all out. |
Hey @stuckless. Since design is going to revisit this pattern and make some further recommendations we have tried to make as many of your suggested changes as possible and for the ones we did not address I have created an issue for design to look into and verify.
Added to issue for design discussion
Kevin has addressed in this PR by having it sort in place if part of multi sort. For now non members of multi-sort will clear sort and add the simple sort.
Added to issue for design discussion
This seems like a no brainer but is not part of the initial spec so we have opened another issue to track this enhancement.
This was added to this PR I believe these actions and future work of issue mentioned will address most of your comments. Can you give this another look? Thanks and thanks for the feature comments. |
@stuckless Friendly bump on the updates to this PR. Can you give it another look now with @davidicus's #2336 (comment) in mind? |
Closes #1376
Summary
Adds the ability to multi-sort columns within a table. A new
option.hasMultiSort
prop is added. Theview.table.sort
prop now accepts both a single sort objects{ columnId: string; direction: 'ASC' | 'DESC' | 'NONE' }
or an array of sort objects. The order of this array determines the order the multi-sort is applied to the table. There are new callback actions for interacting with the multi-sort column data:onSaveMultiSortColumns
,onCancelMultiSortColumns
,onAddMultiSortColumn
, andonRemoveMultiSortColumn
.Change List (commits, features, bugs, etc)
Acceptance Test (how to verify the PR)
Regression Test (how to make sure this PR doesn't break old functionality)