Skip to content
This repository has been archived by the owner on Feb 2, 2019. It is now read-only.

feat(data-table): Add Column Sorting #261

Closed
wants to merge 1 commit into from

Conversation

ollwenjones
Copy link
Collaborator

Add column sorting via an attribute directive which styles its host,
subsribes to and calls method on a service with an observable model.

Closes #144

I struggled initially in terms of where the sorting model / event listener should be housed, but decided on a service (rather than row or table component) since it allowed simplest implementation, and greatest flexibility for the user in terms of how/where they would like to listen to the column sorting changes.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 33c1c32 on feature/data-table-column-sort into * on master*.

@@ -0,0 +1,18 @@
/*
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

should file be named column-sort.d.ts ?

Copy link
Owner

Choose a reason for hiding this comment

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

It looks like it could be but I don't think it should be. We don't have .d.ts files anywhere else except at the root.

Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO, it should be a part of service file. If you separate type and interface in several files, it will never ending.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Like a java project where each interface is in its own file? I feel like I saw a pattern somewhere with type definitions in their own files, but I can't recall where now. I think it's better practice to separate things out, but it's also more consistent with existing code-base to keep them together.

@justindujardin
Copy link
Owner

A few style things from trying the demo:

  • the first column that is left aligned should have the sort arrow on the right of the text
  • the column labels should not shift left/right when toggling between sorting on different columns

@ollwenjones
Copy link
Collaborator Author

the first column that is left aligned should have the sort arrow on the right of the text

Didn't see that in the spec, but it sounds right now that you say it. I'll add a rule for that.

the column labels should not shift left/right when toggling between sorting on different columns

I noticed that, but I wasn't sure how to avoid it without having to style the column widths... it's really the table re-flowing to make the column wider based on the content width changing, not the labels shifting per se. Open to suggestions.

@ollwenjones
Copy link
Collaborator Author

ollwenjones commented Jun 14, 2016

it's really the table re-flowing to make the column wider

Actually I can just add an empty block there so title size stays consistent. nm

@ollwenjones ollwenjones force-pushed the feature/data-table-column-sort branch from 33c1c32 to cbc74b2 Compare June 14, 2016 16:25
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling cbc74b2 on feature/data-table-column-sort into * on master*.

@ollwenjones
Copy link
Collaborator Author

I copy pasted some code and didn't use the cli for it, so I just realized it doesn't have that sanity check unit test... let me know if I need to add it in, but it sounded like they aren't even being run?

@ollwenjones ollwenjones force-pushed the feature/data-table-column-sort branch from cbc74b2 to 0acc3ed Compare June 14, 2016 18:59
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 0acc3ed on feature/data-table-column-sort into * on master*.

private colIdMap

constructor(private sortingService: MdDataColumnSortingService) {
this.colSortChanges$ = this.sortingService.sortingColumn$.subscribe((col) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

the $ suffix doesn't seems to be in angular styleguide

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

$ suffix is kind of standard indicator that a value is an Observable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree but not for Angular styleguide

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

doesn't seem to be in

is precisely true. It does not seem to have an opinion about it. 😉

@ollwenjones
Copy link
Collaborator Author

Thanks @justindujardin and @Gregcop1 for making time to review this. 👍

@ollwenjones ollwenjones force-pushed the feature/data-table-column-sort branch 3 times, most recently from a374213 to a7f5f81 Compare June 16, 2016 18:27
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling a7f5f81 on feature/data-table-column-sort into * on master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling a7f5f81 on feature/data-table-column-sort into * on master*.

@coveralls
Copy link

coveralls commented Jun 16, 2016

Coverage Status

Changes Unknown when pulling a7f5f81 on feature/data-table-column-sort into * on master*.

* @param sorting column & direction to sort by.
*/
public setSorting(sorting: ColumnSortingModel) {
this.sortingColumn$.next(sorting);

Choose a reason for hiding this comment

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

is the $ ok ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's conventional way indicate a var is an observable... but I'll probably have to take it out, because it's not really a convention followed in the code-base so far.

@ollwenjones
Copy link
Collaborator Author

@Gregcop1 @justindujardin What do we say about this, merge ready? Get rid of the $ var names? Make the unit test more like the others?

@Gregcop1
Copy link
Collaborator

Gregcop1 commented Jul 8, 2016

IMO, we have to get rid of $ prefix and stick to other components tests format

@ollwenjones
Copy link
Collaborator Author

@Gregcop1 I'll take out the $ for consistency with existing code - but I would like to understand the reason for the other test format's complexity. The testing API has changed so much since this got started. I don't want to perpetuate doing things "the hard way" if it is no longer necessary. The big bootstrap block is to allow one to use different test component templates for different cases?

@Gregcop1
Copy link
Collaborator

Reading test can be a kind of documentation so we have to be consistent. If you think current test format is too complex you must resolve this issue in another pull request (1 PR = 1 feature) where you revamp all the tests in one shot

@ollwenjones
Copy link
Collaborator Author

ollwenjones commented Jul 11, 2016

Ok. I'll try to find time this week.

@ollwenjones
Copy link
Collaborator Author

ollwenjones commented Jul 11, 2016

I was just thinking if "normal" test style has changed, we could gradually
convert things as we go, sort of like gradually replacing something
deprecated in a large project, or how we're gradually updating components
in here to conform to the angular style-guide as we make changes.

@Gregcop1
Copy link
Collaborator

IMO, I prefer changing everything in one PR, cause gradually convert will never be finished ;)

