diff --git a/ui/packages/consul-ui/README.md b/ui/packages/consul-ui/README.md index 1fb5fbeae..31c851ccf 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,6 +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 link/bookmarklet to the current Scenario | Provides a way to easily save and reload scenarios of configurations via URLs or bookmarklets | ### Code Generators diff --git a/ui/packages/consul-ui/app/utils/get-environment.js b/ui/packages/consul-ui/app/utils/get-environment.js index 468556150..04e252ac5 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_') + ); + }; + 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 = win.open('', '_blank'); + tab.document.write( + `
${location.href}#${str}