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

light-table: add iconSortable property #464

Merged
merged 3 commits into from
Jul 22, 2017
Merged

light-table: add iconSortable property #464

merged 3 commits into from
Jul 22, 2017

Conversation

ignatius-j
Copy link
Contributor

Closes #463

Copy link
Collaborator

@buschtoens buschtoens left a comment

Choose a reason for hiding this comment

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

There's a typo at @property iconDescending.

Other than that, great PR! ❤️

I'd still like to wait for @alexander-alvarez' opinion on my other comments.

*
* @property iconDescending
* @property iconDesci
Copy link
Collaborator

Choose a reason for hiding this comment

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

Whoops? 😛

}

return 'iconSortable';
}),
Copy link
Collaborator

@buschtoens buschtoens Jul 21, 2017

Choose a reason for hiding this comment

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

  /**
   * @property sortIcon
   * @type {String|null}
   * @private
   */
  sortIcon: computed('column.{sortable,sorted,ascending}', function() {
    let sorted = this.get('column.sorted');
    if (sorted) {
      let ascending = this.get('column.ascending');
      return ascending ? 'iconAscending' : 'iconDescending';
    }

    let sortable = this.get('column.sortable');
    return sortable ? 'iconSortable' : null;
  }),

I think I would rather mark sortIcon as private (for now). And only return a sortIcon, if it was set. That way later down in the template, we can just call {{if sortIcon}} as to not insert a "meaningless" <i> tag.

This behavior is slightly different than the current one, but I think this makes more sense. I doubt that the "empty" <i> tag is used in the wild.

Also, brace expansion, yay! 🎉

@alexander-alvarez What is your opinion?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good.
The only thing I can add is a 🚲 🏡 on the name -- sortIconProperty or sortIconAttribute just so it's clear that this string represents the attribute that will be pulled from to generate the icon simply from the name (we could add docs for it too)

{{#if column.sorted}}
<i class="lt-sort-icon {{if column.ascending sortIcons.iconAscending sortIcons.iconDescending}}"></i>
{{#if column.sortable}}
<i class="lt-sort-icon {{get sortIcons sortIcon}}"></i>
Copy link
Collaborator

Choose a reason for hiding this comment

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

With the other comment regarding sortIcon in mind, this would then be:

{{#if sortIcon}}
   <i class="lt-sort-icon {{get sortIcons sortIcon}}"></i>
{{/if}}

@buschtoens
Copy link
Collaborator

Don't get thrown off by the missing-tests label. We didn't have any in the first place. 😜

If you want, you can add some. If not, I'll do it afterwards. 😉

@ignatius-j
Copy link
Contributor Author

@buschtoens I noticed there weren't any tests explicitly for the sort icons. I would be up for taking a crack at putting in some integration tests!

@buschtoens
Copy link
Collaborator

I'd love that.

@ignatius-j ignatius-j changed the title light-table: add property light-table: add iconSortable property Jul 21, 2017
@ignatius-j
Copy link
Contributor Author

@buschtoens @alexander-alvarez I fixed the comments and added the initial integration test for making sure the sort icons render properly on lt-head. We could split that test out into three tests (one for each sort icon) if you would like.

Just let me know what you think!

let sortIcon = find('.lt-sort-icon', sortableHeader);

// Sortable case
assert.ok(hasClass(sortIcon, 'fa-sort'), 'Sortable icon renders');
Copy link
Collaborator

Choose a reason for hiding this comment

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

good test cases! I think it's fine as 1.

this also brought to light for me that the default behavior when sortable is enabled is to show the sortable icons.
If someone is expecting/want it not to show up it could be seen as a "breaking" change that the icon now show up.

Do we care? Should we document how turn it off? Have a cookbook example where it only shows on hover? Have a showSortableIconByDefault configuration option at the ember-cli-build.js level?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before, if the column was sortable but hadn't been sorted yet, it would display the icon in the DOM but with just the lt-sort-icon class and no other classes (<i class="lt-sort-icon"></i>).

To get that same result now, you would just not pass in any iconSortable to lt-head (because by default iconSortable is ''). So it should probably be stated somewhere that it is an optional field that you shouldn't pass in if you don't want an icon for flagging that the column is sortable.

I could also try to put together a Cookbook example of an iconSortable that only shows on hover. Let me know if you think that would be helpful!

Copy link
Collaborator

Choose a reason for hiding this comment

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

woops 🚪 🚶‍♂️ didn't pay close enough attention to the default.
you're right.

Copy link
Collaborator

@alexander-alvarez alexander-alvarez left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@buschtoens buschtoens left a comment

Choose a reason for hiding this comment

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

Great PR. ❤️

I'll add some tests asserting that no meaningless <i> tag is rendered on monday.

@buschtoens buschtoens merged commit 2f1751a into adopted-ember-addons:master Jul 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants