Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: Add 'Scenario' debug function for easy saving debug scenarios #9675

Merged
merged 4 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions ui/packages/consul-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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

Expand Down
27 changes: 26 additions & 1 deletion ui/packages/consul-ui/app/utils/get-environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
`<body><pre>${location.href}#${str}</pre><br /><a href="javascript:Scenario('${str}')">Scenario</a></body>`
);
}
};
if (
typeof win.location !== 'undefined' &&
typeof win.location.hash === 'string' &&
win.location.hash.length > 0
) {
doc.cookie = win.location.hash.substr(1);
win.Scenario(win.location.hash.substr(1));
}
});
const dev = function(str = doc.cookie) {
Expand Down