From b3c49c43ea1530008471e233308b62f80cf71e6d Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 12 Jan 2022 15:34:12 -0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20basic=20type=20sup?= =?UTF-8?q?port=20for=20host=20catalog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../addon/generated/models/host-catalog.js | 2 +- addons/api/addon/models/host-catalog.js | 16 ++++++++++++++ .../generated/factories/host-catalog.js | 11 ++++++++++ .../tests/unit/models/host-catalog-test.js | 10 +++++++++ .../scopes/scope/host-catalogs/index.hbs | 22 ++++++++++++++----- 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/addons/api/addon/generated/models/host-catalog.js b/addons/api/addon/generated/models/host-catalog.js index 553500cc3..f1f78db34 100644 --- a/addons/api/addon/generated/models/host-catalog.js +++ b/addons/api/addon/generated/models/host-catalog.js @@ -49,7 +49,7 @@ export default class GeneratedHostCatalogModel extends BaseModel { }) version; - @attr('string', { + @attr({ description: 'Plugin information for this resource.', readOnly: true, }) diff --git a/addons/api/addon/models/host-catalog.js b/addons/api/addon/models/host-catalog.js index b81493a77..0f424eeca 100644 --- a/addons/api/addon/models/host-catalog.js +++ b/addons/api/addon/models/host-catalog.js @@ -1,6 +1,14 @@ import GeneratedHostCatalogModel from '../generated/models/host-catalog'; export default class HostCatalogModel extends GeneratedHostCatalogModel { + /** + * Returns if the host-catalog is static type or not. + * @type {boolean} + */ + get isStatic() { + return this.type === 'static'; + } + /** * Returns if the host-catalog is a plugin or not. * @type {boolean} @@ -24,4 +32,12 @@ export default class HostCatalogModel extends GeneratedHostCatalogModel { get isAzure() { return this.plugin.name === 'azure'; } + + /** If host-catalog is a plugins returns its name, + * otherwise returns the host-catalog type + * @type {string} + */ + get compositeType() { + return this.isPlugin ? this.plugin.name : this.type; + } } diff --git a/addons/api/mirage/generated/factories/host-catalog.js b/addons/api/mirage/generated/factories/host-catalog.js index 1b2bb8af6..c0185141f 100644 --- a/addons/api/mirage/generated/factories/host-catalog.js +++ b/addons/api/mirage/generated/factories/host-catalog.js @@ -11,4 +11,15 @@ export default Factory.extend({ created_time: () => date.recent(), updated_time: () => date.recent(), disabled: () => datatype.boolean(), + plugin: function () { + if (this.type == 'plugin') { + return { + id: `pl_${datatype.hexaDecimal(5)}`, + name: random.arrayElement(['azure', 'aws']), + description: random.words(), + }; + } else { + return undefined; + } + }, }); diff --git a/addons/api/tests/unit/models/host-catalog-test.js b/addons/api/tests/unit/models/host-catalog-test.js index c377bee8b..db6c1d13d 100644 --- a/addons/api/tests/unit/models/host-catalog-test.js +++ b/addons/api/tests/unit/models/host-catalog-test.js @@ -10,6 +10,16 @@ module('Unit | Model | host catalog', function (hooks) { assert.ok(model); }); + 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-catalog', { type: 'static' }); + const modelB = store.createRecord('host-catalog', { type: 'plugin' }); + assert.equal(typeof modelA.isStatic, 'boolean'); + assert.true(modelA.isStatic); + assert.false(modelB.isStatic); + }); + test('it has isPlugin function and returns the expected values', async function (assert) { assert.expect(3); const store = this.owner.lookup('service:store'); diff --git a/ui/admin/app/templates/scopes/scope/host-catalogs/index.hbs b/ui/admin/app/templates/scopes/scope/host-catalogs/index.hbs index 94eb61309..7765915cd 100644 --- a/ui/admin/app/templates/scopes/scope/host-catalogs/index.hbs +++ b/ui/admin/app/templates/scopes/scope/host-catalogs/index.hbs @@ -56,11 +56,23 @@

{{hostCatalog.description}}

- - {{t - (concat 'resources.host-catalog.types.' hostCatalog.type) - }} - + {{#if hostCatalog.isStatic}} + + {{t + (concat 'resources.host-catalog.types.' hostCatalog.type) + }} + + {{else}} + + {{hostCatalog.compositeType}} + + {{/if}}