mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 17:51:21 +00:00
Node linking added
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
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', []);
|
||||
});
|
||||
});
|
||||
16
client/app/scripts/utils/async-utils.js
Normal file
16
client/app/scripts/utils/async-utils.js
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
export function waterfall(series, target, cb) {
|
||||
function next(result) {
|
||||
const fn = series.shift();
|
||||
if (fn) {
|
||||
try {
|
||||
fn(result, next);
|
||||
} catch (e) {
|
||||
cb(e);
|
||||
}
|
||||
} else {
|
||||
cb(null, result);
|
||||
}
|
||||
}
|
||||
next(target, next);
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
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';
|
||||
@@ -71,7 +73,6 @@ export function updateRoute(getState) {
|
||||
.replace('#!/state/', '')
|
||||
.replace('#!/', '') || '{}';
|
||||
const prevState = JSON.parse(decodeURL(urlStateString));
|
||||
|
||||
// back up state in storage as well
|
||||
storageSet(STORAGE_STATE_KEY, stateUrl);
|
||||
|
||||
@@ -86,7 +87,6 @@ export function updateRoute(getState) {
|
||||
export function getRouter(dispatch, initialState) {
|
||||
// strip any trailing '/'s.
|
||||
page.base(window.location.pathname.replace(/\/$/, ''));
|
||||
|
||||
page('/', () => {
|
||||
// recover from storage state on empty URL
|
||||
const storageState = storageGet(STORAGE_STATE_KEY);
|
||||
@@ -108,3 +108,12 @@ export function getRouter(dispatch, initialState) {
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
export function parseUrlQuery(queryString) {
|
||||
const pairs = trimStart(queryString, '?').split('&');
|
||||
return reduce(pairs, (result, pair) => {
|
||||
const [k, v] = pair.split('=');
|
||||
result[k] = v;
|
||||
return result;
|
||||
}, {});
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ function findNodeMatch(nodeMatches, keyPath, text, query, prefix, label, truncat
|
||||
{text, label, start: index, length: firstMatch.length, truncate});
|
||||
}
|
||||
}
|
||||
|
||||
return nodeMatches;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user