From 53d6b9d7042110c32a8dd135d9917204e15b0bdb Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 24 Oct 2018 14:42:35 -0500 Subject: [PATCH] reorg getQueryToken, stripQueryToken in utils/utils --- embark-ui/src/containers/AppContainer.js | 16 +--------------- embark-ui/src/utils/utils.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index 7121818e..e325cc2a 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -6,6 +6,7 @@ import routes from '../routes'; import Login from '../components/Login'; import Layout from "../components/Layout"; import { DEFAULT_HOST } from '../constants'; +import {getQueryToken, stripQueryToken} from '../utils/utils'; import { authenticate, fetchCredentials, logout, @@ -20,22 +21,7 @@ import {LIGHT_THEME, DARK_THEME} from '../constants'; import { getCredentials, getAuthenticationError, getProcesses, getTheme } from '../reducers/selectors'; -const qs = require('qs'); - class AppContainer extends Component { - getQueryToken() { - return qs.parse(this.props.location.search, {ignoreQueryPrefix: true}).token; - } - - stripQueryToken(location) { - const _location = Object.assign({}, location); - _location.search = _location.search.replace( - /(\?|&?)(token=[\w-]*)(&?)/, - (_, p1, p2, p3) => (p2 ? (p3 === '&' ? p1 : '') : '') - ); - return _location; - } - queryStringAuthenticate() { if (this.props.credentials.authenticating) { return; diff --git a/embark-ui/src/utils/utils.js b/embark-ui/src/utils/utils.js index e70aeb56..243758c5 100644 --- a/embark-ui/src/utils/utils.js +++ b/embark-ui/src/utils/utils.js @@ -1,4 +1,5 @@ const Convert = require('ansi-to-html'); +import qs from 'qs'; export function last(array) { return array && array.length ? array[array.length - 1] : undefined; @@ -18,4 +19,16 @@ export function hashCode(str) { export function ansiToHtml(text) { const convert = new Convert(); return convert.toHtml(text.replace(/\n/g,'
')) + +export function getQueryToken(location) { + return qs.parse(location.search, {ignoreQueryPrefix: true}).token; +} + +export function stripQueryToken(location) { + const _location = Object.assign({}, location); + _location.search = _location.search.replace( + /(\?|&?)(token=[\w-]*)(&?)/, + (_, p1, p2, p3) => (p2 ? (p3 === '&' ? p1 : '') : '') + ); + return _location; }