// 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"; import { getHostedClusterId } from "../common/cluster-store"; export const history = typeof window !== "undefined" ? createBrowserHistory() : createMemoryHistory(); export const navigation = createObservableHistory(history); // handle navigation from global menu if (ipcRenderer) { const clusterId = getHostedClusterId(); const channel = "menu:navigate" + (clusterId ? `:${clusterId}` : ""); ipcRenderer.on(channel, (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