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

fix: Date sort support + avoid null sorts comparison #3243

Merged
merged 1 commit into from
Jul 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 10 additions & 7 deletions app/components/tables/headers/sort.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Component from '@ember/component';
import { computed } from '@ember/object';
import { kebabCase } from 'lodash-es';

export default class extends Component {
@computed('sorts.@each.isAscending', 'sortDir')
get sortIcon() {
if (this.sorts && this.sorts[0] && this.sorts[0].valuePath === this.column.valuePath) {
this.set('sortDirection', this.sorts[0].isAscending ? 'ASC' : 'DES');
if (this.sorts[0].isAscending) {
// support got sort up, sort down to come with next release of semantic-ui-ember
// support for sort up, sort down to come with next release of semantic-ui-ember
return 'caret up';
} else {
return 'caret down';
Expand All @@ -21,15 +21,18 @@ export default class extends Component {
super.didInsertElement(...arguments);
if (this.sorts && this.sorts[0] && this.sorts[0].valuePath === this.column.valuePath) {
this.setProperties({
sortBy : this.sorts[0].valuePath,
sortBy : kebabCase(this.sorts[0].valuePath), // Ensures field names are server compatible with sort
sortDir : this.sorts[0].isAscending ? 'ASC' : 'DSC'
});

} else {
this.setProperties({
sortBy : null,
sortDir : null
});
// avoid resetting the query params, when sorts is uninitialised
if (this.sorts && !this.sorts[0]) {
this.setProperties({
sortBy : null,
sortDir : null
});
}
}
}
}
10 changes: 6 additions & 4 deletions app/controllers/events/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class extends Controller {
search = null;
sort_dir = null;
sort_by = null;

sorts = [];
@computed()
get columns() {
return [
Expand All @@ -29,9 +29,11 @@ export default class extends Controller {
}
},
{
name : 'Date',
valuePath : 'startsAt',
cellComponent : 'ui-table/cell/cell-event-date'
name : 'Date',
valuePath : 'startsAt',
isSortable : true,
headerComponent : 'tables/headers/sort',
cellComponent : 'ui-table/cell/cell-event-date'

},
{
Expand Down