mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Fixed <GhTokenInput> not removing selected options when grouped
no issue Our token input component removes already-selected options from the list of available options but it was expecting a non-grouped set of options. - updated to recursively walk the options list and build a filtered list being careful not to modify the original groups by reference - swapped task decorator syntax out for the more easily readable `ember-concurrency-decorators` style
This commit is contained in:
parent
36feb46c65
commit
67db3f51c2
1 changed files with 35 additions and 8 deletions
|
@ -13,7 +13,7 @@ import {
|
|||
import {htmlSafe} from '@ember/string';
|
||||
import {isBlank} from '@ember/utils';
|
||||
import {tagName} from '@ember-decorators/component';
|
||||
import {task} from 'ember-concurrency';
|
||||
import {task} from 'ember-concurrency-decorators';
|
||||
|
||||
const {Handlebars} = Ember;
|
||||
|
||||
|
@ -130,14 +130,42 @@ class GhTokenInput extends Component {
|
|||
|
||||
// tasks -------------------------------------------------------------------
|
||||
|
||||
@task(function* () {
|
||||
@task
|
||||
*optionsWithoutSelectedTask() {
|
||||
let options = yield this.options;
|
||||
let selected = yield this.selected;
|
||||
return options.filter(o => !selected.includes(o));
|
||||
})
|
||||
optionsWithoutSelectedTask;
|
||||
|
||||
@task(function* (term, select) {
|
||||
let optionsWithoutSelected = [];
|
||||
|
||||
function filterSelectedOptions(opts, result) {
|
||||
opts.forEach((o) => {
|
||||
if (o.options) {
|
||||
const withoutSelected = [];
|
||||
filterSelectedOptions(o.options, withoutSelected);
|
||||
|
||||
if (withoutSelected.length > 0) {
|
||||
result.push({
|
||||
groupName: o.groupName,
|
||||
options: withoutSelected
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!selected.includes(o)) {
|
||||
result.push(o);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
filterSelectedOptions(options, optionsWithoutSelected);
|
||||
|
||||
return optionsWithoutSelected;
|
||||
}
|
||||
|
||||
@task
|
||||
*searchAndSuggestTask(term, select) {
|
||||
let newOptions = (yield this.optionsWithoutSelected).toArray();
|
||||
|
||||
if (term.length === 0) {
|
||||
|
@ -160,8 +188,7 @@ class GhTokenInput extends Component {
|
|||
this._addCreateOption(term, newOptions);
|
||||
|
||||
return newOptions;
|
||||
})
|
||||
searchAndSuggestTask;
|
||||
}
|
||||
|
||||
// internal ----------------------------------------------------------------
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue