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: Adds a Routes() router DSL dumping function only in dev mode #9666

Merged
merged 1 commit into from
Feb 1, 2021

Conversation

johncowen
Copy link
Contributor

@johncowen johncowen commented Jan 29, 2021

Back in #5206 we fixed a URL encoding/decoding issues with URLs for wildcarded routes by extracting our routing configuration to a JSON-like JS pojo, before feeding this in Embers Route.map. This meant we could inspect the routing configuration from elsewhere to provide support for URL encoding/decoding. The one downside in doing this was that we were not using Embers Route DSL to code our Routing configuration.

At the time we wrote a little dump util in order to easily convert the JSON-like configuration back to Ember's Router DSL should we ever need to, but commented it out as we didn't want it ending up in the production source code.

We've since discovered runInDebug, which lets you specify inline code to be stripped from production builds.

This PR uses runInDebug to wrap the a utility function called Routes(), which will print out Embers Route DSL in a new tab should we need to. Passing a URL with a %s marker will pass the Route DSL to the URL, for example http://url.com?routes=%s, this lets you easily use tools like ember-diagonal. Additionally we've added a DEBUG_ROUTES_ENDPOINT development environment variable (set via cookies), so you can set this URL semi-permanently if you always want the DSL passed to a URL instead of opening in a new tab. We named it Routes() for now and hung it off of window for easy usage - we shouldn't have any problems with clashes and its only a development function so we feel this is ok.

To call this Routes() function, you can either type Routes() into your WebInspector console and hit enter, or make some bookmarklets if you find yourself wanting to do this often - see below for directions:

data:text/html,<a href="javascript:Routes()">Print Routing DSL</a><br /><a href="javascript:Routes('https://alexspeller.com/ember-diagonal/?routesInput=%s')">Show Routing DSL in Ember Diagonal</a>

bookmarklets

Lastly, there are probably a few other debug/dev functions I sometimes use that I could add in also, so I've added a new section in the README file to document this one and any future debug/dev functions.

..plus a nice way to view the structure using ember-diagonal
@johncowen johncowen added the theme/ui Anything related to the UI label Jan 29, 2021
@johncowen johncowen requested a review from kaxcode January 29, 2021 10:42
@johncowen johncowen changed the title ui: Adds a Routes router DSL dumping function only in dev mode ui: Adds a Routes() router DSL dumping function only in dev mode Jan 29, 2021
Copy link
Contributor

@kaxcode kaxcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@johncowen johncowen merged commit 3aef5cd into master Feb 1, 2021
@johncowen johncowen deleted the ui/chore/route-dev-utils branch February 1, 2021 17:29
@hashicorp-ci
Copy link
Contributor

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/320575.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/ui Anything related to the UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants