// Navigation helpers import { ipcRenderer } from "electron"; import { compile } from "path-to-regexp" import { createBrowserHistory, createMemoryHistory, Location, LocationDescriptor } from "history"; import { createObservableHistory } from "mobx-observable-history"; export const history = typeof window !== "undefined" ? createBrowserHistory() : createMemoryHistory(); export const navigation = createObservableHistory(history); if (ipcRenderer) { // subscribe for navigation via menu.ts ipcRenderer.on("menu:navigate", (event, path: string) => { navigate(path); }); } export function navigate(location: LocationDescriptor) { navigation.location = location as Location; } export interface IURLParams
{ params?: P; query?: IQueryParams & Q; } export function buildURL
(path: string | string[]) { const pathBuilder = compile(path.toString()); return function ({ params, query }: IURLParams
= {}) {
return pathBuilder(params) + (query ? getQueryString(query, false) : "")
}
}
// common params for all pages
export interface IQueryParams {
namespaces?: string[]; // selected context namespaces
details?: string; // serialized resource details
selected?: string; // mark resource as selected
search?: string; // search-input value
sortBy?: string; // sorting params for table-list
orderBy?: string;
}
export function getQueryString(params?: Partial