From 241135a8e3b6bc70dac815f4562900b4365a17ac Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 17 Dec 2020 15:39:51 +0200 Subject: [PATCH] small fixes Signed-off-by: Roman --- extensions/example-extension/page.tsx | 2 +- extensions/example-extension/renderer.tsx | 2 +- src/extensions/interfaces/registrations.ts | 2 +- src/extensions/lens-renderer-extension.ts | 5 ++--- src/extensions/registries/page-registry.ts | 9 +++++---- src/renderer/navigation/page-param.ts | 14 +++----------- 6 files changed, 13 insertions(+), 21 deletions(-) diff --git a/extensions/example-extension/page.tsx b/extensions/example-extension/page.tsx index 3d98f106c6..3887457f50 100644 --- a/extensions/example-extension/page.tsx +++ b/extensions/example-extension/page.tsx @@ -1,7 +1,7 @@ -import { Component, Interface, K8sApi, LensRendererExtension } from "@k8slens/extensions"; import React from "react"; import { observer } from "mobx-react"; import { CoffeeDoodle } from "react-open-doodles"; +import { Component, Interface, K8sApi, LensRendererExtension } from "@k8slens/extensions"; export interface ExamplePageProps extends Interface.PageComponentProps { extension: LensRendererExtension; // provided in "./renderer.tsx" diff --git a/extensions/example-extension/renderer.tsx b/extensions/example-extension/renderer.tsx index 97cda5cc62..76a00c3bf6 100644 --- a/extensions/example-extension/renderer.tsx +++ b/extensions/example-extension/renderer.tsx @@ -30,7 +30,7 @@ export default class ExampleExtension extends LensRendererExtension { } ]; - clusterPageMenus: Interface.PageMenuRegistration[] = [ + clusterPageMenus: Interface.ClusterPageMenuRegistration[] = [ { title: "Example extension", components: { diff --git a/src/extensions/interfaces/registrations.ts b/src/extensions/interfaces/registrations.ts index aea788233a..47c63062ea 100644 --- a/src/extensions/interfaces/registrations.ts +++ b/src/extensions/interfaces/registrations.ts @@ -4,5 +4,5 @@ export type { KubeObjectDetailRegistration, KubeObjectDetailComponents } from ". export type { KubeObjectMenuRegistration, KubeObjectMenuComponents } from "../registries/kube-object-menu-registry"; export type { KubeObjectStatusRegistration } from "../registries/kube-object-status-registry"; export type { PageRegistration, RegisteredPage, PageParams, PageComponentProps, PageComponents, PageTarget } from "../registries/page-registry"; -export type { PageMenuRegistration, PageMenuComponents } from "../registries/page-menu-registry"; +export type { PageMenuRegistration, ClusterPageMenuRegistration, PageMenuComponents } from "../registries/page-menu-registry"; export type { StatusBarRegistration } from "../registries/status-bar-registry"; \ No newline at end of file diff --git a/src/extensions/lens-renderer-extension.ts b/src/extensions/lens-renderer-extension.ts index b6c00d8353..25afaa76fe 100644 --- a/src/extensions/lens-renderer-extension.ts +++ b/src/extensions/lens-renderer-extension.ts @@ -1,14 +1,13 @@ -import type { AppPreferenceRegistration, ClusterFeatureRegistration, KubeObjectDetailRegistration, KubeObjectMenuRegistration, KubeObjectStatusRegistration, PageMenuRegistration, PageRegistration, StatusBarRegistration, } from "./registries"; +import type { AppPreferenceRegistration, ClusterFeatureRegistration, ClusterPageMenuRegistration, KubeObjectDetailRegistration, KubeObjectMenuRegistration, KubeObjectStatusRegistration, PageMenuRegistration, PageRegistration, StatusBarRegistration, } from "./registries"; import type { Cluster } from "../main/cluster"; import { LensExtension } from "./lens-extension"; import { getExtensionPageUrl } from "./registries/page-registry"; - export class LensRendererExtension extends LensExtension { globalPages: PageRegistration[] = []; clusterPages: PageRegistration[] = []; globalPageMenus: PageMenuRegistration[] = []; - clusterPageMenus: PageMenuRegistration[] = []; + clusterPageMenus: ClusterPageMenuRegistration[] = []; kubeObjectStatusTexts: KubeObjectStatusRegistration[] = []; appPreferences: AppPreferenceRegistration[] = []; clusterFeatures: ClusterFeatureRegistration[] = []; diff --git a/src/extensions/registries/page-registry.ts b/src/extensions/registries/page-registry.ts index 15fcf160a7..0ec6f27da0 100644 --- a/src/extensions/registries/page-registry.ts +++ b/src/extensions/registries/page-registry.ts @@ -4,7 +4,7 @@ import React from "react"; import { observer } from "mobx-react"; import { BaseRegistry } from "./base-registry"; import { LensExtension, sanitizeExtensionName } from "../lens-extension"; -import { isPageParamInit, PageParam, PageParamInit } from "../../renderer/navigation/page-param"; +import { PageParam, PageParamInit } from "../../renderer/navigation/page-param"; import { createPageParam } from "../../renderer/navigation/helpers"; export interface PageRegistration { @@ -103,10 +103,11 @@ export class PageRegistry extends BaseRegistry return; } Object.entries(params).forEach(([name, value]) => { - const paramInit: PageParamInit = isPageParamInit(value) ? value : { name, defaultValue: value }; + const paramInit: PageParamInit = typeof value === "object" + ? { name, ...value } + : { name, defaultValue: value }; - paramInit.name ??= name; - params[name] = createPageParam(paramInit); + params[paramInit.name] = createPageParam(paramInit); }); return params as PageParams; diff --git a/src/renderer/navigation/page-param.ts b/src/renderer/navigation/page-param.ts index 5ab31f2d73..5f71bbe795 100644 --- a/src/renderer/navigation/page-param.ts +++ b/src/renderer/navigation/page-param.ts @@ -20,10 +20,11 @@ export class PageParam { protected urlName: string; constructor(readonly init: PageParamInit, protected history: IObservableHistory) { - const { isSystem, name, skipEmpty = true } = init; + const { isSystem, name } = init; this.name = name; - this.init.skipEmpty = skipEmpty; + this.init.skipEmpty ??= true; + this.init.multiValueSep ??= ","; // prefixing to avoid collisions with extensions this.urlName = `${isSystem ? PageParam.SYSTEM_PREFIX : ""}${name}`; @@ -129,12 +130,3 @@ export class PageParam { }; } } - -export function isPageParamInit(paramInit: PageParamInit | any = {}): paramInit is PageParamInit { - const init: PageParamInit = paramInit; - - return [ - init.defaultValue !== undefined || init.defaultValueStringified !== undefined, - typeof init.parse === "function" && typeof init.stringify === "function", - ].some(Boolean); -}