mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 01:31:17 +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
|
||||
|
||||
Reference in New Issue
Block a user