From 61d7acd51f31860904c2c050718d6fae0c020da9 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Fri, 21 Jan 2022 11:42:48 +0000 Subject: [PATCH] ui: Tweak some code related meta information (#12117) * ui: Correct some meta info * Encoder doesn't take an argument whereas decoder does * Math.trunc looks like the closest to parseInt but using the correct type * use a dynamic string when setting things on window --- ui/packages/consul-ui/app/utils/btoa.js | 4 ++-- ui/packages/consul-ui/app/utils/get-environment.js | 8 +++++--- ui/packages/consul-ui/app/utils/keyToArray.js | 6 +++--- ui/packages/consul-ui/app/utils/maybe-call.js | 2 +- ui/packages/consul-ui/app/utils/merge-checks.js | 8 ++++---- ui/packages/consul-ui/app/utils/routing/walk.js | 2 +- ui/packages/consul-ui/app/utils/tomography.js | 6 +++--- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/ui/packages/consul-ui/app/utils/btoa.js b/ui/packages/consul-ui/app/utils/btoa.js index 76a3844605..5da689afd2 100644 --- a/ui/packages/consul-ui/app/utils/btoa.js +++ b/ui/packages/consul-ui/app/utils/btoa.js @@ -1,6 +1,6 @@ import base64js from 'base64-js'; -export default function(str, encoding = 'utf-8') { +export default function(str) { // encode - const bytes = new TextEncoder(encoding).encode(str); + const bytes = new TextEncoder().encode(str); return base64js.fromByteArray(bytes); } diff --git a/ui/packages/consul-ui/app/utils/get-environment.js b/ui/packages/consul-ui/app/utils/get-environment.js index 3967395b12..d350ca6ecf 100644 --- a/ui/packages/consul-ui/app/utils/get-environment.js +++ b/ui/packages/consul-ui/app/utils/get-environment.js @@ -23,7 +23,7 @@ export default function(config = {}, win = window, doc = document) { .startsWith('CONSUL_') ); }; - win.Scenario = function(str = '') { + win['Scenario'] = function(str = '') { if (str.length > 0) { cookies(str).forEach(item => (doc.cookie = `${item};Path=/`)); win.location.hash = ''; @@ -41,7 +41,7 @@ export default function(config = {}, win = window, doc = document) { typeof win.location.hash === 'string' && win.location.hash.length > 0 ) { - win.Scenario(win.location.hash.substr(1)); + win['Scenario'](win.location.hash.substr(1)); } }); const dev = function(str = doc.cookie) { @@ -107,7 +107,9 @@ export default function(config = {}, win = window, doc = document) { case 'CONSUL_DATACENTER_PRIMARY': return operatorConfig.PrimaryDatacenter; case 'CONSUL_UI_CONFIG': - dashboards = {}; + dashboards = { + service: undefined + }; provider = env('CONSUL_METRICS_PROVIDER'); proxy = env('CONSUL_METRICS_PROXY_ENABLED'); dashboards.service = env('CONSUL_SERVICE_DASHBOARD_URL'); diff --git a/ui/packages/consul-ui/app/utils/keyToArray.js b/ui/packages/consul-ui/app/utils/keyToArray.js index f5fb26944a..47ac074499 100644 --- a/ui/packages/consul-ui/app/utils/keyToArray.js +++ b/ui/packages/consul-ui/app/utils/keyToArray.js @@ -3,9 +3,9 @@ * an array. If the key name is simply the separator (for example '/') * then the array should contain a single empty string value * - * @param {string} key - The separated path/key - * @param {string} [separator=/] - The separator - * @returns {string[]} + * @param {String} key - The separated path/key + * @param {String} separator - The separator + * @returns {String[]} */ export default function(key, separator = '/') { return (key === separator ? '' : key).split(separator); diff --git a/ui/packages/consul-ui/app/utils/maybe-call.js b/ui/packages/consul-ui/app/utils/maybe-call.js index 33f73bc22d..de501b6d56 100644 --- a/ui/packages/consul-ui/app/utils/maybe-call.js +++ b/ui/packages/consul-ui/app/utils/maybe-call.js @@ -2,7 +2,7 @@ * Promise aware conditional function call * * @param {function} cb - The function to possibily call - * @param {function} [what] - A function returning a boolean resolving promise + * @param {Promise} [what] - A boolean resolving promise * @returns {function} - function when called returns a Promise that resolves the argument it is called with */ export default function(cb, what) { diff --git a/ui/packages/consul-ui/app/utils/merge-checks.js b/ui/packages/consul-ui/app/utils/merge-checks.js index 0551ffbb5d..99b33feb4b 100644 --- a/ui/packages/consul-ui/app/utils/merge-checks.js +++ b/ui/packages/consul-ui/app/utils/merge-checks.js @@ -8,10 +8,10 @@ import MultiMap from 'mnemonist/multi-map'; * proxy is likely to be on the same node, without adding something extra here * the node check will likely end up in the list twice. * - * @param {array} checks - Multiple lists of healthchecks to merge each one of the items in this array should be a further array of healthchecks - * @param {boolean} exposed - Whether the checks should be marked as exposed via the proxy or not - * @param {class} MMap - A MultiMap class. This is only exposed to allow for an easier interface but still allow an innjectable MultiMap if we choose to do that during testing - * @returns {array} - The final array of all of the healthchecks with any duplicate node checks removed, and also marked as exposed if required + * @param {Array} checks - Multiple lists of healthchecks to merge each one of the items in this array should be a further array of healthchecks + * @param {Boolean} exposed - Whether the checks should be marked as exposed via the proxy or not + * @param {Object} MMap - A MultiMap class. This is only exposed to allow for an easier interface but still allow an injectable MultiMap if we choose to do that during testing + * @returns {Array} - The final array of all of the healthchecks with any duplicate node checks removed, and also marked as exposed if required */ export default (checks = [], exposed = false, MMap = MultiMap) => { const ids = new MMap(); diff --git a/ui/packages/consul-ui/app/utils/routing/walk.js b/ui/packages/consul-ui/app/utils/routing/walk.js index 82bccb5065..0eef8a71c2 100644 --- a/ui/packages/consul-ui/app/utils/routing/walk.js +++ b/ui/packages/consul-ui/app/utils/routing/walk.js @@ -37,7 +37,7 @@ export default function(routes) { }; } -export let dump = () => {}; +export let dump = (routes) => {}; runInDebug(() => { const indent = function(num) { diff --git a/ui/packages/consul-ui/app/utils/tomography.js b/ui/packages/consul-ui/app/utils/tomography.js index 4f9611086d..137bc1dcb4 100644 --- a/ui/packages/consul-ui/app/utils/tomography.js +++ b/ui/packages/consul-ui/app/utils/tomography.js @@ -44,9 +44,9 @@ export default function(distance) { } return { distances: distances, - min: parseInt(min * 100) / 100, - median: parseInt(median * 100) / 100, - max: parseInt(max * 100) / 100, + min: Math.trunc(min * 100) / 100, + median: Math.trunc(median * 100) / 100, + max: Math.trunc(max * 100) / 100, }; }; }