open-nomad/ui/app/routes/variables/new.js
Phil Renaud e58a95ed2f
New variable creation adds the first namespace in your available list at variable creation time (#13991)
* New variable creation adds the first namespace in your available list at variable creation time

* Changelog
2022-08-03 15:09:25 -04:00

22 lines
634 B
JavaScript

import Route from '@ember/routing/route';
export default class VariablesNewRoute extends Route {
async model(params) {
const namespaces = await this.store.peekAll('namespace');
return this.store.createRecord('variable', {
path: params.path,
namespace: namespaces.objectAt(0)?.id,
});
}
resetController(controller, isExiting) {
// If the user navigates away from /new, clear the path
controller.set('path', null);
if (isExiting) {
// If user didn't save, delete the freshly created model
if (controller.model.isNew) {
controller.model.destroyRecord();
}
}
}
}