mirror of https://github.com/hashicorp/consul
ui: Previously we were passing through 'fake' events, revert to real.. (#5810)
Previously we were creating a fake event and amending the name of the fake event, this meant that other `event.target` properties weren't being passed through (in this instance `checked`) this changes the approach to not use fake events, and allows you to overwrite the name that the form uses for `handleEvent`pull/5816/head
parent
d22ac2a5c2
commit
077d70ff44
|
@ -23,16 +23,24 @@ export default Component.extend(WithListeners, SlotsMixin, {
|
||||||
actions: {
|
actions: {
|
||||||
change: function(e, value, item) {
|
change: function(e, value, item) {
|
||||||
let event = get(this, 'dom').normalizeEvent(e, value);
|
let event = get(this, 'dom').normalizeEvent(e, value);
|
||||||
|
// currently form-components don't deal with deeply nested forms, only top level
|
||||||
|
// we therefore grab the end of the nest off here,
|
||||||
|
// so role[policy][Rules] will end up as policy[Rules]
|
||||||
|
// but also policy[Rules] will end up as Rules
|
||||||
|
// for now we look for a [ so we know whether this component is deeply
|
||||||
|
// nested or not and we pass the name through as an optional argument to handleEvent
|
||||||
|
// once this component handles deeply nested forms this can go
|
||||||
const matches = [...event.target.name.matchAll(propRe)];
|
const matches = [...event.target.name.matchAll(propRe)];
|
||||||
const prop = matches[matches.length - 1][0];
|
const prop = matches[matches.length - 1][0];
|
||||||
event = get(this, 'dom').normalizeEvent(
|
let name;
|
||||||
`${get(this, 'type')}[${prop}]`,
|
if (prop.indexOf('[') === -1) {
|
||||||
event.target.value,
|
name = `${get(this, 'type')}[${prop}]`;
|
||||||
event.target
|
} else {
|
||||||
);
|
name = prop;
|
||||||
|
}
|
||||||
const form = get(this, 'form');
|
const form = get(this, 'form');
|
||||||
try {
|
try {
|
||||||
form.handleEvent(event);
|
form.handleEvent(event, name);
|
||||||
this.onchange({ target: this });
|
this.onchange({ target: this });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err;
|
throw err;
|
||||||
|
|
|
@ -56,9 +56,11 @@ export default function(changeset = defaultChangeset, getFormNameProperty = pars
|
||||||
_children[child.getName()] = child;
|
_children[child.getName()] = child;
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
handleEvent: function(e) {
|
handleEvent: function(e, targetName) {
|
||||||
const target = e.target;
|
const target = e.target;
|
||||||
const parts = getFormNameProperty(target.name);
|
// currently we only use targetName in {{form-component}} for handling deeply
|
||||||
|
// nested forms, once {{form-component}} handles deeply nested forms targetName can go
|
||||||
|
const parts = getFormNameProperty(targetName || target.name);
|
||||||
// split the form element name from `name[prop]`
|
// split the form element name from `name[prop]`
|
||||||
const name = parts[0];
|
const name = parts[0];
|
||||||
const prop = parts[1];
|
const prop = parts[1];
|
||||||
|
|
|
@ -5,6 +5,7 @@ Feature: dc / acls / policies / update: ACL Policy Update
|
||||||
And 1 policy model from yaml
|
And 1 policy model from yaml
|
||||||
---
|
---
|
||||||
ID: policy-id
|
ID: policy-id
|
||||||
|
Datacenters: []
|
||||||
---
|
---
|
||||||
And 3 token models
|
And 3 token models
|
||||||
When I visit the policy page for yaml
|
When I visit the policy page for yaml
|
||||||
|
@ -21,12 +22,16 @@ Feature: dc / acls / policies / update: ACL Policy Update
|
||||||
Description: [Description]
|
Description: [Description]
|
||||||
Rules: [Rules]
|
Rules: [Rules]
|
||||||
---
|
---
|
||||||
|
And I click validDatacenters
|
||||||
|
And I click datacenter
|
||||||
And I submit
|
And I submit
|
||||||
Then a PUT request is made to "/v1/acl/policy/policy-id?dc=datacenter" with the body from yaml
|
Then a PUT request is made to "/v1/acl/policy/policy-id?dc=datacenter" with the body from yaml
|
||||||
---
|
---
|
||||||
Name: [Name]
|
Name: [Name]
|
||||||
Description: [Description]
|
Description: [Description]
|
||||||
Rules: [Rules]
|
Rules: [Rules]
|
||||||
|
Datacenters:
|
||||||
|
- datacenter
|
||||||
---
|
---
|
||||||
Then the url should be /datacenter/acls/policies
|
Then the url should be /datacenter/acls/policies
|
||||||
And "[data-notification]" has the "notification-update" class
|
And "[data-notification]" has the "notification-update" class
|
||||||
|
|
|
@ -69,7 +69,7 @@ export default {
|
||||||
policies: create(
|
policies: create(
|
||||||
policies(visitable, deletable, creatable, clickable, attribute, collection, freetextFilter)
|
policies(visitable, deletable, creatable, clickable, attribute, collection, freetextFilter)
|
||||||
),
|
),
|
||||||
policy: create(policy(visitable, submitable, deletable, cancelable, tokenList)),
|
policy: create(policy(visitable, submitable, deletable, cancelable, clickable, tokenList)),
|
||||||
roles: create(
|
roles: create(
|
||||||
roles(visitable, deletable, creatable, clickable, attribute, collection, freetextFilter)
|
roles(visitable, deletable, creatable, clickable, attribute, collection, freetextFilter)
|
||||||
),
|
),
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
export default function(visitable, submitable, deletable, cancelable, tokenList) {
|
export default function(visitable, submitable, deletable, cancelable, clickable, tokenList) {
|
||||||
return {
|
return {
|
||||||
visit: visitable(['/:dc/acls/policies/:policy', '/:dc/acls/policies/create']),
|
visit: visitable(['/:dc/acls/policies/:policy', '/:dc/acls/policies/create']),
|
||||||
...submitable({}, 'form > div'),
|
...submitable({}, 'form > div'),
|
||||||
...cancelable({}, 'form > div'),
|
...cancelable({}, 'form > div'),
|
||||||
...deletable({}, 'form > div'),
|
...deletable({}, 'form > div'),
|
||||||
tokens: tokenList(),
|
tokens: tokenList(),
|
||||||
|
validDatacenters: clickable('[name="policy[isScoped]"]'),
|
||||||
|
datacenter: clickable('[name="policy[Datacenters]"]'),
|
||||||
deleteModal: {
|
deleteModal: {
|
||||||
resetScope: true,
|
resetScope: true,
|
||||||
scope: '[data-test-delete-modal]',
|
scope: '[data-test-delete-modal]',
|
||||||
|
|
Loading…
Reference in New Issue