From ed248f583fe22be7f903007f1bd0d9b0defb9a67 Mon Sep 17 00:00:00 2001
From: Randall Morey
Date: Mon, 14 Feb 2022 18:06:12 -0500
Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20consolidate=20ho?=
=?UTF-8?q?st=20catalog=20type=20badges=20to=20component?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
addons/api/addon/models/host-set.js | 13 ++++++-
addons/api/tests/unit/models/host-set-test.js | 10 +++--
.../host-catalog-type-badge/index.hbs | 15 ++++++++
.../host-catalog/host-sets/host-set/hosts.hbs | 2 +-
.../host-catalog/host-sets/index.hbs | 24 +-----------
.../scopes/scope/host-catalogs/index.hbs | 38 +------------------
.../scope/targets/target/host-sources.hbs | 4 +-
7 files changed, 38 insertions(+), 68 deletions(-)
create mode 100644 ui/admin/app/components/host-catalog-type-badge/index.hbs
diff --git a/addons/api/addon/models/host-set.js b/addons/api/addon/models/host-set.js
index 98f7cd5e2..bd5f64f1a 100644
--- a/addons/api/addon/models/host-set.js
+++ b/addons/api/addon/models/host-set.js
@@ -1,5 +1,6 @@
import GeneratedHostSetModel from '../generated/models/host-set';
import { fragmentArray } from 'ember-data-model-fragments/attributes';
+import { types } from './host-catalog';
export default class HostSetModel extends GeneratedHostSetModel {
// =attributes
@@ -20,6 +21,14 @@ export default class HostSetModel extends GeneratedHostSetModel {
return this.type === 'plugin';
}
+ /**
+ * True if the host set is an unknown type.
+ * @type {boolean}
+ */
+ get isUnknown() {
+ return this.isPlugin && !types.includes(this.plugin?.name);
+ }
+
/**
* Returns if a host-set plugin is AWS or not
* @type {boolean}
@@ -41,7 +50,9 @@ export default class HostSetModel extends GeneratedHostSetModel {
* @type {string}
*/
get compositeType() {
- return this.plugin ? this.plugin.name : this.type;
+ if (this.isUnknown) return 'unknown';
+ if (this.isPlugin) return this.plugin.name;
+ return 'static';
}
/**
diff --git a/addons/api/tests/unit/models/host-set-test.js b/addons/api/tests/unit/models/host-set-test.js
index 33189d3d4..f3dd6c020 100644
--- a/addons/api/tests/unit/models/host-set-test.js
+++ b/addons/api/tests/unit/models/host-set-test.js
@@ -183,15 +183,19 @@ module('Unit | Model | host set', function (hooks) {
test('get compositeType return expected values', async function (assert) {
assert.expect(3);
const store = this.owner.lookup('service:store');
- const modelPlugin = store.createRecord('host-set', {
+ const modelPlugin1 = store.createRecord('host-set', {
+ type: 'plugin',
+ plugin: { name: 'aws' },
+ });
+ const modelPlugin2 = store.createRecord('host-set', {
type: 'plugin',
plugin: { name: 'Test name' },
});
const modelStatic = store.createRecord('host-set', {
type: 'static',
});
- assert.equal(typeof modelPlugin.compositeType, 'string');
- assert.equal(modelPlugin.compositeType, 'Test name');
+ assert.equal(modelPlugin1.compositeType, 'aws');
+ assert.equal(modelPlugin2.compositeType, 'unknown');
assert.equal(modelStatic.compositeType, 'static');
});
diff --git a/ui/admin/app/components/host-catalog-type-badge/index.hbs b/ui/admin/app/components/host-catalog-type-badge/index.hbs
new file mode 100644
index 000000000..8ee191dea
--- /dev/null
+++ b/ui/admin/app/components/host-catalog-type-badge/index.hbs
@@ -0,0 +1,15 @@
+{{#if @model.isStatic}}
+
+ {{t (concat 'resources.host-catalog.types.' @model.compositeType '.label')}}
+
+{{else if @model.isUnknown}}
+
+ {{t (concat 'resources.host-catalog.types.' @model.compositeType '.label')}}
+
+{{else}}
+
+ {{t (concat 'resources.host-catalog.types.' @model.compositeType '.label')}}
+
+{{/if}}
\ No newline at end of file
diff --git a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/host-sets/host-set/hosts.hbs b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/host-sets/host-set/hosts.hbs
index 9bcbe0fd4..21d06fcb9 100644
--- a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/host-sets/host-set/hosts.hbs
+++ b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/host-sets/host-set/hosts.hbs
@@ -26,7 +26,7 @@
{{host.description}}
- {{host.type}}
+
{{hostSet.description}}
- {{#if hostSet.isStatic}}
-
- {{t
- (concat
- 'resources.host-set.types.' hostSet.compositeType '.label'
- )
- }}
-
- {{else}}
-
- {{t
- (concat
- 'resources.host-set.types.' hostSet.compositeType '.label'
- )
- }}
-
- {{/if}}
+
{{hostCatalog.description}}
- {{#if hostCatalog.isStatic}}
-
- {{t
- (concat
- 'resources.host-catalog.types.'
- hostCatalog.compositeType
- '.label'
- )
- }}
-
- {{else if hostCatalog.isUnknown}}
-
- {{t
- (concat
- 'resources.host-catalog.types.'
- hostCatalog.compositeType
- '.label'
- )
- }}
-
- {{else}}
-
- {{t
- (concat
- 'resources.host-catalog.types.'
- hostCatalog.compositeType
- '.label'
- )
- }}
-
- {{/if}}
+
{{hostSet.model.description}}
- {{t
- (concat 'resources.host-set.types.' hostSet.model.type)
- }}
+
Date: Mon, 14 Feb 2022 15:37:12 -0800
Subject: [PATCH 2/2] =?UTF-8?q?chore:=20=F0=9F=A4=96=20use=20hostcatalogba?=
=?UTF-8?q?dge=20component?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ui/admin/app/components/form/target/add-host-sets/index.hbs | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/ui/admin/app/components/form/target/add-host-sets/index.hbs b/ui/admin/app/components/form/target/add-host-sets/index.hbs
index ca5c7a3e4..bd4c97765 100644
--- a/ui/admin/app/components/form/target/add-host-sets/index.hbs
+++ b/ui/admin/app/components/form/target/add-host-sets/index.hbs
@@ -34,9 +34,7 @@
{{hostSet.name}}
- {{t
- (concat 'resources.host-set.types.' hostSet.type)
- }}
+
{{hostSet.host_catalog_id}}