mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-04 10:41:14 +00:00
* Fix node-details-test for search * Label spacing and matched text truncation * Delete pinned search on backspace, add hint for metrics, escape % in URL * Fix text-bg on node highlight * Added tests for search-utils * Fix matching of other topologies, added comment re quick clear * s/cx/classnames/ * Ignore MoC keys when search in focus, blur on Esc * Fixes search term highlighting on-hover * Fix SVG exports * Fine-tuned search item rendering * Fixed search highlighting in the details panel * Dont throb node on hover * Hotkey for search: '/' * Keep focus on search when tabbing away from the browser * bring hovered node to top * background for search results on hover * fixed height for foreign object to prevent layout glitches * Dont blur focused nodes on search * More robust metric matchers * More meaningful search hints
85 lines
2.5 KiB
JavaScript
85 lines
2.5 KiB
JavaScript
import page from 'page';
|
|
|
|
import { route } from '../actions/app-actions';
|
|
|
|
//
|
|
// page.js won't match the routes below if ":state" has a slash in it, so replace those before we
|
|
// load the state into the URL.
|
|
//
|
|
const SLASH = '/';
|
|
const SLASH_REPLACEMENT = '<SLASH>';
|
|
const PERCENT = '%';
|
|
const PERCENT_REPLACEMENT = '<PERCENT>';
|
|
|
|
function encodeURL(url) {
|
|
return url
|
|
.replace(new RegExp(PERCENT, 'g'), PERCENT_REPLACEMENT)
|
|
.replace(new RegExp(SLASH, 'g'), SLASH_REPLACEMENT);
|
|
}
|
|
|
|
function decodeURL(url) {
|
|
return decodeURIComponent(url.replace(new RegExp(SLASH_REPLACEMENT, 'g'), SLASH))
|
|
.replace(new RegExp(PERCENT_REPLACEMENT, 'g'), PERCENT);
|
|
}
|
|
|
|
function shouldReplaceState(prevState, nextState) {
|
|
// Opening a new terminal while an existing one is open.
|
|
const terminalToTerminal = (prevState.controlPipe && nextState.controlPipe);
|
|
// Closing a terminal.
|
|
const closingTheTerminal = (prevState.controlPipe && !nextState.controlPipe);
|
|
|
|
return terminalToTerminal || closingTheTerminal;
|
|
}
|
|
|
|
export function getUrlState(state) {
|
|
const cp = state.get('controlPipes').last();
|
|
const nodeDetails = state.get('nodeDetails').toIndexedSeq().map(details => ({
|
|
id: details.id, label: details.label, topologyId: details.topologyId
|
|
}));
|
|
|
|
return {
|
|
controlPipe: cp ? cp.toJS() : null,
|
|
nodeDetails: nodeDetails.toJS(),
|
|
pinnedMetricType: state.get('pinnedMetricType'),
|
|
pinnedSearches: state.get('pinnedSearches').toJS(),
|
|
searchQuery: state.get('searchQuery'),
|
|
selectedNodeId: state.get('selectedNodeId'),
|
|
topologyId: state.get('currentTopologyId'),
|
|
topologyOptions: state.get('topologyOptions').toJS() // all options
|
|
};
|
|
}
|
|
|
|
export function updateRoute(getState) {
|
|
const state = getUrlState(getState());
|
|
const stateUrl = encodeURL(JSON.stringify(state));
|
|
const dispatch = false;
|
|
const urlStateString = window.location.hash
|
|
.replace('#!/state/', '')
|
|
.replace('#!/', '') || '{}';
|
|
const prevState = JSON.parse(decodeURL(urlStateString));
|
|
|
|
if (shouldReplaceState(prevState, state)) {
|
|
// Replace the top of the history rather than pushing on a new item.
|
|
page.replace(`/state/${stateUrl}`, state, dispatch);
|
|
} else {
|
|
page.show(`/state/${stateUrl}`, state, dispatch);
|
|
}
|
|
}
|
|
|
|
|
|
export function getRouter(dispatch, initialState) {
|
|
// strip any trailing '/'s.
|
|
page.base(window.location.pathname.replace(/\/$/, ''));
|
|
|
|
page('/', () => {
|
|
dispatch(route(initialState));
|
|
});
|
|
|
|
page('/state/:state', (ctx) => {
|
|
const state = JSON.parse(decodeURL(ctx.params.state));
|
|
dispatch(route(state));
|
|
});
|
|
|
|
return page;
|
|
}
|