ember-emeis
Version:
The frontend for the emeis user management service
46 lines (38 loc) • 1.51 kB
JavaScript
import { inject as service } from "@ember/service";
import { isTesting, macroCondition } from "@embroider/macros";
import Component from "@glimmer/component";
import { restartableTask, lastValue, timeout } from "ember-concurrency";
import PowerSelect from "ember-power-select/components/power-select";
import PowerSelectMultiple from "ember-power-select/components/power-select-multiple";
import { handleTaskErrors } from "ember-emeis/-private/decorators";
export default class RelationshipSelectComponent extends Component {
notification;
intl;
store;
models;
get searchEnabled() {
return this.models && this.args.modelName && this.models.length > 5;
}
get selectComponent() {
return this.args.multiple ? PowerSelectMultiple : PowerSelect;
}
*fetchModels(search) {
if (this.args.model) {
return this.args.model;
}
if (typeof search === "string") {
if (macroCondition(!isTesting())) {
yield timeout(500);
}
return yield this.store.query(this.args.modelName, {
filter: { search },
});
}
// For some reason the this.model.lenght is 1 and this.model.content.length is 2
// It looks like an issue with the way findAll retrieves all cached first before making a request.
// The {reload: true} fixes this since the cached are ignored.
return yield this.store.findAll(this.args.modelName, { reload: true });
}
}