refactor: 💡 simplify new host catalog creation steps

This commit is contained in:
Randall Morey committed 2022-02-15 14:36:54 -05:00
1 parent a1494be628
commit 58731f1448
3 files changed
+7 -25

No files matched your search

@@ -15,10 +15,6 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsNewRoute extends
const { id: host_catalog_id, compositeType } = this.modelFor(
'scopes.scope.host-catalogs.host-catalog'
);
if (this.currentModel?.isNew) {
this.currentModel.rollbackAttributes();
}
console.log('typedwed', compositeType);
return this.store.createRecord('host-set', {
compositeType,
host_catalog_id,
@@ -55,17 +51,10 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsNewRoute extends
model: model,
});
}
/**
* Update type of host set
* @param {string} type
*/
@action
async changeType(type) {
await this.router.replaceWith({ queryParams: { type } });
}
/**
* Adds a string item to array `property` on the passed `filter`.
* @param {hostSetModel} hostSet
* @param {string} property
* @param {string} value
@@ -23,7 +23,7 @@ export default class ScopesScopeHostCatalogsNewRoute extends Route {
* creating another, but reuse name/description if available.
* @return {HostCatalogModel}
*/
model() {
model({ type: compositeType = 'static' }) {
const scopeModel = this.modelFor('scopes.scope');
let name, description;
if (this.currentModel?.isNew) {
@@ -32,25 +32,19 @@ export default class ScopesScopeHostCatalogsNewRoute extends Route {
}
return this.store.createRecord('host-catalog', {
scopeModel,
compositeType,
name,
description,
});
}
afterModel(model, transition) {
this.changeType(transition.to.queryParams?.type);
}
/**
* Update type of host catalog
* @param {string} type
*/
@action
async changeType(type) {
const model = this.modelFor('scopes.scope.host-catalogs.new');
if (!type) type = 'static'; // Unknown host catalog type defaults to 'static'
if (model.isUnknown) type = 'aws'; //Is this the default case for plugin type?
model.compositeType = type;
await this.router.replaceWith({ queryParams: { type } });
changeType(type) {
if (type === 'plugin') type = 'aws';
this.router.replaceWith({ queryParams: { type } });
}
}
@@ -4,7 +4,6 @@
@model={{@model}}
@submit={{route-action 'save' @model}}
@cancel={{route-action 'cancel' @model}}
@changeType={{route-action 'changeType' @model.type}}
@removeItemByIndex={{route-action 'removeItemByIndex' @model}}
@addStringItem={{route-action 'addStringItem' @model}}
/>