From ac5710979a6ed072c6a4da6a6d65b429a2403085 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 15 Dec 2021 13:15:31 -0500 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20apply=20type=20to=20?= =?UTF-8?q?host=20catalog=20and=20distribute=20down?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/addon/models/host.js | 7 -- addons/api/mirage/factories/host-catalog.js | 6 +- .../generated/factories/host-catalog.js | 2 +- addons/api/mirage/generated/factories/host.js | 2 +- addons/api/tests/unit/models/host-test.js | 10 --- .../host-catalog/hosts/index.hbs | 66 +++++++++---------- 6 files changed, 37 insertions(+), 56 deletions(-) diff --git a/addons/api/addon/models/host.js b/addons/api/addon/models/host.js index 62274032b..7748e023b 100644 --- a/addons/api/addon/models/host.js +++ b/addons/api/addon/models/host.js @@ -7,11 +7,4 @@ export default class HostModel extends GeneratedHostModel { * @type {FragmentHostAttributesModel} */ @fragment('fragment-host-attributes', { defaultValue: {} }) attributes; - - /** - * @type {boolean} - */ - get isStatic() { - return this.type === 'static'; - } } diff --git a/addons/api/mirage/factories/host-catalog.js b/addons/api/mirage/factories/host-catalog.js index c08d2786a..75bcc3928 100644 --- a/addons/api/mirage/factories/host-catalog.js +++ b/addons/api/mirage/factories/host-catalog.js @@ -18,9 +18,9 @@ export default factory.extend({ }, withChildren: trait({ afterCreate(hostCatalog, server) { - const { scope } = hostCatalog; - const hosts = server.createList('host', 10, { scope, hostCatalog }); - server.createList('host-set', 3, { scope, hostCatalog, hosts }); + const { scope, type } = hostCatalog; + const hosts = server.createList('host', 10, { scope, hostCatalog, type }); + server.createList('host-set', 3, { scope, hostCatalog, hosts, type }); }, }), }); diff --git a/addons/api/mirage/generated/factories/host-catalog.js b/addons/api/mirage/generated/factories/host-catalog.js index 36d5e64c6..1b2bb8af6 100644 --- a/addons/api/mirage/generated/factories/host-catalog.js +++ b/addons/api/mirage/generated/factories/host-catalog.js @@ -5,7 +5,7 @@ import { random, date, datatype } from 'faker'; * GeneratedHostCatalogModelFactory */ export default Factory.extend({ - type: 'static', + type: () => random.arrayElement(['static', 'plugin']), name: () => random.words(), description: () => random.words(), created_time: () => date.recent(), diff --git a/addons/api/mirage/generated/factories/host.js b/addons/api/mirage/generated/factories/host.js index 08ac8a5f3..db9de3b56 100644 --- a/addons/api/mirage/generated/factories/host.js +++ b/addons/api/mirage/generated/factories/host.js @@ -5,7 +5,7 @@ import { random, date, internet, datatype } from 'faker'; * GeneratedHostModelFactory */ export default Factory.extend({ - type: () => random.arrayElement(['static', 'plugin']), + type: 'static', name: () => random.words(), description: () => random.words(), created_time: () => date.recent(), diff --git a/addons/api/tests/unit/models/host-test.js b/addons/api/tests/unit/models/host-test.js index 9cd08b5aa..625774e71 100644 --- a/addons/api/tests/unit/models/host-test.js +++ b/addons/api/tests/unit/models/host-test.js @@ -22,14 +22,4 @@ module('Unit | Model | host', function (hooks) { }); assert.equal(model.attributes.address, '127.0.0.1'); }); - - test('it has isStatic function and returns the expected values', async function (assert) { - assert.expect(3); - const store = this.owner.lookup('service:store'); - const modelA = store.createRecord('host', { type: 'static' }); - const modelB = store.createRecord('host', { type: 'plugin' }); - assert.equal(typeof modelA.isStatic, 'boolean'); - assert.true(modelA.isStatic); - assert.false(modelB.isStatic); - }); }); diff --git a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/hosts/index.hbs b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/hosts/index.hbs index eb69b4d5d..afd87cccc 100644 --- a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/hosts/index.hbs +++ b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/hosts/index.hbs @@ -11,41 +11,39 @@ {{#each @model as |host|}} - {{#if host.isStatic}} - - - {{#if (can 'read model' host)}} - - - {{host.displayName}} - - {{else}} - {{host.displayName}} - {{/if}} -

{{host.description}}

-
- - - {{t (concat 'resources.host.types.' host.type)}} - - - - + + {{#if (can 'read model' host)}} + - {{host.id}} - - - - {{host.attributes.address}} - -
- {{/if}} + + {{host.displayName}} + + {{else}} + {{host.displayName}} + {{/if}} +

{{host.description}}

+ + + + {{t (concat 'resources.host.types.' host.type)}} + + + + + {{host.id}} + + + + {{host.attributes.address}} + + {{/each}}