From eb36be3688704b8416c6cf3362d76ffc197e2879 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Tue, 11 Jan 2022 15:34:11 -0800 Subject: [PATCH 01/10] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20host=20catal?= =?UTF-8?q?og=20type=20basic=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add host catalog type basic support. Delete previous conditional rendering to just render static types --- .../addon/generated/models/host-catalog.js | 6 ++ addons/api/addon/models/host-catalog.js | 21 ++++++- .../tests/unit/models/host-catalog-test.js | 40 ++++++++++-- .../scopes/scope/host-catalogs/index.hbs | 62 +++++++++---------- 4 files changed, 89 insertions(+), 40 deletions(-) diff --git a/addons/api/addon/generated/models/host-catalog.js b/addons/api/addon/generated/models/host-catalog.js index 5f4569e6a..553500cc3 100644 --- a/addons/api/addon/generated/models/host-catalog.js +++ b/addons/api/addon/generated/models/host-catalog.js @@ -48,4 +48,10 @@ export default class GeneratedHostCatalogModel extends BaseModel { description: 'Current version number of this resource.', }) version; + + @attr('string', { + description: 'Plugin information for this resource.', + readOnly: true, + }) + plugin; } diff --git a/addons/api/addon/models/host-catalog.js b/addons/api/addon/models/host-catalog.js index f9ae96493..b81493a77 100644 --- a/addons/api/addon/models/host-catalog.js +++ b/addons/api/addon/models/host-catalog.js @@ -2,9 +2,26 @@ import GeneratedHostCatalogModel from '../generated/models/host-catalog'; export default class HostCatalogModel extends GeneratedHostCatalogModel { /** + * Returns if the host-catalog is a plugin or not. * @type {boolean} */ - get isStatic() { - return this.type === 'static'; + get isPlugin() { + return this.type === 'plugin'; + } + + /** + * Returns if host-catalog plugin is AWS or not + * @type {boolean} + */ + get isAWS() { + return this.plugin.name === 'aws'; + } + + /** + * Return if host-catalog plugin is Azure or not. + * @type {boolean} + */ + get isAzure() { + return this.plugin.name === 'azure'; } } diff --git a/addons/api/tests/unit/models/host-catalog-test.js b/addons/api/tests/unit/models/host-catalog-test.js index 48b21051d..c377bee8b 100644 --- a/addons/api/tests/unit/models/host-catalog-test.js +++ b/addons/api/tests/unit/models/host-catalog-test.js @@ -10,13 +10,41 @@ module('Unit | Model | host catalog', function (hooks) { assert.ok(model); }); - test('it has isStatic function and returns the expected values', async function (assert) { + test('it has isPlugin 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); + const modelPlugin = store.createRecord('host-catalog', { type: 'plugin' }); + const modelStatic = store.createRecord('host-catalog', { type: 'static' }); + assert.equal(typeof modelPlugin.isPlugin, 'boolean'); + assert.true(modelPlugin.isPlugin); + assert.false(modelStatic.isPlugin); + }); + + test('it has isAWS function and returns the expected values', async function (assert) { + assert.expect(3); + const store = this.owner.lookup('service:store'); + const modelAws = store.createRecord('host-catalog', { + plugin: { name: 'aws' }, + }); + const modelRandom = store.createRecord('host-catalog', { + plugin: { name: 'random' }, + }); + assert.equal(typeof modelAws.isAWS, 'boolean'); + assert.true(modelAws.isAWS); + assert.false(modelRandom.isAWS); + }); + + test('it has isAzure function and return the expected values', async function (assert) { + assert.expect(3); + const store = this.owner.lookup('service:store'); + const modelAzure = store.createRecord('host-catalog', { + plugin: { name: 'azure' }, + }); + const modelRandom = store.createRecord('host-catalog', { + plugin: { name: 'random' }, + }); + assert.equal(typeof modelAzure.isAzure, 'boolean'); + assert.true(modelAzure.isAzure); + assert.false(modelRandom.isAzure); }); }); 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 b3900063f..94eb61309 100644 --- a/ui/admin/app/templates/scopes/scope/host-catalogs/index.hbs +++ b/ui/admin/app/templates/scopes/scope/host-catalogs/index.hbs @@ -41,39 +41,37 @@ {{#each @model as |hostCatalog|}} - {{#if hostCatalog.isStatic}} - - - {{#if (can 'read model' hostCatalog)}} - - {{hostCatalog.displayName}} - - {{else}} - {{hostCatalog.displayName}} - {{/if}} -

{{hostCatalog.description}}

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

{{hostCatalog.description}}

+ + + + {{t + (concat 'resources.host-catalog.types.' hostCatalog.type) + }} + + + + + {{hostCatalog.id}} + + + {{/each}}
From b3c49c43ea1530008471e233308b62f80cf71e6d Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 12 Jan 2022 15:34:12 -0800 Subject: [PATCH 02/10] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20basic=20type?= =?UTF-8?q?=20support=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}} Date: Thu, 13 Jan 2022 13:22:09 -0800 Subject: [PATCH 03/10] Delete unnecesary return --- addons/api/mirage/generated/factories/host-catalog.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/addons/api/mirage/generated/factories/host-catalog.js b/addons/api/mirage/generated/factories/host-catalog.js index c0185141f..88ab771f3 100644 --- a/addons/api/mirage/generated/factories/host-catalog.js +++ b/addons/api/mirage/generated/factories/host-catalog.js @@ -18,8 +18,6 @@ export default Factory.extend({ name: random.arrayElement(['azure', 'aws']), description: random.words(), }; - } else { - return undefined; } }, }); From 4c0cc5375b846aa30388376bf514e00b030c2721 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Thu, 13 Jan 2022 18:31:17 -0800 Subject: [PATCH 04/10] Add set compositeType. Add tests for get and set compositeType --- addons/api/addon/models/host-catalog.js | 12 +++++++ .../tests/unit/models/host-catalog-test.js | 33 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/addons/api/addon/models/host-catalog.js b/addons/api/addon/models/host-catalog.js index 0f424eeca..0c649ea4f 100644 --- a/addons/api/addon/models/host-catalog.js +++ b/addons/api/addon/models/host-catalog.js @@ -40,4 +40,16 @@ export default class HostCatalogModel extends GeneratedHostCatalogModel { get compositeType() { return this.isPlugin ? this.plugin.name : this.type; } + + /** + * Sets type, if type is different than static, sets plugin name to type + */ + set compositeType(type) { + if (type === 'static') { + this.type = 'static'; + } else { + this.type = 'plugin'; + this.plugin.name = type; + } + } } diff --git a/addons/api/tests/unit/models/host-catalog-test.js b/addons/api/tests/unit/models/host-catalog-test.js index db6c1d13d..429e3f50b 100644 --- a/addons/api/tests/unit/models/host-catalog-test.js +++ b/addons/api/tests/unit/models/host-catalog-test.js @@ -57,4 +57,37 @@ module('Unit | Model | host catalog', function (hooks) { assert.true(modelAzure.isAzure); assert.false(modelRandom.isAzure); }); + + test('get compositeType returns expected values', async function (assert) { + assert.expect(3); + const store = this.owner.lookup('service:store'); + const modelPlugin = store.createRecord('host-catalog', { + type: 'plugin', + plugin: { name: 'Test name' }, + }); + const modelStatic = store.createRecord('host-catalog', { + type: 'static', + }); + assert.equal(typeof modelPlugin.compositeType, 'string'); + assert.equal(modelPlugin.compositeType, 'Test name'); + assert.equal(modelStatic.compositeType, 'static'); + }); + + test('set compositeType sets expected values', async function (assert) { + assert.expect(3); + const store = this.owner.lookup('service:store'); + const modelPlugin = store.createRecord('host-catalog', { + type: 'plugin', + plugin: { name: 'Test name' }, + }); + const modelStatic = store.createRecord('host-catalog', { + type: 'static', + }); + modelPlugin.set('compositeType', 'aws'); + modelStatic.set('compositeType', 'static'); + + assert.equal(modelPlugin.type, 'plugin'); + assert.equal(modelPlugin.plugin.name, 'aws'); + assert.equal(modelStatic.type, 'static'); + }); }); From d6b01e8308b8aed1c1af8ce1f24828ea2fdad13c Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 14 Jan 2022 08:21:25 -0800 Subject: [PATCH 05/10] =?UTF-8?q?chore:=20=F0=9F=A4=96=20Update=20flight?= =?UTF-8?q?=20icons=20to=202.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update flight icons to 2.0 --- addons/rose/package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/rose/package.json b/addons/rose/package.json index 1814040ea..18a3d9829 100644 --- a/addons/rose/package.json +++ b/addons/rose/package.json @@ -44,7 +44,7 @@ "@ember/test-helpers": "^2.4.2", "@glimmer/component": "^1.0.4", "@glimmer/tracking": "^1.0.4", - "@hashicorp/flight-icons": "^1.0.0", + "@hashicorp/flight-icons": "^2.0.1", "@storybook/addon-a11y": "^6.3.12", "@storybook/addon-actions": "^6.3.10", "@storybook/addon-docs": "^6.3.8", diff --git a/yarn.lock b/yarn.lock index 2fdf55c4c..52a46ca22 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3449,10 +3449,10 @@ resolved "https://registry.yarnpkg.com/@handlebars/parser/-/parser-1.1.0.tgz#d6dbc7574774b238114582410e8fee0dc3532bdf" integrity sha512-rR7tJoSwJ2eooOpYGxGGW95sLq6GXUaS1UtWvN7pei6n2/okYvCGld9vsUTvkl2migxbkszsycwtMf/GEc1k1A== -"@hashicorp/flight-icons@^1.0.0": - version "1.0.0" - resolved "https://registry.yarnpkg.com/@hashicorp/flight-icons/-/flight-icons-1.0.0.tgz#488ec6c3aaa8702d7878274abb8a5352eae1f6a2" - integrity sha512-LehZZOxbHZmVLzF6fy2w1LqJ5jQv+QXCfGlb7oToBc3u6YPxlIb3S1+bKQJIXzn7TELFRjRndnCtuYYXFO90Ng== +"@hashicorp/flight-icons@^2.0.1": + version "2.0.1" + resolved "https://registry.yarnpkg.com/@hashicorp/flight-icons/-/flight-icons-2.0.1.tgz#7e7370f1d45207409dd20ebdce7285370e7d9532" + integrity sha512-445WEmL0ysOeVQDe2khCqGbmNm+/Rv5B35Q8FXvc+RuE+r9mNWL0ufe2cVa8Sqqt/VRg0lyTEhArNX9gYCX1Yg== "@humanwhocodes/config-array@^0.5.0": version "0.5.0" From cc20e5a076205e990abe8d14cde5d244ea4e4e5a Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 14 Jan 2022 13:14:50 -0800 Subject: [PATCH 06/10] Use compositeType in isAws and isAzure --- addons/api/addon/models/host-catalog.js | 6 +++--- addons/api/tests/unit/models/host-catalog-test.js | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/api/addon/models/host-catalog.js b/addons/api/addon/models/host-catalog.js index 0c649ea4f..43f2800c9 100644 --- a/addons/api/addon/models/host-catalog.js +++ b/addons/api/addon/models/host-catalog.js @@ -22,7 +22,7 @@ export default class HostCatalogModel extends GeneratedHostCatalogModel { * @type {boolean} */ get isAWS() { - return this.plugin.name === 'aws'; + return this.compositeType === 'aws'; } /** @@ -30,7 +30,7 @@ export default class HostCatalogModel extends GeneratedHostCatalogModel { * @type {boolean} */ get isAzure() { - return this.plugin.name === 'azure'; + return this.compositeType === 'azure'; } /** If host-catalog is a plugins returns its name, @@ -49,7 +49,7 @@ export default class HostCatalogModel extends GeneratedHostCatalogModel { this.type = 'static'; } else { this.type = 'plugin'; - this.plugin.name = type; + this.plugin = { name: type } } } } diff --git a/addons/api/tests/unit/models/host-catalog-test.js b/addons/api/tests/unit/models/host-catalog-test.js index 429e3f50b..cf1cc94d5 100644 --- a/addons/api/tests/unit/models/host-catalog-test.js +++ b/addons/api/tests/unit/models/host-catalog-test.js @@ -34,6 +34,7 @@ module('Unit | Model | host catalog', function (hooks) { assert.expect(3); const store = this.owner.lookup('service:store'); const modelAws = store.createRecord('host-catalog', { + type: 'plugin', plugin: { name: 'aws' }, }); const modelRandom = store.createRecord('host-catalog', { @@ -48,6 +49,7 @@ module('Unit | Model | host catalog', function (hooks) { assert.expect(3); const store = this.owner.lookup('service:store'); const modelAzure = store.createRecord('host-catalog', { + type: 'plugin', plugin: { name: 'azure' }, }); const modelRandom = store.createRecord('host-catalog', { From bdc9dacdce264b20c57217f87f5e8984888031ad Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 14 Jan 2022 15:15:08 -0600 Subject: [PATCH 07/10] Update addons/api/mirage/generated/factories/host-catalog.js Co-authored-by: Randall Morey --- addons/api/mirage/generated/factories/host-catalog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/api/mirage/generated/factories/host-catalog.js b/addons/api/mirage/generated/factories/host-catalog.js index 88ab771f3..783c684b1 100644 --- a/addons/api/mirage/generated/factories/host-catalog.js +++ b/addons/api/mirage/generated/factories/host-catalog.js @@ -11,7 +11,7 @@ export default Factory.extend({ created_time: () => date.recent(), updated_time: () => date.recent(), disabled: () => datatype.boolean(), - plugin: function () { + plugin: function (i) { if (this.type == 'plugin') { return { id: `pl_${datatype.hexaDecimal(5)}`, From 8007762bd1f66639a18ab40df07f78f5e0aea3fc Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 14 Jan 2022 15:15:13 -0600 Subject: [PATCH 08/10] Update addons/api/mirage/generated/factories/host-catalog.js Co-authored-by: Randall Morey --- addons/api/mirage/generated/factories/host-catalog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/api/mirage/generated/factories/host-catalog.js b/addons/api/mirage/generated/factories/host-catalog.js index 783c684b1..fa8135226 100644 --- a/addons/api/mirage/generated/factories/host-catalog.js +++ b/addons/api/mirage/generated/factories/host-catalog.js @@ -15,7 +15,7 @@ export default Factory.extend({ if (this.type == 'plugin') { return { id: `pl_${datatype.hexaDecimal(5)}`, - name: random.arrayElement(['azure', 'aws']), + name: i % 2 ? 'aws' : 'azure', description: random.words(), }; } From df673ad29b3f0948b5a6d9528211b17214d6009c Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 14 Jan 2022 13:28:13 -0800 Subject: [PATCH 09/10] Use compositeType properly on tests --- addons/api/tests/unit/models/host-catalog-test.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/addons/api/tests/unit/models/host-catalog-test.js b/addons/api/tests/unit/models/host-catalog-test.js index cf1cc94d5..84adfd1b8 100644 --- a/addons/api/tests/unit/models/host-catalog-test.js +++ b/addons/api/tests/unit/models/host-catalog-test.js @@ -79,14 +79,11 @@ module('Unit | Model | host catalog', function (hooks) { assert.expect(3); const store = this.owner.lookup('service:store'); const modelPlugin = store.createRecord('host-catalog', { - type: 'plugin', - plugin: { name: 'Test name' }, + compositeType: 'aws' }); const modelStatic = store.createRecord('host-catalog', { - type: 'static', + compositeType: 'static', }); - modelPlugin.set('compositeType', 'aws'); - modelStatic.set('compositeType', 'static'); assert.equal(modelPlugin.type, 'plugin'); assert.equal(modelPlugin.plugin.name, 'aws'); From d2e914cba9d7933ee8ea41bb7218d26201eb096d Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 14 Jan 2022 13:32:38 -0800 Subject: [PATCH 10/10] Fix lint errors --- addons/api/addon/models/host-catalog.js | 2 +- addons/api/tests/unit/models/host-catalog-test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/api/addon/models/host-catalog.js b/addons/api/addon/models/host-catalog.js index 43f2800c9..8a0a64bd5 100644 --- a/addons/api/addon/models/host-catalog.js +++ b/addons/api/addon/models/host-catalog.js @@ -49,7 +49,7 @@ export default class HostCatalogModel extends GeneratedHostCatalogModel { this.type = 'static'; } else { this.type = 'plugin'; - this.plugin = { name: type } + this.plugin = { name: type }; } } } diff --git a/addons/api/tests/unit/models/host-catalog-test.js b/addons/api/tests/unit/models/host-catalog-test.js index 84adfd1b8..7a8a77147 100644 --- a/addons/api/tests/unit/models/host-catalog-test.js +++ b/addons/api/tests/unit/models/host-catalog-test.js @@ -79,7 +79,7 @@ module('Unit | Model | host catalog', function (hooks) { assert.expect(3); const store = this.owner.lookup('service:store'); const modelPlugin = store.createRecord('host-catalog', { - compositeType: 'aws' + compositeType: 'aws', }); const modelStatic = store.createRecord('host-catalog', { compositeType: 'static',