Skip to content

Commit

Permalink
Change model-fetching from peek to find
Browse files Browse the repository at this point in the history
It’s not reliable to assume that the model will already be
present in the store.
  • Loading branch information
backspace committed Apr 15, 2020
1 parent a748cee commit 86f747a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions ui/app/components/global-search/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ export default Component.extend({
}
},

select({ model }) {
const itemModelName = model.constructor.modelName;
async select({ model }) {
const resolvedModel = await model.then();
const itemModelName = resolvedModel.constructor.modelName;

if (itemModelName === 'job') {
this.router.transitionTo('jobs.job', model.plainId);
this.router.transitionTo('jobs.job', resolvedModel.name);
} else if (itemModelName === 'allocation') {
this.router.transitionTo('allocations.allocation', model.id);
this.router.transitionTo('allocations.allocation', resolvedModel.id);
} else if (itemModelName === 'node') {
this.router.transitionTo('clients.client', model.id);
this.router.transitionTo('clients.client', resolvedModel.id);
}
},
},
Expand Down Expand Up @@ -109,25 +110,28 @@ function collectModels(store, searchResultsTypeKey, matches) {
if (searchResultsTypeKey === 'jobs') {
return matches.map(id => {
// FIXME don’t hardcode namespace
const model = store.peekRecord('job', JSON.stringify([id, 'default']));
const model = store.findRecord('job', JSON.stringify([id, 'default']));
return {
model,
labelProperty: 'name',
label: model.name,
};
});
} else if (searchResultsTypeKey === 'allocs') {
return matches.map(id => {
const model = store.peekRecord('allocation', id);
const model = store.findRecord('allocation', id);
return {
model,
labelProperty: 'id',
label: model.id,
};
});
} else if (searchResultsTypeKey === 'nodes') {
return matches.map(id => {
const model = store.peekRecord('node', id);
const model = store.findRecord('node', id);
return {
model,
labelProperty: 'id',
label: model.id,
};
});
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/components/global-search/control.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
@triggerComponent="global-search/trigger"
@registerAPI={{action 'storeSelect'}}
as |option|>
{{option.label}}
{{get option.model option.labelProperty}}
</PowerSelect>

0 comments on commit 86f747a

Please sign in to comment.