Merge pull request #186 from hashicorp/chore-target-port

chore: 🤖 add target default_port field to API and UI
This commit is contained in:
Susmitha Girumala authored and GitHub committed 2020-09-15 17:33:09 -04:00
commit bde5609209
7 files changed
+59 -7

No files matched your search

@@ -0,0 +1,10 @@
import Fragment from 'ember-data-model-fragments/fragment';
import { attr } from '@ember-data/model';
export default class FragmentTargetAttributesModel extends Fragment {
@attr('number', {
description: 'The default port a target should use if present.'
}) default_port;
}
+7 -1
View File
@@ -1,11 +1,17 @@
import GeneratedTargetModel from '../generated/models/target';
import { fragmentArray } from 'ember-data-model-fragments/attributes';
import { fragment, fragmentArray } from 'ember-data-model-fragments/attributes';
import { computed } from '@ember/object';
export default class TargetModel extends GeneratedTargetModel {
// =attributes
/**
* Attributes of this resource, if any, represented as a JSON fragment.
* @type {FragmentTargetAttributesModel}
*/
@fragment('fragment-target-attributes', { defaultValue: {} }) attributes;
/**
* @type {[FragmentHostSetModel]}
*/
@@ -0,0 +1 @@
export { default } from 'api/models/fragment-target-attributes';
@@ -30,7 +30,10 @@ module('Unit | Serializer | target', function(hooks) {
description: 'Description',
version: 1,
type: 'tcp',
scope_id: 'org_1'
scope_id: 'org_1',
attributes: {
default_port: null
}
});
});
+22 -5
View File
@@ -14,11 +14,10 @@
<form.input
@name="name"
@type="name"
@type="text"
@value={{@model.name}}
@label={{t "form.label.name"}}
@error={{@model.errors.name}}
readonly={{false}}
as |field|>
{{#if @model.errors.name}}
<field.errors as |errors|>
@@ -31,12 +30,10 @@
<form.textarea
@name="description"
@type="description"
@type="text"
@value={{@model.description}}
@label={{t "form.label.description"}}
@error={{@model.errors.description}}
disabled={{@model.isSaving}}
readonly={{false}}
as |field|>
{{#if @model.errors.description}}
<field.errors as |errors|>
@@ -47,6 +44,26 @@
{{/if}}
</form.textarea>
{{!-- TODO this is a type-specific field --}}
<form.input
@name="default_port"
@type="number"
@value={{@model.attributes.default_port}}
@label={{t "form.label.default_port"}}
@error={{@model.errors.default_port}}
min="0"
step="1"
as |field|>
{{!-- TODO need to figure out how to reference `attributes.errors` here --}}
{{#if @model.errors.default_port}}
<field.errors as |errors|>
{{#each @model.errors.default_port as |error|}}
<errors.message>{{error.message}}</errors.message>
{{/each}}
</field.errors>
{{/if}}
</form.input>
<form.actions
@disabled={{if @model.cannotSave @model.cannotSave}}
@submitText={{t "actions.save"}}
+14
View File
@@ -1,11 +1,25 @@
import factory from '../generated/factories/target';
import { trait } from 'ember-cli-mirage';
import { random } from 'faker';
const randomBoolean = (chance = 0.5) => Math.random() < chance;
const hostSetChance = 0.3;
export default factory.extend({
/**
* Generates attributes fields by type.
*/
afterCreate(target) {
if (target.type === 'tcp') {
target.update({
attributes: {
default_port: random.number()
}
});
}
},
/**
* Randomly selects existing host sets to assign to target.
*/
+1
View File
@@ -140,6 +140,7 @@ form:
address: Address
protocol: Protocol
actions: Actions
default_port: Default Port
errors:
titles:
unauthenticated-error: You are not signed in