(store: RootStore)
| 70 | } |
| 71 | |
| 72 | export function updateUrlFromStore(store: RootStore) { |
| 73 | const state = store.getState(); |
| 74 | const query = { |
| 75 | [Query.SEARCH]: state.ui.filter[FilterName.Search], |
| 76 | [Query.HIGHLIGHT]: state.ui.filter[FilterName.Highlight], |
| 77 | [Query.SHOW_EVENTLOG]: state.eventLog.visible, |
| 78 | [Query.SHOW_COMMANDBAR]: state.commandBar.visible, |
| 79 | }; |
| 80 | const queryStr = Object.keys(query) |
| 81 | .filter((k) => query[k]) |
| 82 | .map((k) => `${k}=${encodeURIComponent(query[k]!)}`) |
| 83 | .join("&"); |
| 84 | |
| 85 | let url; |
| 86 | if (state.ui.tabs.current === Tab.Capture) { |
| 87 | url = "/capture"; |
| 88 | } else if (state.flows.selected.length > 0) { |
| 89 | url = `/flows/${state.flows.selected[0].id}/${state.ui.flow.tab}`; |
| 90 | } else { |
| 91 | url = "/flows"; |
| 92 | } |
| 93 | |
| 94 | if (queryStr) { |
| 95 | url += "?" + queryStr; |
| 96 | } |
| 97 | let pathname = window.location.pathname; |
| 98 | if (pathname === "blank") { |
| 99 | pathname = "/"; // this happens in tests... |
| 100 | } |
| 101 | if (window.location.hash.substr(1) !== url) { |
| 102 | history.replaceState(undefined, "", `${pathname}#${url}`); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | export default function initialize(store) { |
| 107 | updateStoreFromUrl(store); |
no test coverage detected
searching dependent graphs…