From 10c90171c9ca23e460080a228a52d5edde7ef834 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Tue, 10 Nov 2020 14:36:27 +0000 Subject: [PATCH] ui: Remove unnecessay reopens from sort and form services (#9146) --- .../consul-ui/app/initializers/form.js | 46 ----------------- .../consul-ui/app/initializers/sort.js | 36 ------------- ui/packages/consul-ui/app/services/form.js | 51 +++++++++++++++---- ui/packages/consul-ui/app/services/sort.js | 27 +++++++++- 4 files changed, 66 insertions(+), 94 deletions(-) delete mode 100644 ui/packages/consul-ui/app/initializers/form.js delete mode 100644 ui/packages/consul-ui/app/initializers/sort.js diff --git a/ui/packages/consul-ui/app/initializers/form.js b/ui/packages/consul-ui/app/initializers/form.js deleted file mode 100644 index 91f5e0bfb..000000000 --- a/ui/packages/consul-ui/app/initializers/form.js +++ /dev/null @@ -1,46 +0,0 @@ -import { get, set } from '@ember/object'; - -import kv from 'consul-ui/forms/kv'; -import acl from 'consul-ui/forms/acl'; -import token from 'consul-ui/forms/token'; -import policy from 'consul-ui/forms/policy'; -import role from 'consul-ui/forms/role'; -import intention from 'consul-ui/forms/intention'; -import nspace from 'consul-ui/forms/nspace'; - -export function initialize(application) { - // Service-less injection using private properties at a per-project level - const FormBuilder = application.resolveRegistration('service:form'); - const forms = { - kv: kv, - acl: acl, - token: token, - policy: policy, - role: role, - intention: intention, - nspace: nspace, - }; - FormBuilder.reopen({ - form: function(name) { - let form = get(this.forms, name); - if (!form) { - form = set(this.forms, name, forms[name](this)); - // only do special things for our new things for the moment - if (name === 'role' || name === 'policy') { - const repo = get(this, name); - form.clear(function(obj) { - return repo.create(obj); - }); - form.submit(function(obj) { - return repo.persist(obj); - }); - } - } - return form; - }, - }); -} - -export default { - initialize, -}; diff --git a/ui/packages/consul-ui/app/initializers/sort.js b/ui/packages/consul-ui/app/initializers/sort.js deleted file mode 100644 index 1f30f55b0..000000000 --- a/ui/packages/consul-ui/app/initializers/sort.js +++ /dev/null @@ -1,36 +0,0 @@ -import service from 'consul-ui/sort/comparators/service'; -import serviceInstance from 'consul-ui/sort/comparators/service-instance'; -import kv from 'consul-ui/sort/comparators/kv'; -import check from 'consul-ui/sort/comparators/check'; -import intention from 'consul-ui/sort/comparators/intention'; -import token from 'consul-ui/sort/comparators/token'; -import role from 'consul-ui/sort/comparators/role'; -import policy from 'consul-ui/sort/comparators/policy'; -import nspace from 'consul-ui/sort/comparators/nspace'; -import node from 'consul-ui/sort/comparators/node'; - -export function initialize(container) { - // Service-less injection using private properties at a per-project level - const Sort = container.resolveRegistration('service:sort'); - const comparators = { - service: service(), - serviceInstance: serviceInstance(), - kv: kv(), - check: check(), - intention: intention(), - token: token(), - role: role(), - policy: policy(), - nspace: nspace(), - node: node(), - }; - Sort.reopen({ - comparator: function(type) { - return comparators[type]; - }, - }); -} - -export default { - initialize, -}; diff --git a/ui/packages/consul-ui/app/services/form.js b/ui/packages/consul-ui/app/services/form.js index 4e387d227..3c40b4c20 100644 --- a/ui/packages/consul-ui/app/services/form.js +++ b/ui/packages/consul-ui/app/services/form.js @@ -1,27 +1,56 @@ import Service, { inject as service } from '@ember/service'; import builderFactory from 'consul-ui/utils/form/builder'; + +import kv from 'consul-ui/forms/kv'; +import acl from 'consul-ui/forms/acl'; +import token from 'consul-ui/forms/token'; +import policy from 'consul-ui/forms/policy'; +import role from 'consul-ui/forms/role'; +import intention from 'consul-ui/forms/intention'; +import nspace from 'consul-ui/forms/nspace'; + const builder = builderFactory(); + +const forms = { + kv: kv, + acl: acl, + token: token, + policy: policy, + role: role, + intention: intention, + nspace: nspace, +}; + export default class FormService extends Service { // a `get` method is added via the form initializer // see initializers/form.js // TODO: Temporarily add these here until something else needs // dynamic repos - @service('repository/role') - role; - - @service('repository/policy') - policy; - + @service('repository/role') role; + @service('repository/policy') policy; // - init() { - super.init(...arguments); - this.forms = []; - } + forms = []; build(obj, name) { return builder(...arguments); } - form() {} + form(name) { + let form = this.forms[name]; + if (typeof form === 'undefined') { + form = this.forms[name] = forms[name](this); + // only do special things for our new things for the moment + if (name === 'role' || name === 'policy') { + const repo = this[name]; + form.clear(function(obj) { + return repo.create(obj); + }); + form.submit(function(obj) { + return repo.persist(obj); + }); + } + } + return form; + } } diff --git a/ui/packages/consul-ui/app/services/sort.js b/ui/packages/consul-ui/app/services/sort.js index 69d28260e..c18cff2a9 100644 --- a/ui/packages/consul-ui/app/services/sort.js +++ b/ui/packages/consul-ui/app/services/sort.js @@ -1,4 +1,29 @@ import Service from '@ember/service'; +import service from 'consul-ui/sort/comparators/service'; +import serviceInstance from 'consul-ui/sort/comparators/service-instance'; +import kv from 'consul-ui/sort/comparators/kv'; +import check from 'consul-ui/sort/comparators/check'; +import intention from 'consul-ui/sort/comparators/intention'; +import token from 'consul-ui/sort/comparators/token'; +import role from 'consul-ui/sort/comparators/role'; +import policy from 'consul-ui/sort/comparators/policy'; +import nspace from 'consul-ui/sort/comparators/nspace'; +import node from 'consul-ui/sort/comparators/node'; + +const comparators = { + service: service(), + serviceInstance: serviceInstance(), + kv: kv(), + check: check(), + intention: intention(), + token: token(), + role: role(), + policy: policy(), + nspace: nspace(), + node: node(), +}; export default class SortService extends Service { - comparator(type) {} + comparator(type) { + return comparators[type]; + } }