mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-16 12:00:11 +00:00
wip
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import { translateUrlParams } from '../router-utils';
|
||||
|
||||
describe('router-utils', () => {
|
||||
it('translates a query to a view state', () => {
|
||||
// const dispatch = createSpy();
|
||||
// const state = Object.assign({}, initialState, {
|
||||
// nodes: [{node_1: 'some_id'}]
|
||||
// });
|
||||
// window.location.search = '?node=node_1';
|
||||
// const page = getRouter(dispatch, state);
|
||||
// expect(page).toBeTruthy();
|
||||
translateUrlParams('?key=value&otherkey=othervalue', []);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import page from 'page';
|
||||
import reduce from 'lodash/reduce';
|
||||
import trimStart from 'lodash/trimStart';
|
||||
|
||||
import { route } from '../actions/app-actions';
|
||||
import { storageGet, storageSet } from './storage-utils';
|
||||
import { searchTopology } from './search-utils';
|
||||
|
||||
//
|
||||
// page.js won't match the routes below if ":state" has a slash in it, so replace those before we
|
||||
@@ -83,10 +86,27 @@ export function updateRoute(getState) {
|
||||
}
|
||||
}
|
||||
|
||||
export function translateUrlParams(paramString, nodes) {
|
||||
// ?key=value&otherkey=othervalue
|
||||
let state;
|
||||
const pairs = trimStart(paramString, '?').split('&');
|
||||
const params = reduce(pairs, (result, pair) => {
|
||||
const [k, v] = pair.split('=');
|
||||
result[k] = v;
|
||||
return result;
|
||||
}, {});
|
||||
if (params.node) {
|
||||
state = searchTopology(nodes, { query: params.node });
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
export function getRouter(dispatch, initialState) {
|
||||
// strip any trailing '/'s.
|
||||
page.base(window.location.pathname.replace(/\/$/, ''));
|
||||
console.log(translateUrlParams(window.location.search));
|
||||
|
||||
page('/', () => {
|
||||
// recover from storage state on empty URL
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
"eslint-plugin-import": "2.2.0",
|
||||
"eslint-plugin-jsx-a11y": "2.2.3",
|
||||
"eslint-plugin-react": "6.8.0",
|
||||
"expect": "^1.20.2",
|
||||
"extract-text-webpack-plugin": "1.0.1",
|
||||
"file-loader": "0.9.0",
|
||||
"font-awesome-webpack": "0.0.4",
|
||||
@@ -99,7 +100,9 @@
|
||||
"loadreport": "npm run noprobe && sleep 1 && curl -X POST -H \"Content-Type: application/json\" http://$BACKEND_HOST/api/report -d"
|
||||
},
|
||||
"jest": {
|
||||
"transform": {".*": "<rootDir>/node_modules/babel-jest"},
|
||||
"transform": {
|
||||
".*": "<rootDir>/node_modules/babel-jest"
|
||||
},
|
||||
"setupFiles": [
|
||||
"<rootDir>/test/support/localStorage.js"
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user