renaming by jim's request: UrlParam => PageParam (type), createUrlParam => createPageParam (helper)

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman committed 2020-12-08 15:19:12 +02:00
1 parent 250a2d4d2c
commit 96e69b344f
11 files changed
+57 -66

No files matched your search

-33
View File
@@ -1,33 +0,0 @@
// Navigation helpers
import { matchPath, RouteProps } from "react-router";
import { LocationDescriptor } from "history";
import { clusterViewRoute, IClusterViewRouteParams } from "../components/cluster-manager/cluster-view.route";
import { navigation } from "./index";
export function navigate(location: LocationDescriptor) {
const currentLocation = navigation.getPath();
navigation.push(location);
if (currentLocation === navigation.getPath()) {
navigation.goBack(); // prevent sequences of same url in history
}
}
export function matchParams<P>(route: string | string[] | RouteProps) {
return matchPath<P>(navigation.location.pathname, route);
}
export function isActiveRoute(route: string | string[] | RouteProps): boolean {
return !!matchParams(route);
}
export function getMatchedClusterId(): string {
const matched = matchPath<IClusterViewRouteParams>(navigation.location.pathname, {
exact: true,
path: clusterViewRoute.path
});
return matched?.params.clusterId;
}
+34 -11
View File
@@ -1,19 +1,47 @@
// Navigation helpers
import { ipcRenderer } from "electron";
import logger from "../../main/logger";
import { reaction } from "mobx";
import { matchPath, RouteProps } from "react-router";
import { createObservableHistory } from "mobx-observable-history";
import { createBrowserHistory, createMemoryHistory } from "history";
import { createBrowserHistory, createMemoryHistory, LocationDescriptor } from "history";
import { broadcastMessage, subscribeToBroadcast } from "../../common/ipc";
import { getMatchedClusterId, navigate } from "./helpers";
import { UrlParam, UrlParamInit } from "./url-param";
import { PageParam, PageParamInit } from "./page-param";
import { clusterViewRoute, IClusterViewRouteParams } from "../components/cluster-manager/cluster-view.route";
import logger from "../../main/logger";
export let history = ipcRenderer ? createBrowserHistory() : createMemoryHistory();
export let navigation = createObservableHistory(history);
export function createUrlParam<V = string>(init: UrlParamInit<V>) {
return new UrlParam<V>(init, navigation);
export function navigate(location: LocationDescriptor) {
const currentLocation = navigation.getPath();
navigation.push(location);
if (currentLocation === navigation.getPath()) {
navigation.goBack(); // prevent sequences of same url in history
}
}
export function matchParams<P>(route: string | string[] | RouteProps) {
return matchPath<P>(navigation.location.pathname, route);
}
export function isActiveRoute(route: string | string[] | RouteProps): boolean {
return !!matchParams(route);
}
export function getMatchedClusterId(): string {
const matched = matchPath<IClusterViewRouteParams>(navigation.location.pathname, {
exact: true,
path: clusterViewRoute.path
});
return matched?.params.clusterId;
}
export function createPageParam<V = string>(init: PageParamInit<V>) {
return new PageParam<V>(init, navigation);
}
if (ipcRenderer) {
@@ -40,8 +68,3 @@ if (ipcRenderer) {
location.reload();
});
}
// Re-exports from sub-modules
export * from "./helpers";
export * from "./url-param";
@@ -1,7 +1,7 @@
// Manage observable URL-param via location.search
import { IObservableHistory } from "mobx-observable-history";
export interface UrlParamInit<V = any> {
export interface PageParamInit<V = any> {
name: string;
isSystem?: boolean;
defaultValue?: V;
@@ -12,20 +12,20 @@ export interface UrlParamInit<V = any> {
stringify?(values: V): string | string[]; // serialize params to URL
}
export class UrlParam<V = any | any[]> {
export class PageParam<V = any | any[]> {
static SYSTEM_PREFIX = "lens-";
readonly name: string;
readonly urlName: string;
protected urlName: string;
constructor(private init: UrlParamInit<V>, private history: IObservableHistory) {
constructor(private init: PageParamInit<V>, private history: IObservableHistory) {
const { isSystem, name, skipEmpty = true } = init;
this.name = name;
this.init.skipEmpty = skipEmpty;
// prefixing to avoid collisions with extensions
this.urlName = `${isSystem ? UrlParam.SYSTEM_PREFIX : ""}${name}`;
this.urlName = `${isSystem ? PageParam.SYSTEM_PREFIX : ""}${name}`;
}
isEmpty(value: V) {