From 74d1b352b1ef6ec5e0fd0179c4bf1a3799dedcfb Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 9 Feb 2022 13:51:38 -0500 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20reuse=20name/descriptio?= =?UTF-8?q?n=20when=20changing=20instance=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routes/scopes/scope/host-catalogs/new.js | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/ui/admin/app/routes/scopes/scope/host-catalogs/new.js b/ui/admin/app/routes/scopes/scope/host-catalogs/new.js index 588ecac90..1e4932280 100644 --- a/ui/admin/app/routes/scopes/scope/host-catalogs/new.js +++ b/ui/admin/app/routes/scopes/scope/host-catalogs/new.js @@ -17,21 +17,24 @@ export default class ScopesScopeHostCatalogsNewRoute extends Route { // =methods - /** - * Rollback/destroy any new, unsaved instances from this route before - * creating another. - */ - beforeModel() { - if (this.currentModel?.isNew) this.currentModel.rollbackAttributes(); - } - /** * Creates a new unsaved host catalog belonging to the current scope. + * Also rollback/destroy any new, unsaved instances from this route before + * creating another, but reuse name/description if available. * @return {HostCatalogModel} */ model() { const scopeModel = this.modelFor('scopes.scope'); - return this.store.createRecord('host-catalog', { scopeModel }); + let name, description; + if (this.currentModel?.isNew) { + ({ name, description } = this.currentModel); + this.currentModel.rollbackAttributes(); + } + return this.store.createRecord('host-catalog', { + scopeModel, + name, + description, + }); } afterModel(model, transition) {