Fixes labels duplicating themselves across lalbe inputs when unsaved

no issue

- Unsaved labels were still persisted in the store. This was causing unsaved labels reappearing on different instances and caused broken states
This commit is contained in:
Nazar Gargol 2020-06-09 17:42:55 +12:00
parent 6c9aad0f5b
commit 0395b63d63
2 changed files with 11 additions and 5 deletions

View File

@ -34,6 +34,16 @@ export default Component.extend({
this.set('_availableLabels', this.store.peekAll('label'));
},
willDestroyElement() {
// NOTE: cleans up labels store in case they were not persisted, this avoids unsaved labels
// from appearing on different input instances when unsaved
this.get('_availableLabels').forEach((label) => {
if (label.get('isNew')) {
this.store.deleteRecord(label);
}
});
},
actions: {
matchLabels(labelName, term) {
return labelName.toLowerCase() === term.trim().toLowerCase();

View File

@ -165,11 +165,7 @@ export default class MembersController extends Controller {
@task
*fetchLabelsTask() {
if (!this._hasLoadedLabels) {
yield this.store.query('label', {limit: 'all'}).then(() => {
this._hasLoadedLabels = true;
});
}
yield this.store.query('label', {limit: 'all'});
}
@task({restartable: true})