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

ENCD-5432 Use WalkMe test snippet on nonproduction hosts #3446

Merged
merged 1 commit into from
Jul 30, 2020
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
2 changes: 1 addition & 1 deletion src/encoded/static/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ class App extends React.Component {
<link rel="canonical" href={canonical} />
<link href="https://fonts.googleapis.com/css2?family=Mada:wght@200;400;500;600;700&family=Oswald:wght@200;300;400;500&family=Quicksand:wght@300;400;600&display=swap" rel="stylesheet" />
<script async src="//www.google-analytics.com/analytics.js" />
<script async src="https://cdn.walkme.com/users/8c7ff9322d01408798869806f9f5a132/walkme_8c7ff9322d01408798869806f9f5a132_https.js" />
<script async src={`https://cdn.walkme.com/users/8c7ff9322d01408798869806f9f5a132/${globals.isProductionHost(this.props.href) ? '' : 'test/'}walkme_8c7ff9322d01408798869806f9f5a132_https.js`} />
{this.props.inline ? <script data-prop-name="inline" dangerouslySetInnerHTML={{ __html: this.props.inline }} /> : null}
{this.props.styles ? <link rel="stylesheet" href={this.props.styles} /> : null}
{newsHead(this.props, `${hrefUrl.protocol}//${hrefUrl.host}`)}
Expand Down
12 changes: 11 additions & 1 deletion src/encoded/static/components/globals.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _ from 'underscore';
import ga from 'google-analytics';
import url from 'url';
import Registry from '../libs/registry';
import DataColors from './datacolors';

Expand Down Expand Up @@ -154,7 +155,16 @@ export function zeroFill(n, digits) {
export const statusToClassElement = status => status.toLowerCase().replace(/ /g, '-').replace(/\(|\)/g, '');


export const productionHost = { 'www.encodeproject.org': 1, 'encodeproject.org': 1, 'www.encodedcc.org': 1 };
/**
* Returns true if code runs on the production host, as opposed to test, demos, or local. This
* applies to both server and browser rendering.
* @param {string} currentUrl Normally from React context.location_href
*
* @return True if code runs on production host
*/
export const isProductionHost = currentUrl => (
['www.encodeproject.org', 'encodeproject.org', 'www.encodedcc.org'].includes(url.parse(currentUrl).hostname)
Copy link
Contributor

Choose a reason for hiding this comment

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

Something in the back of my head is telling me this can be done with regex much better. Anyway, this is good as-is

);

export const encodeVersionMap = {
ENCODE2: '2',
Expand Down
4 changes: 2 additions & 2 deletions src/encoded/static/components/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import url from 'url';
import { Navbar, Nav, NavItem } from '../libs/ui/navbar';
import { DropdownMenu, DropdownMenuSep } from '../libs/ui/dropdown-menu';
import { CartStatus } from './cart';
import { productionHost } from './globals';
import { isProductionHost } from './globals';
import Tooltip from '../libs/ui/tooltip';
import { BrowserFeat } from './browserfeat';

Expand Down Expand Up @@ -46,7 +46,7 @@ export default class Navigation extends React.Component {
/** ID of the currently dropped-down main navigation menu; '' if none */
openDropdown: '',
/** True if test warning banner visible; default depends on domain */
testWarning: !productionHost[url.parse(context.location_href).hostname],
testWarning: !isProductionHost(context.location_href),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is easier to understand.

};

// Bind this to non-React methods.
Expand Down