diff --git a/ui/packages/consul-ui/app/components/data-form/index.hbs b/ui/packages/consul-ui/app/components/data-form/index.hbs index 1e1cb912e8..32c5658a1f 100644 --- a/ui/packages/consul-ui/app/components/data-form/index.hbs +++ b/ui/packages/consul-ui/app/components/data-form/index.hbs @@ -1,8 +1,28 @@ - + diff --git a/ui/packages/consul-ui/app/components/topology-metrics/stats/index.hbs b/ui/packages/consul-ui/app/components/topology-metrics/stats/index.hbs index a5ee66112e..b116a9bf7b 100644 --- a/ui/packages/consul-ui/app/components/topology-metrics/stats/index.hbs +++ b/ui/packages/consul-ui/app/components/topology-metrics/stats/index.hbs @@ -1,6 +1,15 @@ {{#if (not @noMetricsReason)}} diff --git a/ui/packages/consul-ui/app/helpers/render-template.js b/ui/packages/consul-ui/app/helpers/render-template.js index 8c743a8b80..57c006b84c 100644 --- a/ui/packages/consul-ui/app/helpers/render-template.js +++ b/ui/packages/consul-ui/app/helpers/render-template.js @@ -1,18 +1,19 @@ -import { helper } from '@ember/component/helper'; -import { get } from '@ember/object'; +import Helper from '@ember/component/helper'; +import { inject as service } from '@ember/service'; -// Covers alpha-capitalized dot separated API keys such as -// `{{Name}}`, `{{Service.Name}}` etc. but not `{{}}` +// simple mustache regexp `/{{item.Name}}/` const templateRe = /{{([A-Za-z.0-9_-]+)}}/g; -export default helper(function renderTemplate([template, vars]) { - if (typeof vars !== 'undefined' && typeof template !== 'undefined') { - return template.replace(templateRe, function(match, group) { - try { - return encodeURIComponent(get(vars, group) || ''); - } catch (e) { - return ''; - } - }); +let render; +export default class RenderTemplateHelper extends Helper { + @service('encoder') encoder; + constructor() { + super(...arguments); + if (typeof render !== 'function') { + render = this.encoder.createRegExpEncoder(templateRe, encodeURIComponent, false); + } } - return ''; -}); + + compute([template, vars]) { + return render(template, vars); + } +} diff --git a/ui/packages/consul-ui/app/helpers/uri.js b/ui/packages/consul-ui/app/helpers/uri.js index 46dd443d1b..8c3667ea11 100644 --- a/ui/packages/consul-ui/app/helpers/uri.js +++ b/ui/packages/consul-ui/app/helpers/uri.js @@ -1,10 +1,18 @@ import Helper from '@ember/component/helper'; import { inject as service } from '@ember/service'; +const templateRe = /\${([A-Za-z.0-9_-]+)}/g; +let render; export default class UriHelper extends Helper { @service('encoder') encoder; + constructor() { + super(...arguments); + if (typeof render !== 'function') { + render = this.encoder.createRegExpEncoder(templateRe, encodeURIComponent); + } + } - compute(params, hash) { - return this.encoder.uriJoin(params); + compute([template, vars]) { + return render(template, vars); } } diff --git a/ui/packages/consul-ui/app/services/encoder.js b/ui/packages/consul-ui/app/services/encoder.js index c9a6c135b9..12b2f71d97 100644 --- a/ui/packages/consul-ui/app/services/encoder.js +++ b/ui/packages/consul-ui/app/services/encoder.js @@ -1,10 +1,32 @@ import Service from '@ember/service'; +import { get } from '@ember/object'; +import { runInDebug } from '@ember/debug'; import atob from 'consul-ui/utils/atob'; import btoa from 'consul-ui/utils/btoa'; +const createRegExpEncoder = function(re, encoder = str => str, strict = true) { + return (template = '', vars = {}) => { + if (template !== '') { + return template.replace(re, (match, group) => { + const value = get(vars, group); + runInDebug(() => { + if (strict && typeof value === 'undefined') { + console.error(new Error(`${group} is undefined in ${template}`)); + } + }); + return encoder(value || ''); + }); + } + return ''; + }; +}; export default class EncoderService extends Service { uriComponent = encodeURIComponent; + createRegExpEncoder(re, encoder) { + return createRegExpEncoder(re, encoder); + } + atob() { return atob(...arguments); } diff --git a/ui/packages/consul-ui/app/templates/dc/services/show/intentions/index.hbs b/ui/packages/consul-ui/app/templates/dc/services/show/intentions/index.hbs index 4a27e352e1..7456e16c3c 100644 --- a/ui/packages/consul-ui/app/templates/dc/services/show/intentions/index.hbs +++ b/ui/packages/consul-ui/app/templates/dc/services/show/intentions/index.hbs @@ -1,4 +1,13 @@ - +