feat: 🎸 Add basic type support for host catalog

This commit is contained in:
Carlos Alcaide Corvo committed 2022-01-12 15:34:12 -08:00
1 parent eb36be3688
commit b3c49c43ea
5 files changed
+55 -6

No files matched your search

@@ -49,7 +49,7 @@ export default class GeneratedHostCatalogModel extends BaseModel {
})
version;
@attr('string', {
@attr({
description: 'Plugin information for this resource.',
readOnly: true,
})
+16
View File
@@ -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;
}
}
@@ -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;
}
},
});
@@ -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');
@@ -56,11 +56,23 @@
<p>{{hostCatalog.description}}</p>
</row.headerCell>
<row.cell>
<Rose::Badge>
{{t
(concat 'resources.host-catalog.types.' hostCatalog.type)
}}
</Rose::Badge>
{{#if hostCatalog.isStatic}}
<Rose::Badge>
{{t
(concat 'resources.host-catalog.types.' hostCatalog.type)
}}
</Rose::Badge>
{{else}}
<Rose::Badge
@icon={{concat
'flight-icons/svg/'
hostCatalog.compositeType
'-color-16'
}}
>
{{hostCatalog.compositeType}}
</Rose::Badge>
{{/if}}
</row.cell>
<row.cell>
<Copyable