added another example

Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
Jim Ehrismann committed 2020-12-18 11:07:44 -05:00
1 parent 5a24b2c5b5
commit e654af383b
2 files changed
+57 -10

No files matched your search

+22 -4
View File
@@ -92,10 +92,6 @@ export interface SimpleParamsPageParams {
@observer
export class SimpleParamsPage extends React.Component<SimpleParamsPageProps> {
async componentDidMount() {
await namespaceStore.loadAll();
}
deactivate = () => {
const { extension } = this.props;
@@ -137,3 +133,25 @@ export class SimpleParamsPage extends React.Component<SimpleParamsPageProps> {
}
}
export interface NonStringParamsPageProps extends Interface.PageComponentProps<NonStringParamsPageParams> {
extension: LensRendererExtension; // provided in "./renderer.tsx"
}
export interface NonStringParamsPageParams {
exampleId: string;
namespaceId: Number;
}
@observer
export class NonStringParamsPage extends React.Component<NonStringParamsPageProps> {
render() {
const { exampleId, namespaceId } = this.props.params;
return (
<div className="flex gaps inline">
<p>exampleId is {exampleId.get()}</p>
<p>namespaceId is {namespaceId.get()}</p>
</div>
);
}
}
+35 -6
View File
@@ -1,7 +1,8 @@
import { Component, Interface, K8sApi, LensRendererExtension } from "@k8slens/extensions";
import {
ExamplePage, ExamplePageParams, namespaceStore,
SimplePage, SimpleParamsPage, SimpleParamsPageParams
SimplePage, SimpleParamsPage, SimpleParamsPageParams,
NonStringParamsPage, NonStringParamsPageParams
} from "./page";
import React from "react";
import path from "path";
@@ -29,6 +30,20 @@ export default class ExampleExtension extends LensRendererExtension {
namespace: "default"
}
},
{
id: "page-with-non-string-params",
components: {
Page: (props: Interface.PageComponentProps<NonStringParamsPageParams>) => {
return <NonStringParamsPage {...props} extension={this}/>;
},
},
params: {
exampleId: "demo",
namespaceId: {
defaultValue: 7
}
}
},
{
id: "page-with-complicated-params",
components: {
@@ -57,14 +72,14 @@ export default class ExampleExtension extends LensRendererExtension {
clusterPageMenus: Interface.ClusterPageMenuRegistration[] = [
{
id: "top-example-menu",
// id: "top-example-menu",
title: "Example extension",
components: {
Icon: ExampleIcon,
},
},
{
parentId: "top-example-menu",
// parentId: "top-example-menu",
title: "Simple Page",
target: {
pageId: "simple-page"
@@ -74,10 +89,10 @@ export default class ExampleExtension extends LensRendererExtension {
},
},
{
parentId: "top-example-menu",
// parentId: "top-example-menu",
title: "Simple Params",
target: {
pageId: "page-with-simple-parms",
pageId: "page-with-simple-params",
params: {
exampleId: "no-secret",
namespace: "test"
@@ -88,7 +103,21 @@ export default class ExampleExtension extends LensRendererExtension {
},
},
{
parentId: "top-example-menu",
// parentId: "top-example-menu",
title: "Non-String Params",
target: {
pageId: "page-with-non-string-params",
params: {
exampleId: "A string",
namespaceId: 42
}
},
components: {
Icon: ExampleIcon,
},
},
{
// parentId: "top-example-menu",
title: "Complicated Params",
target: {
pageId: "page-with-complicated-params"