-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Refactor table sort properties #11073
Refactor table sort properties #11073
Conversation
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.
Awesome! Just had a couple requests.
@@ -60,6 +60,15 @@ export function VisualizeListingController($injector, $scope) { | |||
selectedItems = this.pageOfItems.slice(0); | |||
}; | |||
|
|||
this.isAscending = () => sortProperties.isAscending(); |
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 future-proofing this a bit by changing it so that it accepts a property name and returns the ascending value of that SortProperty. The only reason this currently works from a UI perspective is because the sort arrow gets hidden if a column isn't being sorted on. If we ever decide to show that arrow for columns that aren't being sorted on (e.g. maybe we show it on hover), then the direction would be incorrect.
* Stores sort information for a set of SortProperties, including which property is currently being sorted on, as | ||
* well as the last sort order for each property. | ||
*/ | ||
export class SortProperties { |
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.
Can we add tests for this file? Should be pretty straightforward.
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.
Whoa I could have sworn I added a comment that said I was going to add tests as soon as you approved of the general direction. :) Just wanted to make sure we were on the same page first, in case there was conflict and the pr got scrapped.
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.
👍 Cool!
BTW, I think at some point we should add a For reference, here is a similar thing I did with the UI framework at my previous job: https://github.com/smaato/ui-framework/tree/develop/src/framework/services. It contained services for sorting, filtering, scrolling, handling key input, and humanizing numbers. There was also a test utility which looks very similar to something you wrote in another PR. 😄 In fact, if you're planning on writing tests, maybe we should create this directory as part of this PR, so we don't have to rewrite the tests later? |
I love that idea, happy to move it over. Was struggling with where to put that kind of logic. ++ |
@cjcenizal, ready to go for look two, with tests and the new folder location! |
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.
Hahaha sweeeeet!!!! It's so cool seeing these tests included in the coverage report. I just had a couple suggestions.
expect(new SortProperties([name, size, color], 'does not exist')).toThrow(); | ||
}); | ||
|
||
test('is optional', () => { |
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.
Maybe this shouldn't be optional. Should we throw an error if it isn't supplied? I think we always want to set a default sort for anything that can be sorted.
let sortedItems = sortProperties.sortItems(birds); | ||
expect(sortedItems[0].size).toBe(8); | ||
expect(sortedItems[1].size).toBe(7); | ||
expect(sortedItems[2].size).toBe(3); |
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 don't think we need these first three assertions since they're already covered by the preceding test.
@@ -1,7 +1,8 @@ | |||
import SavedObjectRegistryProvider from 'ui/saved_objects/saved_object_registry'; | |||
import 'ui/pager_control'; | |||
import 'ui/pager'; | |||
import _ from 'lodash'; | |||
|
|||
import { SortProperties } from 'ui_framework/services'; |
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 we're going to find ourselves with a lot of services that are standalone functions, which will all have verb-based names. Since "sort" is also a verb, I think this name is a bit ambiguous. How about renaming it to SortableProperties
?
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.
good point, sortableProperties is more accurate. ✅
d629e72
to
edfc938
Compare
- add tests - address code review feedback - Include new folders in build output.
Require initial sorted property name.
edfc938
to
d91df10
Compare
Just ran into this again #11040:
Jenkins, test this |
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.
LGTM!
* Refactor sorting capabilities * clean up and comments * Move to ui_framework/services - add tests - address code review feedback - Include new folders in build output. * Rename to sortableProperties Require initial sorted property name. * fix a refactor miss
* Refactor sorting capabilities * clean up and comments * Move to ui_framework/services - add tests - address code review feedback - Include new folders in build output. * Rename to sortableProperties Require initial sorted property name. * fix a refactor miss
* Refactor sorting capabilities * clean up and comments * Move to ui_framework/services - add tests - address code review feedback - Include new folders in build output. * Rename to sortableProperties Require initial sorted property name. * fix a refactor miss
* Refactor sorting capabilities * clean up and comments * Move to ui_framework/services - add tests - address code review feedback - Include new folders in build output. * Rename to sortableProperties Require initial sorted property name. * fix a refactor miss
Pushes common sort logic from visualize and dashboard landing pages into a common file. I want to add a new column to dashboard, and currently the logic is not in place for it to sort on multiple columns - the logic assumes only one column. So I tackled this refactor first.