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 { observer } from "mobx-react";
|
||||||
import { CoffeeDoodle } from "react-open-doodles";
|
import { CoffeeDoodle } from "react-open-doodles";
|
||||||
|
|
||||||
export const exampleId = Navigation.createUrlParam<string>({
|
export const exampleId = Navigation.createPageParam({
|
||||||
name: "exampleId",
|
name: "exampleId",
|
||||||
defaultValue: "demo",
|
defaultValue: "demo",
|
||||||
});
|
});
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import type React from "react";
|
|||||||
import { action } from "mobx";
|
import { action } from "mobx";
|
||||||
import { BaseRegistry } from "./base-registry";
|
import { BaseRegistry } from "./base-registry";
|
||||||
import { LensExtension, sanitizeExtensionName } from "../lens-extension";
|
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";
|
import logger from "../../main/logger";
|
||||||
|
|
||||||
export interface PageRegistration {
|
export interface PageRegistration {
|
||||||
@ -18,7 +18,7 @@ export interface PageRegistration {
|
|||||||
* Used to generate final page url when provided in getExtensionPageUrl()-helper.
|
* Used to generate final page url when provided in getExtensionPageUrl()-helper.
|
||||||
* Advanced usage: provide `UrlParam` as values to customize parsing/stringification from/to URL.
|
* Advanced usage: provide `UrlParam` as values to customize parsing/stringification from/to URL.
|
||||||
*/
|
*/
|
||||||
params?: PageTargetParams<string | UrlParam>;
|
params?: PageTargetParams<string | PageParam>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PageComponents {
|
export interface PageComponents {
|
||||||
@ -56,7 +56,7 @@ export function getExtensionPageUrl(target: PageTarget): string {
|
|||||||
Object.entries(registeredPage.params).forEach(([name, param]) => {
|
Object.entries(registeredPage.params).forEach(([name, param]) => {
|
||||||
const targetParamValue = targetParams[name];
|
const targetParamValue = targetParams[name];
|
||||||
|
|
||||||
if (param instanceof UrlParam) {
|
if (param instanceof PageParam) {
|
||||||
pageUrl.searchParams.set(name, param.stringify(targetParamValue));
|
pageUrl.searchParams.set(name, param.stringify(targetParamValue));
|
||||||
} else {
|
} else {
|
||||||
const value = String(targetParamValue ?? param);
|
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 { hideDetails, showDetails, getDetailsUrl } from "../../renderer/components/kube-object/kube-object-details";
|
||||||
export { IURLParams } from "../../common/utils/buildUrl";
|
export { IURLParams } from "../../common/utils/buildUrl";
|
||||||
|
|||||||
@ -10,10 +10,10 @@ import { KubeObjectListLayout } from "../kube-object";
|
|||||||
import { crdStore } from "./crd.store";
|
import { crdStore } from "./crd.store";
|
||||||
import { CustomResourceDefinition } from "../../api/endpoints/crd.api";
|
import { CustomResourceDefinition } from "../../api/endpoints/crd.api";
|
||||||
import { Select, SelectOption } from "../select";
|
import { Select, SelectOption } from "../select";
|
||||||
import { createUrlParam } from "../../navigation";
|
import { createPageParam } from "../../navigation";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
|
|
||||||
export const crdGroupsUrlParam = createUrlParam<string[]>({
|
export const crdGroupsUrlParam = createPageParam<string[]>({
|
||||||
name: "groups",
|
name: "groups",
|
||||||
multiValues: true,
|
multiValues: true,
|
||||||
isSystem: true,
|
isSystem: true,
|
||||||
|
|||||||
@ -2,14 +2,14 @@ import { action, comparer, observable, reaction } from "mobx";
|
|||||||
import { autobind, createStorage } from "../../utils";
|
import { autobind, createStorage } from "../../utils";
|
||||||
import { KubeObjectStore } from "../../kube-object.store";
|
import { KubeObjectStore } from "../../kube-object.store";
|
||||||
import { Namespace, namespacesApi } from "../../api/endpoints";
|
import { Namespace, namespacesApi } from "../../api/endpoints";
|
||||||
import { createUrlParam } from "../../navigation";
|
import { createPageParam } from "../../navigation";
|
||||||
import { apiManager } from "../../api/api-manager";
|
import { apiManager } from "../../api/api-manager";
|
||||||
import { isAllowedResource } from "../../../common/rbac";
|
import { isAllowedResource } from "../../../common/rbac";
|
||||||
import { getHostedCluster } from "../../../common/cluster-store";
|
import { getHostedCluster } from "../../../common/cluster-store";
|
||||||
|
|
||||||
const storage = createStorage<string[]>("context_namespaces", []);
|
const storage = createStorage<string[]>("context_namespaces", []);
|
||||||
|
|
||||||
export const namespaceUrlParam = createUrlParam<string[]>({
|
export const namespaceUrlParam = createPageParam<string[]>({
|
||||||
name: "namespaces",
|
name: "namespaces",
|
||||||
isSystem: true,
|
isSystem: true,
|
||||||
multiValues: true,
|
multiValues: true,
|
||||||
|
|||||||
@ -4,9 +4,9 @@ import { autorun, observable } from "mobx";
|
|||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { InputProps } from "./input";
|
import { InputProps } from "./input";
|
||||||
import { SearchInput } from "./search-input";
|
import { SearchInput } from "./search-input";
|
||||||
import { createUrlParam } from "../../navigation";
|
import { createPageParam } from "../../navigation";
|
||||||
|
|
||||||
export const searchUrlParam = createUrlParam({
|
export const searchUrlParam = createPageParam({
|
||||||
name: "search",
|
name: "search",
|
||||||
isSystem: true,
|
isSystem: true,
|
||||||
defaultValue: "",
|
defaultValue: "",
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import React from "react";
|
|||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { computed, observable, reaction } from "mobx";
|
import { computed, observable, reaction } from "mobx";
|
||||||
import { Trans } from "@lingui/macro";
|
import { Trans } from "@lingui/macro";
|
||||||
import { createUrlParam, navigation } from "../../navigation";
|
import { createPageParam, navigation } from "../../navigation";
|
||||||
import { Drawer } from "../drawer";
|
import { Drawer } from "../drawer";
|
||||||
import { KubeObject } from "../../api/kube-object";
|
import { KubeObject } from "../../api/kube-object";
|
||||||
import { Spinner } from "../spinner";
|
import { Spinner } from "../spinner";
|
||||||
@ -14,12 +14,12 @@ import { CrdResourceDetails } from "../+custom-resources";
|
|||||||
import { KubeObjectMenu } from "./kube-object-menu";
|
import { KubeObjectMenu } from "./kube-object-menu";
|
||||||
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
|
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
|
||||||
|
|
||||||
export const kubeDetailsUrlParam = createUrlParam({
|
export const kubeDetailsUrlParam = createPageParam({
|
||||||
name: "kube-details",
|
name: "kube-details",
|
||||||
isSystem: true,
|
isSystem: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const kubeSelectedUrlParam = createUrlParam({
|
export const kubeSelectedUrlParam = createPageParam({
|
||||||
name: "kube-selected",
|
name: "kube-selected",
|
||||||
isSystem: true,
|
isSystem: true,
|
||||||
get defaultValue() {
|
get defaultValue() {
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import { TableRow, TableRowElem, TableRowProps } from "./table-row";
|
|||||||
import { TableHead, TableHeadElem, TableHeadProps } from "./table-head";
|
import { TableHead, TableHeadElem, TableHeadProps } from "./table-head";
|
||||||
import { TableCellElem } from "./table-cell";
|
import { TableCellElem } from "./table-cell";
|
||||||
import { VirtualList } from "../virtual-list";
|
import { VirtualList } from "../virtual-list";
|
||||||
import { createUrlParam } from "../../navigation";
|
import { createPageParam } from "../../navigation";
|
||||||
import { ItemObject } from "../../item.store";
|
import { ItemObject } from "../../item.store";
|
||||||
|
|
||||||
export type TableSortBy = string;
|
export type TableSortBy = string;
|
||||||
@ -41,12 +41,12 @@ export interface TableProps extends React.DOMAttributes<HTMLDivElement> {
|
|||||||
getTableRow?: (uid: string) => React.ReactElement<TableRowProps>;
|
getTableRow?: (uid: string) => React.ReactElement<TableRowProps>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const sortByUrlParam = createUrlParam({
|
export const sortByUrlParam = createPageParam({
|
||||||
name: "sort",
|
name: "sort",
|
||||||
isSystem: true,
|
isSystem: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const orderByUrlParam = createUrlParam({
|
export const orderByUrlParam = createPageParam({
|
||||||
name: "order",
|
name: "order",
|
||||||
isSystem: true,
|
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
|
// Navigation helpers
|
||||||
|
|
||||||
import { ipcRenderer } from "electron";
|
import { ipcRenderer } from "electron";
|
||||||
import logger from "../../main/logger";
|
|
||||||
import { reaction } from "mobx";
|
import { reaction } from "mobx";
|
||||||
|
import { matchPath, RouteProps } from "react-router";
|
||||||
import { createObservableHistory } from "mobx-observable-history";
|
import { createObservableHistory } from "mobx-observable-history";
|
||||||
import { createBrowserHistory, createMemoryHistory } from "history";
|
import { createBrowserHistory, createMemoryHistory, LocationDescriptor } from "history";
|
||||||
import { broadcastMessage, subscribeToBroadcast } from "../../common/ipc";
|
import { broadcastMessage, subscribeToBroadcast } from "../../common/ipc";
|
||||||
import { getMatchedClusterId, navigate } from "./helpers";
|
import { PageParam, PageParamInit } from "./page-param";
|
||||||
import { UrlParam, UrlParamInit } from "./url-param";
|
import { clusterViewRoute, IClusterViewRouteParams } from "../components/cluster-manager/cluster-view.route";
|
||||||
|
import logger from "../../main/logger";
|
||||||
|
|
||||||
export let history = ipcRenderer ? createBrowserHistory() : createMemoryHistory();
|
export let history = ipcRenderer ? createBrowserHistory() : createMemoryHistory();
|
||||||
export let navigation = createObservableHistory(history);
|
export let navigation = createObservableHistory(history);
|
||||||
|
|
||||||
export function createUrlParam<V = string>(init: UrlParamInit<V>) {
|
export function navigate(location: LocationDescriptor) {
|
||||||
return new UrlParam<V>(init, navigation);
|
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) {
|
if (ipcRenderer) {
|
||||||
@ -40,8 +68,3 @@ if (ipcRenderer) {
|
|||||||
location.reload();
|
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
|
// Manage observable URL-param via location.search
|
||||||
import { IObservableHistory } from "mobx-observable-history";
|
import { IObservableHistory } from "mobx-observable-history";
|
||||||
|
|
||||||
export interface UrlParamInit<V = any> {
|
export interface PageParamInit<V = any> {
|
||||||
name: string;
|
name: string;
|
||||||
isSystem?: boolean;
|
isSystem?: boolean;
|
||||||
defaultValue?: V;
|
defaultValue?: V;
|
||||||
@ -12,20 +12,20 @@ export interface UrlParamInit<V = any> {
|
|||||||
stringify?(values: V): string | string[]; // serialize params to URL
|
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-";
|
static SYSTEM_PREFIX = "lens-";
|
||||||
|
|
||||||
readonly name: string;
|
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;
|
const { isSystem, name, skipEmpty = true } = init;
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.init.skipEmpty = skipEmpty;
|
this.init.skipEmpty = skipEmpty;
|
||||||
|
|
||||||
// prefixing to avoid collisions with extensions
|
// prefixing to avoid collisions with extensions
|
||||||
this.urlName = `${isSystem ? UrlParam.SYSTEM_PREFIX : ""}${name}`;
|
this.urlName = `${isSystem ? PageParam.SYSTEM_PREFIX : ""}${name}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
isEmpty(value: V) {
|
isEmpty(value: V) {
|
||||||
Loading…
Reference in New Issue
Block a user