@ollwenjones ollwenjones force-pushed the feature/data-table-column-sort branch from a7f5f81 to ad4b7d5 Compare July 25, 2016 19:02
@ollwenjones
Copy link
Collaborator Author

@Gregcop1 I removed the $ suffix on observable fields and refactored the test to use the more verbose setup() function.

@coveralls
Copy link

coveralls commented Jul 25, 2016

Coverage Status

Coverage increased (+0.4%) to 88.394% when pulling ad4b7d5 on feature/data-table-column-sort into dbfc4e8 on master.

@ollwenjones ollwenjones force-pushed the feature/data-table-column-sort branch from ad4b7d5 to 84a5f82 Compare July 28, 2016 19:47
@coveralls
Copy link

coveralls commented Jul 28, 2016

Coverage Status

Coverage increased (+0.4%) to 88.394% when pulling 84a5f82 on feature/data-table-column-sort into dbfc4e8 on master.

@ollwenjones
Copy link
Collaborator Author

Afraid I'm not real savvy on Travis. When the tests actually run, they are all passing, but it looks like IE9 is not connecting on SauceLabs.

28 07 2016 20:02:18.859:WARN [launcher]: internet explorer 9 (Windows 7) on SauceLabs have not captured in 240000 ms, killing.
28 07 2016 20:02:19.027:ERROR [launcher]: internet explorer 9 (Windows 7) on SauceLabs failed 2 times (timeout). Giving up.

Anything I need to do here?

@justindujardin
Copy link
Owner

@ollwenjones can you update this to the latest master? I removed IE9 and IE10, and merged the RC4 branch. Hopefully this problem will be resolved simply by updating.

@ollwenjones ollwenjones force-pushed the feature/data-table-column-sort branch from 84a5f82 to fa897b2 Compare August 12, 2016 19:21
@ollwenjones
Copy link
Collaborator Author

@justindujardin sorry I didn't see that right away. I just rebased on master.

@ollwenjones
Copy link
Collaborator Author

Woops, looks like I missed a some testing updates, sorry.

Add column sorting via an attribute direcive which styles its host,
subsribes to and calls method on a service with an observable model.

Closes #144
@ollwenjones ollwenjones force-pushed the feature/data-table-column-sort branch from fa897b2 to c09c878 Compare August 16, 2016 01:57
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.6%) to 86.42% when pulling c09c878 on feature/data-table-column-sort into 81116f4 on master.

@ollwenjones
Copy link
Collaborator Author

Hm... now I don't know @justindujardin. I had a bad import, but now my tests are passing, but a whole lot of others are failing. 😦

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants