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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions addon/components/columns/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ const Column = Component.extend(DraggableColumnMixin, {
*/
sortIcons: null,

/**
* @property sortIcon
* @type {String}
*/
sortIcon: computed('column.sorted', 'column.ascending', function() {
let sorted = this.get('column.sorted');

if (sorted) {
let ascending = this.get('column.ascending');
return ascending ? 'iconAscending' : 'iconDescending';
}

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)


/**
* @property colspan
* @type {Number}
Expand Down
28 changes: 20 additions & 8 deletions addon/mixins/table-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,24 @@ export default Mixin.create({
resizeOnDrag: false,

/**
* CSS classes to be applied to an `<i class="lt-sort-icon></i>` tag that is
* inserted into the column's `<th>` element.
* CSS classes to be applied to an `<i class="lt-sort-icon"></i>` tag that is
* inserted into the column's `<th>` element when the column is sortable but
* not yet sorted.
*
* For instance, if you have installed `ember-font-awesome` or include the
* `font-awesome` assets manually (e.g. via a CDN), you can set
* `iconAscending` to `'fa fa-sort-asc'`, which would yield this markup:
* `<i class="lt-sort-icon fa fa-sort-asc"></i>`
* `iconSortable` to `'fa fa-sort'`, which would yield this markup:
* `<i class="lt-sort-icon fa fa-sort"></i>`
*
* @property iconSortable
* @type {String}
* @default ''
*/
iconSortable: '',

/**
* See `iconSortable`. CSS classes to apply to `<i class="lt-sort-icon"></i>`
* when the column is sorted ascending.
*
* @property iconAscending
* @type {String}
Expand All @@ -84,9 +95,10 @@ export default Mixin.create({
iconAscending: '',

/**
* See `iconAscending`.
* See `iconSortable`. CSS classes to apply to `<i class="lt-sort-icon"></i>`
* when the column is sorted descending.
*
* @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? 😛

* @type {String}
* @default ''
*/
Expand All @@ -103,8 +115,8 @@ export default Mixin.create({
subColumns: computed.readOnly('table.visibleSubColumns'),
columns: computed.readOnly('table.visibleColumns'),

sortIcons: computed('iconAscending', 'iconDescending', function() {
return this.getProperties(['iconAscending', 'iconDescending']);
sortIcons: computed('iconSortable', 'iconAscending', 'iconDescending', function() {
return this.getProperties(['iconSortable', 'iconAscending', 'iconDescending']);
}).readOnly(),

init() {
Expand Down
4 changes: 2 additions & 2 deletions addon/templates/components/columns/base.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{{component column.component column=column table=table tableActions=tableActions sortIcons=sortIcons}}
{{else}}
{{label}}
{{#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}}

{{/if}}
{{/if}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{{#light-table table height='65vh' as |t|}}
{{t.head
onColumnClick=(action 'onColumnClick')
iconSortable='fa fa-sort'
iconAscending='fa fa-sort-asc'
iconDescending='fa fa-sort-desc'
fixed=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{{#light-table table height='65vh' as |t|}}
{{t.head
onColumnClick=(action 'onColumnClick')
iconSortable='fa fa-sort'
iconAscending='fa fa-sort-asc'
iconDescending='fa fa-sort-desc'
fixed=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

{{t.head
onColumnClick=(action 'onColumnClick')
iconSortable='fa fa-sort'
iconAscending='fa fa-sort-asc'
iconDescending='fa fa-sort-desc'
resizeOnDrag=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

{{t.head
onColumnClick=(action 'onColumnClick')
iconSortable='fa fa-sort'
iconAscending='fa fa-sort-asc'
iconDescending='fa fa-sort-desc'
fixed=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

{{t.head
onColumnClick=(action 'onColumnClick')
iconSortable='fa fa-sort'
iconAscending='fa fa-sort-asc'
iconDescending='fa fa-sort-desc'
fixed=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

{{t.head
onColumnClick=(action 'onColumnClick')
iconSortable='fa fa-sort'
iconAscending='fa fa-sort-asc'
iconDescending='fa fa-sort-desc'
fixed=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

{{t.head
onColumnClick=(pipe (action 'onColumnClick') (action 'setPage' 1))
iconSortable='fa fa-sort'
iconAscending='fa fa-sort-asc'
iconDescending='fa fa-sort-desc'
fixed=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

{{t.head
onColumnClick=(action 'onColumnClick')
iconSortable='fa fa-sort'
iconAscending='fa fa-sort-asc'
iconDescending='fa fa-sort-desc'
fixed=true
Expand Down
1 change: 1 addition & 0 deletions tests/dummy/app/templates/components/responsive-table.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

{{t.head
onColumnClick=(action 'onColumnClick')
iconSortable='fa fa-sort'
iconAscending='fa fa-sort-asc'
iconDescending='fa fa-sort-desc'
fixed=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{{#light-table table height='65vh' as |t|}}
{{t.head
onColumnClick=(action 'onColumnClick')
iconSortable='fa fa-sort'
iconAscending='fa fa-sort-asc'
iconDescending='fa fa-sort-desc'
fixed=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{{#light-table table height='65vh' as |t|}}
{{t.head
onColumnClick=(action 'onColumnClick')
iconSortable='fa fa-sort'
iconAscending='fa fa-sort-asc'
iconDescending='fa fa-sort-desc'
fixed=true
Expand Down
1 change: 1 addition & 0 deletions tests/dummy/app/templates/components/scrolling-table.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

{{t.head
onColumnClick=(action 'onColumnClick')
iconSortable='fa fa-sort'
iconAscending='fa fa-sort-asc'
iconDescending='fa fa-sort-desc'
fixed=true
Expand Down
1 change: 1 addition & 0 deletions tests/dummy/app/templates/components/simple-table.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

{{t.head
onColumnClick=(action 'onColumnClick')
iconSortable='fa fa-sort'
iconAscending='fa fa-sort-asc'
iconDescending='fa fa-sort-desc'
fixed=true
Expand Down