From 777dcf773bbe8555da6642b3552139fb67671999 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Mon, 1 Feb 2021 10:53:39 +0000 Subject: [PATCH 1/4] ui: Add 'Scenario' debug function for easy saving debug scenarios --- .../consul-ui/app/utils/get-environment.js | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/ui/packages/consul-ui/app/utils/get-environment.js b/ui/packages/consul-ui/app/utils/get-environment.js index 468556150ca6..748dd5c4a36b 100644 --- a/ui/packages/consul-ui/app/utils/get-environment.js +++ b/ui/packages/consul-ui/app/utils/get-environment.js @@ -11,12 +11,37 @@ export default function(config = {}, win = window, doc = document) { // look at the hash in the URL and transfer anything after the hash into // cookies to enable linking of the UI with various settings enabled runInDebug(() => { + const cookies = function(str) { + return str + .split(';') + .map(item => item.trim()) + .filter(item => item !== '') + .filter(item => + item + .split('=') + .shift() + .startsWith('CONSUL_') + ); + }; + window.Scenario = function(str = '') { + if (str.length > 0) { + cookies(str).forEach(item => (doc.cookie = `${item};Path=/`)); + win.location.hash = ''; + location.reload(); + } else { + str = cookies(doc.cookie).join(';'); + const tab = window.open('', '_blank'); + tab.document.write( + `
${location.href}#${str}

Scenario` + ); + } + }; if ( typeof win.location !== 'undefined' && typeof win.location.hash === 'string' && win.location.hash.length > 0 ) { - doc.cookie = win.location.hash.substr(1); + Scenario(win.location.hash.substr(1)); } }); const dev = function(str = doc.cookie) { From 7b57d4f4765e57ae4f1d3ed283fd099113457bd9 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Mon, 1 Feb 2021 12:37:48 +0000 Subject: [PATCH 2/4] Use win for accessing Scenario --- ui/packages/consul-ui/app/utils/get-environment.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/packages/consul-ui/app/utils/get-environment.js b/ui/packages/consul-ui/app/utils/get-environment.js index 748dd5c4a36b..04e252ac5cdf 100644 --- a/ui/packages/consul-ui/app/utils/get-environment.js +++ b/ui/packages/consul-ui/app/utils/get-environment.js @@ -23,14 +23,14 @@ export default function(config = {}, win = window, doc = document) { .startsWith('CONSUL_') ); }; - window.Scenario = function(str = '') { + win.Scenario = function(str = '') { if (str.length > 0) { cookies(str).forEach(item => (doc.cookie = `${item};Path=/`)); win.location.hash = ''; location.reload(); } else { str = cookies(doc.cookie).join(';'); - const tab = window.open('', '_blank'); + const tab = win.open('', '_blank'); tab.document.write( `
${location.href}#${str}

Scenario` ); @@ -41,7 +41,7 @@ export default function(config = {}, win = window, doc = document) { typeof win.location.hash === 'string' && win.location.hash.length > 0 ) { - Scenario(win.location.hash.substr(1)); + win.Scenario(win.location.hash.substr(1)); } }); const dev = function(str = doc.cookie) { From bc651250623ffc133c11864e8669e1f69f530493 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Mon, 1 Feb 2021 17:33:47 +0000 Subject: [PATCH 3/4] Add to the README --- ui/packages/consul-ui/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/packages/consul-ui/README.md b/ui/packages/consul-ui/README.md index 1fb5fbeae7eb..7a7bebbce5bf 100644 --- a/ui/packages/consul-ui/README.md +++ b/ui/packages/consul-ui/README.md @@ -144,6 +144,7 @@ URLs i.e. `javascript:Routes()` | Variable | Arguments | Description | | -------- | --------- | ----------- | | `Routes(url)` | url: The url to pass the DSL to, if left `undefined` just use a blank tab | Provides a way to easily print out Embers Route DSL for the application or to pass it straight to any third party utility such as ember-diagonal | +| `Scenario(str)` | str: 'Cookie formatted' string, if left `undefined` open a new tab with a lonk to the current Scenario | Provides a way to easily save and reload scenarios of configurations via URLs or bookmarklets | ### Code Generators From b190b7a72dfba6bf853c1452bc89b25afaae2023 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Mon, 1 Feb 2021 17:34:50 +0000 Subject: [PATCH 4/4] Fix typo --- ui/packages/consul-ui/README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ui/packages/consul-ui/README.md b/ui/packages/consul-ui/README.md index 7a7bebbce5bf..31c851ccf958 100644 --- a/ui/packages/consul-ui/README.md +++ b/ui/packages/consul-ui/README.md @@ -128,9 +128,7 @@ token/secret. | `CONSUL_EXPOSED_COUNT` | (random) | Configure the number of exposed paths that the API returns. | | `CONSUL_CHECK_COUNT` | (random) | Configure the number of health checks that the API returns. | | `CONSUL_OIDC_PROVIDER_COUNT` | (random) | Configure the number of OIDC providers that the API returns. | -| `DEBUG_ROUTES_ENDPOINT` | undefined | When using the window.Routes() debug -utility ([see utility functions](#browser-debug-utility-functions)), use a URL to pass the route DSL to. %s in the URL will be replaced -with the route DSL - http://url.com?routes=%s | +| `DEBUG_ROUTES_ENDPOINT` | undefined | When using the window.Routes() debug utility ([see utility functions](#browser-debug-utility-functions)), use a URL to pass the route DSL to. %s in the URL will be replaced with the route DSL - http://url.com?routes=%s | See `./mock-api` for more details. @@ -144,7 +142,7 @@ URLs i.e. `javascript:Routes()` | Variable | Arguments | Description | | -------- | --------- | ----------- | | `Routes(url)` | url: The url to pass the DSL to, if left `undefined` just use a blank tab | Provides a way to easily print out Embers Route DSL for the application or to pass it straight to any third party utility such as ember-diagonal | -| `Scenario(str)` | str: 'Cookie formatted' string, if left `undefined` open a new tab with a lonk to the current Scenario | Provides a way to easily save and reload scenarios of configurations via URLs or bookmarklets | +| `Scenario(str)` | str: 'Cookie formatted' string, if left `undefined` open a new tab with a link/bookmarklet to the current Scenario | Provides a way to easily save and reload scenarios of configurations via URLs or bookmarklets | ### Code Generators