mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
renaming by jim's request: UrlParam => PageParam (type), createUrlParam => createPageParam (helper)
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
250a2d4d2c
commit
96e69b344f
@ -4,7 +4,7 @@ import path from "path";
|
||||
import { observer } from "mobx-react";
|
||||
import { CoffeeDoodle } from "react-open-doodles";
|
||||
|
||||
export const exampleId = Navigation.createUrlParam<string>({
|
||||
export const exampleId = Navigation.createPageParam({
|
||||
name: "exampleId",
|
||||
defaultValue: "demo",
|
||||
});
|
||||
|
||||
@ -3,7 +3,7 @@ import type React from "react";
|
||||
import { action } from "mobx";
|
||||
import { BaseRegistry } from "./base-registry";
|
||||
import { LensExtension, sanitizeExtensionName } from "../lens-extension";
|
||||
import { UrlParam } from "../../renderer/navigation/url-param";
|
||||
import { PageParam } from "../../renderer/navigation/page-param";
|
||||
import logger from "../../main/logger";
|
||||
|
||||
export interface PageRegistration {
|
||||
@ -18,7 +18,7 @@ export interface PageRegistration {
|
||||
* Used to generate final page url when provided in getExtensionPageUrl()-helper.
|
||||
* Advanced usage: provide `UrlParam` as values to customize parsing/stringification from/to URL.
|
||||
*/
|
||||
params?: PageTargetParams<string | UrlParam>;
|
||||
params?: PageTargetParams<string | PageParam>;
|
||||
}
|
||||
|
||||
export interface PageComponents {
|
||||
@ -56,7 +56,7 @@ export function getExtensionPageUrl(target: PageTarget): string {
|
||||
Object.entries(registeredPage.params).forEach(([name, param]) => {
|
||||
const targetParamValue = targetParams[name];
|
||||
|
||||
if (param instanceof UrlParam) {
|
||||
if (param instanceof PageParam) {
|
||||
pageUrl.searchParams.set(name, param.stringify(targetParamValue));
|
||||
} else {
|
||||
const value = String(targetParamValue ?? param);
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
export { createUrlParam, navigate, isActiveRoute, UrlParamInit, UrlParam } from "../../renderer/navigation";
|
||||
export { PageParam, PageParamInit } from "../../renderer/navigation/page-param";
|
||||
export { navigate, isActiveRoute, createPageParam } from "../../renderer/navigation";
|
||||
export { hideDetails, showDetails, getDetailsUrl } from "../../renderer/components/kube-object/kube-object-details";
|
||||
export { IURLParams } from "../../common/utils/buildUrl";
|
||||
|
||||
@ -10,10 +10,10 @@ import { KubeObjectListLayout } from "../kube-object";
|
||||
import { crdStore } from "./crd.store";
|
||||
import { CustomResourceDefinition } from "../../api/endpoints/crd.api";
|
||||
import { Select, SelectOption } from "../select";
|
||||
import { createUrlParam } from "../../navigation";
|
||||
import { createPageParam } from "../../navigation";
|
||||
import { Icon } from "../icon";
|
||||
|
||||
export const crdGroupsUrlParam = createUrlParam<string[]>({
|
||||
export const crdGroupsUrlParam = createPageParam<string[]>({
|
||||
name: "groups",
|
||||
multiValues: true,
|
||||
isSystem: true,
|
||||
|
||||
@ -2,14 +2,14 @@ import { action, comparer, observable, reaction } from "mobx";
|
||||
import { autobind, createStorage } from "../../utils";
|
||||
import { KubeObjectStore } from "../../kube-object.store";
|
||||
import { Namespace, namespacesApi } from "../../api/endpoints";
|
||||
import { createUrlParam } from "../../navigation";
|
||||
import { createPageParam } from "../../navigation";
|
||||
import { apiManager } from "../../api/api-manager";
|
||||
import { isAllowedResource } from "../../../common/rbac";
|
||||
import { getHostedCluster } from "../../../common/cluster-store";
|
||||
|
||||
const storage = createStorage<string[]>("context_namespaces", []);
|
||||
|
||||
export const namespaceUrlParam = createUrlParam<string[]>({
|
||||
export const namespaceUrlParam = createPageParam<string[]>({
|
||||
name: "namespaces",
|
||||
isSystem: true,
|
||||
multiValues: true,
|
||||
|
||||
@ -4,9 +4,9 @@ import { autorun, observable } from "mobx";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import { InputProps } from "./input";
|
||||
import { SearchInput } from "./search-input";
|
||||
import { createUrlParam } from "../../navigation";
|
||||
import { createPageParam } from "../../navigation";
|
||||
|
||||
export const searchUrlParam = createUrlParam({
|
||||
export const searchUrlParam = createPageParam({
|
||||
name: "search",
|
||||
isSystem: true,
|
||||
defaultValue: "",
|
||||
|
||||
@ -4,7 +4,7 @@ import React from "react";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import { computed, observable, reaction } from "mobx";
|
||||
import { Trans } from "@lingui/macro";
|
||||
import { createUrlParam, navigation } from "../../navigation";
|
||||
import { createPageParam, navigation } from "../../navigation";
|
||||
import { Drawer } from "../drawer";
|
||||
import { KubeObject } from "../../api/kube-object";
|
||||
import { Spinner } from "../spinner";
|
||||
@ -14,12 +14,12 @@ import { CrdResourceDetails } from "../+custom-resources";
|
||||
import { KubeObjectMenu } from "./kube-object-menu";
|
||||
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
|
||||
|
||||
export const kubeDetailsUrlParam = createUrlParam({
|
||||
export const kubeDetailsUrlParam = createPageParam({
|
||||
name: "kube-details",
|
||||
isSystem: true,
|
||||
});
|
||||
|
||||
export const kubeSelectedUrlParam = createUrlParam({
|
||||
export const kubeSelectedUrlParam = createPageParam({
|
||||
name: "kube-selected",
|
||||
isSystem: true,
|
||||
get defaultValue() {
|
||||
|
||||
@ -9,7 +9,7 @@ import { TableRow, TableRowElem, TableRowProps } from "./table-row";
|
||||
import { TableHead, TableHeadElem, TableHeadProps } from "./table-head";
|
||||
import { TableCellElem } from "./table-cell";
|
||||
import { VirtualList } from "../virtual-list";
|
||||
import { createUrlParam } from "../../navigation";
|
||||
import { createPageParam } from "../../navigation";
|
||||
import { ItemObject } from "../../item.store";
|
||||
|
||||
export type TableSortBy = string;
|
||||
@ -41,12 +41,12 @@ export interface TableProps extends React.DOMAttributes<HTMLDivElement> {
|
||||
getTableRow?: (uid: string) => React.ReactElement<TableRowProps>;
|
||||
}
|
||||
|
||||
export const sortByUrlParam = createUrlParam({
|
||||
export const sortByUrlParam = createPageParam({
|
||||
name: "sort",
|
||||
isSystem: true,
|
||||
});
|
||||
|
||||
export const orderByUrlParam = createUrlParam({
|
||||
export const orderByUrlParam = createPageParam({
|
||||
name: "order",
|
||||
isSystem: true,
|
||||
});
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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) {
|
||||
Loading…
Reference in New Issue
Block a user