mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 09:41:57 +00:00
added translateUrlParamsToViewState action; wip
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
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
|
||||
@@ -86,27 +83,9 @@ 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
|
||||
|
||||
@@ -68,6 +68,7 @@ function findNodeMatch(nodeMatches, keyPath, text, query, prefix, label, truncat
|
||||
if (!prefix || matchPrefix(label, prefix)) {
|
||||
const queryRe = makeRegExp(query);
|
||||
const matches = text.match(queryRe);
|
||||
|
||||
if (matches) {
|
||||
const firstMatch = matches[0];
|
||||
const index = text.search(queryRe);
|
||||
@@ -172,6 +173,7 @@ export function searchTopology(nodes, { prefix, query, metric, comp, value }) {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return nodeMatches;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user