-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There are two changes here, and some caveats/commentary: 1. The “State“ table column was actually sorting only by status. The state was not an actual property, just something calculated in each client row, as a product of status, isEligible, and isDraining. This PR adds isDraining as a component of compositeState so it can be used for sorting. 2. The Sortable mixin declares dependent keys that cause the sort to be live-updating, but only if the members of the array change, such as if a new client is added, but not if any of the sortable properties change. This PR adds a SortableFactory function that generates a mixin whose listSorted computed property includes dependent keys for the sortable properties, so the table will live-update if any of the sortable properties change, not just the array members. There’s a warning if you use SortableFactory without dependent keys and via the original Sortable interface, so we can eventually migrate away from it.
- Loading branch information
Showing
11 changed files
with
252 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Mixin from '@ember/object/mixin'; | ||
import Ember from 'ember'; | ||
import { computed } from '@ember/object'; | ||
import { warn } from '@ember/debug'; | ||
|
||
/** | ||
Sortable mixin factory | ||
Simple sorting behavior for a list of objects. Pass the list of properties | ||
you want the list to be live-sorted based on, or use the generic sortable.js | ||
if you don’t need that. | ||
Properties to override: | ||
- sortProperty: the property to sort by | ||
- sortDescending: when true, the list is reversed | ||
- listToSort: the list of objects to sort | ||
Properties provided: | ||
- listSorted: a copy of listToSort that has been sorted | ||
*/ | ||
export default function sortableFactory(properties, fromSortableMixin) { | ||
const eachProperties = properties.map(property => `listToSort.@each.${property}`); | ||
|
||
return Mixin.create({ | ||
// Override in mixin consumer | ||
sortProperty: null, | ||
sortDescending: true, | ||
listToSort: computed(() => []), | ||
|
||
_sortableFactoryWarningPrinted: false, | ||
|
||
listSorted: computed( | ||
...eachProperties, | ||
'listToSort.[]', | ||
'sortProperty', | ||
'sortDescending', | ||
function() { | ||
if (!this._sortableFactoryWarningPrinted && !Ember.testing) { | ||
let message = | ||
'Using SortableFactory without property keys means the list will only sort when the members change, not when any of their properties change.'; | ||
|
||
if (fromSortableMixin) { | ||
message += ' The Sortable mixin is deprecated in favor of SortableFactory.'; | ||
} | ||
|
||
warn(message, properties.length > 0, { id: 'nomad.no-sortable-properties' }); | ||
this.set('_sortableFactoryWarningPrinted', true); | ||
} | ||
|
||
const sorted = this.listToSort.compact().sortBy(this.sortProperty); | ||
if (this.sortDescending) { | ||
return sorted.reverse(); | ||
} | ||
return sorted; | ||
} | ||
), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,5 @@ | ||
import Mixin from '@ember/object/mixin'; | ||
import { computed } from '@ember/object'; | ||
import SortableFactory from 'nomad-ui/mixins/sortable-factory'; | ||
|
||
/** | ||
Sortable mixin | ||
// A generic version of SortableFactory with no sort property dependent keys. | ||
|
||
Simple sorting behavior for a list of objects. | ||
Properties to override: | ||
- sortProperty: the property to sort by | ||
- sortDescending: when true, the list is reversed | ||
- listToSort: the list of objects to sort | ||
Properties provided: | ||
- listSorted: a copy of listToSort that has been sorted | ||
*/ | ||
export default Mixin.create({ | ||
// Override in mixin consumer | ||
sortProperty: null, | ||
sortDescending: true, | ||
listToSort: computed(() => []), | ||
|
||
listSorted: computed('listToSort.[]', 'sortProperty', 'sortDescending', function() { | ||
const sorted = this.listToSort | ||
.compact() | ||
.sortBy(this.sortProperty); | ||
if (this.sortDescending) { | ||
return sorted.reverse(); | ||
} | ||
return sorted; | ||
}), | ||
}); | ||
export default SortableFactory([], true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,8 @@ $size: 0.75em; | |
); | ||
} | ||
|
||
&.ineligible { | ||
&.ineligible, | ||
&.draining { | ||
background: $warning; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.