mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* decentralizing page url-params management -- PoC / tsc 4.1 random fixes Signed-off-by: Roman <ixrock@gmail.com> * fixes, tweak example-extension for demo Signed-off-by: Roman <ixrock@gmail.com> * lint fixes, revert tests Signed-off-by: Roman <ixrock@gmail.com> * removed occasional changes related to typescript 4.1 Signed-off-by: Roman <ixrock@gmail.com> * updated example with 2 menu-items targeting same page with different params Signed-off-by: Roman <ixrock@gmail.com> * fix: merge page url chunks with native URL()-api, simplified default page-params registration Signed-off-by: Roman <ixrock@gmail.com> * fix: make lint happy Signed-off-by: Roman <ixrock@gmail.com> * fix: unit-tests Signed-off-by: Roman <ixrock@gmail.com> * renaming by jim's request: UrlParam => PageParam (type), createUrlParam => createPageParam (helper) Signed-off-by: Roman <ixrock@gmail.com> * fix: reverting NamespaceStore public-api breaking changes Signed-off-by: Roman <ixrock@gmail.com> * lint fix Signed-off-by: Roman <ixrock@gmail.com> * fine-tuning Signed-off-by: Roman <ixrock@gmail.com> * yes, lint always unhappy Signed-off-by: Roman <ixrock@gmail.com> * fix build Signed-off-by: Roman <ixrock@gmail.com> * small fixes Signed-off-by: Roman <ixrock@gmail.com> * fix merge-conflicts Signed-off-by: Roman <ixrock@gmail.com> * removed `isSystem` page-param's init field exposed to extensions-api Signed-off-by: Roman <ixrock@gmail.com>
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { Component, Interface, K8sApi, LensRendererExtension } from "@k8slens/extensions";
|
|
import { ExamplePage, ExamplePageParams, namespaceStore } from "./page";
|
|
import React from "react";
|
|
import path from "path";
|
|
|
|
export default class ExampleExtension extends LensRendererExtension {
|
|
clusterPages: Interface.PageRegistration[] = [
|
|
{
|
|
components: {
|
|
Page: (props: Interface.PageComponentProps<ExamplePageParams>) => {
|
|
return <ExamplePage {...props} extension={this}/>;
|
|
},
|
|
},
|
|
params: {
|
|
// setup basic param "exampleId" with default value "demo"
|
|
exampleId: "demo",
|
|
|
|
// setup advanced multi-values param "selectedNamespaces" with custom parsing/stringification
|
|
selectedNamespaces: {
|
|
defaultValueStringified: ["default", "kube-system"],
|
|
multiValues: true,
|
|
parse(values: string[]) { // from URL
|
|
return values.map(name => namespaceStore.getByName(name)).filter(Boolean);
|
|
},
|
|
stringify(values: K8sApi.Namespace[]) { // to URL
|
|
return values.map(namespace => namespace.getName());
|
|
},
|
|
}
|
|
}
|
|
}
|
|
];
|
|
|
|
clusterPageMenus: Interface.ClusterPageMenuRegistration[] = [
|
|
{
|
|
title: "Example extension",
|
|
components: {
|
|
Icon: ExampleIcon,
|
|
},
|
|
},
|
|
];
|
|
}
|
|
|
|
export function ExampleIcon(props: Component.IconProps) {
|
|
return <Component.Icon {...props} material="pages" tooltip={path.basename(__filename)}/>;
|
|
}
|