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

Refactor table sort properties #11073

Merged

Conversation

stacey-gammon
Copy link
Contributor

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.

Copy link
Contributor

@cjcenizal cjcenizal left a 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();
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Cool!

@cjcenizal
Copy link
Contributor

cjcenizal commented Apr 6, 2017

BTW, I think at some point we should add a ui_framework/services directory, which will house non-visual yet UI-specific logic like sort_properties.js. This will help codify the behavior of our components. As an added benefit, we can write the tests for these services in Jest and they'll be part of our coverage report.

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?

@stacey-gammon
Copy link
Contributor Author

I love that idea, happy to move it over. Was struggling with where to put that kind of logic. ++

@stacey-gammon
Copy link
Contributor Author

@cjcenizal, ready to go for look two, with tests and the new folder location!

Copy link
Contributor

@cjcenizal cjcenizal left a 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', () => {
Copy link
Contributor

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

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';
Copy link
Contributor

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?

Copy link
Contributor Author

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. ✅

@stacey-gammon stacey-gammon force-pushed the refactor-landing-page-sorting branch 2 times, most recently from d629e72 to edfc938 Compare April 10, 2017 11:13
- add tests
- address code review feedback
- Include new folders in build output.
Require initial sorted property name.
@stacey-gammon
Copy link
Contributor Author

Just ran into this again #11040:

>> FAIL: chrome on any platform - kibana - settings app - creating and using Painless boolean scripted fields - should visualize scripted field in vertical bar chart (3706ms)
Error: expected [ 'true 359' ] to sort of equal [ 'true 359', 'false 27' ]

  [
    0: "true 359",
E   1: "false 27",
E   length: 2
A   length: 1
  ]

Jenkins, test this

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

LGTM!

@stacey-gammon stacey-gammon merged commit 8eb17b3 into elastic:master Apr 11, 2017
stacey-gammon added a commit to stacey-gammon/kibana that referenced this pull request Apr 12, 2017
* 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
stacey-gammon added a commit to stacey-gammon/kibana that referenced this pull request Apr 12, 2017
* 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
stacey-gammon added a commit to stacey-gammon/kibana that referenced this pull request Apr 12, 2017
* 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
stacey-gammon added a commit that referenced this pull request Apr 13, 2017
* 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
@stacey-gammon stacey-gammon deleted the refactor-landing-page-sorting branch April 13, 2017 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Dashboard Dashboard related features review v5.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants