resolve conflict

This commit is contained in:
dharini committed 2022-02-14 19:02:00 -08:00
commit 4c7f92f035
20 files changed
+182 -178

No files matched your search

@@ -39,11 +39,6 @@ export default class GeneratedHostCatalogModel extends BaseModel {
})
disabled;
@attr({
description: 'Attributes specific to the catalog type',
})
attributes;
@attr('number', {
description: 'Current version number of this resource.',
})
+12 -1
View File
@@ -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';
}
/**
+9 -14
View File
@@ -234,11 +234,13 @@ export default class ApplicationSerializer extends RESTSerializer {
*/
normalizeNestedAttributes(typeClass, hash) {
typeClass.attributes.forEach((attribute) => {
const { isNestedAttribute } = attribute.options;
const attributeValue = hash.attributes?.[attribute.name];
if (isNestedAttribute && typeof attributeValue != 'undefined') {
hash[attribute.name] = attributeValue;
}
const {
name,
options: { isNestedAttribute },
} = attribute;
const value = hash.attributes?.[name];
const isUndefined = value === undefined;
if (isNestedAttribute && !isUndefined) hash[name] = value;
});
return hash;
}
@@ -261,15 +263,8 @@ export default class ApplicationSerializer extends RESTSerializer {
name,
options: { isNestedSecret },
} = attribute;
const attributeValue = hash.secrets?.[name];
// FIXME: This could be improved
if (isNestedSecret) {
hash[name] = null;
if (typeof attributeValue != 'undefined') {
hash[name] = attributeValue;
}
}
const value = hash.secrets?.[name];
if (isNestedSecret) hash[name] = value || null;
});
return hash;
}
@@ -1,5 +1,4 @@
import ApplicationSerializer from './application';
import { copy } from 'ember-copy';
const fieldsByType = {
aws: [
@@ -57,11 +56,4 @@ export default class HostCatalogSerializer extends ApplicationSerializer {
delete serialized.secrets;
return serialized;
}
normalize(typeClass, hash, ...rest) {
let normalizedHash = copy(hash, true);
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
delete normalized.data.attributes.attributes;
return normalized;
}
}
@@ -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');
});
@@ -78,6 +78,75 @@
<Rose::Form::Fieldset>
<:title>{{t 'form.provider.filter.label'}}</:title>
<:description>{{t 'form.provider.filter.help'}}</:description>
<:body>
{{#if @model.errors.filters}}
<Rose::Form::Errors as |errors|>
{{#each @model.errors.filters as |error|}}
<errors.message>{{error.message}}</errors.message>
{{/each}}
</Rose::Form::Errors>
{{/if}}
<Rose::Table @style='condensed' as |table|>
<table.header as |header|>
<header.row @hidden={{true}} as |row|>
<row.headerCell>{{t 'titles.value'}}</row.headerCell>
<row.headerCell />
</header.row>
</table.header>
<table.body as |body|>
{{#each @model.filters as |filter i|}}
<body.row as |row|>
<row.cell>
<form.input
@type='text'
@value={{filter.value}}
@error={{@model.errors.filters}}
@contextual={{true}}
as |field|
>
<field.field />
</form.input>
</row.cell>
<row.cell @shrink={{true}}>
<Rose::Button
@style='warning'
@iconOnly='flight-icons/svg/trash-16'
title={{t 'actions.remove'}}
@disabled={{if
@model.isNew
false
(if form.isEditable false true)
}}
{{on 'click' (fn @removeItemByIndex 'filters' i)}}
>
{{t 'actions.remove'}}
</Rose::Button>
</row.cell>
</body.row>
{{/each}}
<body.row as |row|>
<row.cell>
<form.input @type='text' @value={{@model.filter}} />
</row.cell>
<row.cell @shrink={{true}}>
<Rose::Button
@style='secondary'
title={{t 'actions.add'}}
@disabled={{if
@model.isNew
false
(if form.isEditable false true)
}}
{{on 'click' (fn @addStringItem 'filters' @model.filter)}}
>
{{t 'actions.add'}}
</Rose::Button>
</row.cell>
</body.row>
</table.body>
</Rose::Table>
</:body>
</Rose::Form::Fieldset>
{{#if (can 'save model' @model)}}
@@ -78,6 +78,7 @@
<form.textarea
@name='filter'
@type='filter'
@value={{@model.filter}}
@label={{t 'form.provider.filter.label'}}
@helperText={{t 'form.provider.filter.help'}}
@linkText={{t 'form.provider.filter.link-text'}}
@@ -3,4 +3,6 @@
model=@model
submit=@submit
cancel=@cancel
removeItemByIndex=@removeItemByIndex
addStringItem=@addStringItem
}}
@@ -56,16 +56,16 @@
<form.input
@name='address'
@type='text'
@value={{@model.attributes.address}}
@value={{@model.address}}
@label={{t 'form.address.label'}}
@error={{@model.errors.name}}
@error={{@model.errors.address}}
@helperText={{t 'form.address.help'}}
readonly={{false}}
as |field|
>
{{#if @model.errors.name}}
{{#if @model.errors.address}}
<field.errors as |errors|>
{{#each @model.errors.name as |error|}}
{{#each @model.errors.address as |error|}}
<errors.message>{{error.message}}</errors.message>
{{/each}}
</field.errors>
@@ -33,33 +33,9 @@
/>
</row.cell>
<row.cell>{{hostSet.name}}</row.cell>
{{#if hostSet.isPlugin}}
<Rose::Badge
@icon={{concat
'flight-icons/svg/'
hostSet.compositeType
'-color-16'
}}
>
{{t
(concat
'resources.host-catalog.types.'
hostSet.compositeType
'.label'
)
}}
</Rose::Badge>
{{else}}
<Rose::Badge>
{{t
(concat
'resources.host-catalog.types.'
hostSet.compositeType
'.label'
)
}}
</Rose::Badge>
{{/if}}
<row.cell>
<HostCatalogTypeBadge @model={{hostSet}} />
</row.cell>
<row.cell>
<code>{{hostSet.host_catalog_id}}</code>
</row.cell>
@@ -0,0 +1,15 @@
{{#if @model.isStatic}}
<Rose::Badge>
{{t (concat 'resources.host-catalog.types.' @model.compositeType '.label')}}
</Rose::Badge>
{{else if @model.isUnknown}}
<Rose::Badge>
{{t (concat 'resources.host-catalog.types.' @model.compositeType '.label')}}
</Rose::Badge>
{{else}}
<Rose::Badge
@icon={{concat 'flight-icons/svg/' @model.compositeType '-color-16'}}
>
{{t (concat 'resources.host-catalog.types.' @model.compositeType '.label')}}
</Rose::Badge>
{{/if}}
@@ -1,4 +1,5 @@
import Route from '@ember/routing/route';
import { action } from '@ember/object';
export default class ScopesScopeHostCatalogsHostCatalogHostSetsHostSetRoute extends Route {
// =methods
@@ -49,4 +50,30 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsHostSetRoute exte
}
);
}
/**
* Adds a string item to array `property` on the passed `filter`.
* @param {hostSetModel} hostSet
* @param {string} property
* @param {string} value
*/
@action
async addStringItem(hostSet, property, value) {
const array = hostSet.get(property);
array.addObject({ value });
}
/**
* Removes an item from array `property` at `index` on the
* passed `hostSet`.
* @param {hostSetModel} hostSet
* @param {string} property
* @param {number} index
*/
@action
async removeItemByIndex(hostSet, property, index) {
const array = hostSet.get(property);
array.removeAt(index);
}
}
@@ -63,4 +63,28 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsNewRoute extends
async changeType(type) {
await this.router.replaceWith({ queryParams: { type } });
}
/**
* Adds a string item to array `property` on the passed `filter`.
* @param {hostSetModel} hostSet
* @param {string} property
* @param {string} value
*/
@action
async addStringItem(hostSet, property, value) {
const array = hostSet.get(property);
array.addObject({ value });
}
/**
* Removes an item from array `property` at `index` on the
* passed `hostSet`.
* @param {hostSetModel} hostSet
* @param {string} property
* @param {number} index
*/
@action
async removeItemByIndex(hostSet, property, index) {
const array = hostSet.get(property);
array.removeAt(index);
}
}
@@ -26,29 +26,7 @@
<p>{{host.description}}</p>
</row.headerCell>
<row.cell>
{{#if host.isStatic}}
<Rose::Badge>
{{t
(concat
'resources.host-catalog.types.' host.compositeType '.label'
)
}}
</Rose::Badge>
{{else}}
<Rose::Badge
@icon={{concat
'flight-icons/svg/'
host.compositeType
'-color-16'
}}
>
{{t
(concat
'resources.host-catalog.types.' host.compositeType '.label'
)
}}
</Rose::Badge>
{{/if}}
<HostCatalogTypeBadge @model={{host}} />
</row.cell>
<row.cell>
<Copyable
@@ -2,4 +2,6 @@
@model={{@model}}
@submit={{route-action 'save' @model}}
@cancel={{route-action 'cancel' @model}}
@removeItemByIndex={{route-action 'removeItemByIndex' @model}}
@addStringItem={{route-action 'addStringItem' @model}}
/>
@@ -25,33 +25,7 @@
<p>{{hostSet.description}}</p>
</row.headerCell>
<row.cell>
{{#if hostSet.isStatic}}
<Rose::Badge>
{{t
(concat
'resources.host-catalog.types.'
hostSet.compositeType
'.label'
)
}}
</Rose::Badge>
{{else}}
<Rose::Badge
@icon={{concat
'flight-icons/svg/'
hostSet.compositeType
'-color-16'
}}
>
{{t
(concat
'resources.host-catalog.types.'
hostSet.compositeType
'.label'
)
}}
</Rose::Badge>
{{/if}}
<HostCatalogTypeBadge @model={{hostSet}} />
</row.cell>
<row.cell>
<Copyable
@@ -5,4 +5,6 @@
@submit={{route-action 'save' @model}}
@cancel={{route-action 'cancel' @model}}
@changeType={{route-action 'changeType' @model.type}}
@removeItemByIndex={{route-action 'removeItemByIndex' @model}}
@addStringItem={{route-action 'addStringItem' @model}}
/>
@@ -61,7 +61,7 @@
</Copyable>
</row.cell>
<row.cell>
<code>{{host.attributes.address}}</code>
<code>{{host.address}}</code>
</row.cell>
</body.row>
{{/each}}
@@ -56,43 +56,7 @@
<p>{{hostCatalog.description}}</p>
</row.headerCell>
<row.cell>
{{#if hostCatalog.isStatic}}
<Rose::Badge>
{{t
(concat
'resources.host-catalog.types.'
hostCatalog.compositeType
'.label'
)
}}
</Rose::Badge>
{{else if hostCatalog.isUnknown}}
<Rose::Badge>
{{t
(concat
'resources.host-catalog.types.'
hostCatalog.compositeType
'.label'
)
}}
</Rose::Badge>
{{else}}
<Rose::Badge
@icon={{concat
'flight-icons/svg/'
hostCatalog.compositeType
'-color-16'
}}
>
{{t
(concat
'resources.host-catalog.types.'
hostCatalog.compositeType
'.label'
)
}}
</Rose::Badge>
{{/if}}
<HostCatalogTypeBadge @model={{hostCatalog}} />
</row.cell>
<row.cell>
<Copyable
@@ -38,34 +38,7 @@
<p>{{hostSet.model.description}}</p>
</row.headerCell>
<row.cell>
{{#if hostSet.model.isPlugin}}
<Rose::Badge
@icon={{concat
'flight-icons/svg/'
hostSet.model.compositeType
'-color-16'
}}
>
{{t
(concat
'resources.host-catalog.types.'
hostSet.model.compositeType
'.label'
)
}}
</Rose::Badge>
{{else}}
<Rose::Badge>
{{t
(concat
'resources.host-catalog.types.'
hostSet.model.compositeType
'.label'
)
}}
</Rose::Badge>
{{/if}}
<HostCatalogTypeBadge @model={{hostSet.model}} />
</row.cell>
<row.cell>
<Copyable