Node linking added

This commit is contained in:
jpellizzari
2017-01-16 15:25:20 -08:00
parent dea2612611
commit 443941e1b8
8 changed files with 64 additions and 52 deletions

View File

@@ -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', []);
});
});

View 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);
}

View File

@@ -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;
}, {});
}

View File

@@ -76,6 +76,7 @@ function findNodeMatch(nodeMatches, keyPath, text, query, prefix, label, truncat
{text, label, start: index, length: firstMatch.length, truncate});
}
}
return nodeMatches;
}