2021-08-13 14:41:34 +03:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
|
|
|
|
export default class GhMemberLabelInput extends Component {
|
|
|
|
@service store;
|
|
|
|
|
|
|
|
@tracked selectedLabel;
|
|
|
|
|
|
|
|
get availableLabels() {
|
|
|
|
return this._availableLabels.toArray().sort((labelA, labelB) => {
|
|
|
|
return labelA.name.localeCompare(labelB.name, undefined, {ignorePunctuation: true});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get availableLabelNames() {
|
|
|
|
return this.availableLabels.map(label => label.name.toLowerCase());
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(...args) {
|
|
|
|
super(...args);
|
|
|
|
// perform a background query to fetch all users and set `availableLabels`
|
|
|
|
// to a live-query that will be immediately populated with what's in the
|
|
|
|
// store and be updated when the above query returns
|
|
|
|
this.store.query('label', {limit: 'all'});
|
|
|
|
this._availableLabels = this.store.peekAll('label');
|
2021-09-10 07:49:25 +03:00
|
|
|
this.selectedLabel = this.args.label || this.availableLabels[0]?.get('id');
|
2021-08-13 19:20:46 +03:00
|
|
|
this.args.onChange(this.selectedLabel);
|
2021-08-13 14:41:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
updateLabel(newLabel) {
|
|
|
|
// update labels
|
|
|
|
this.selectedLabel = newLabel;
|
|
|
|
this.args.onChange(newLabel);
|
|
|
|
}
|
|
|
|
}
|