1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/extensions/example-extension/renderer.tsx
Sebastian Malton 17291a1709 Remove custom <Icon /> component
- Move to using Material-UI's <Icon /> and <SvgIcon />

- Move to using Material-UI's <Tooltip />

- Move to using Material-UI's <IconButton />

- Switch *.svg webpack importer so we can import then as React
  components

- Export the above to the extension API

- Move to using the Material-UI's component names for menuItem.icon's.
  This means that they are now in PascalCase instead of snake_case

- Remove the Material-UI font

Signed-off-by: Sebastian Malton <sebastian@malton.name>
2021-04-15 16:23:52 -04:00

50 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() {
return (
<Component.MuiCore.Tooltip title={path.basename(__filename)}>
<Component.Icons.Pages />
</Component.MuiCore.Tooltip>
);
}