1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

example-extension reworks (3): wrap example-extension into main-layout

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2020-09-08 16:03:47 +03:00 committed by Lauri Nevala
parent 89bc526e4d
commit c6cb8adbcf
3 changed files with 20 additions and 6 deletions

View File

@ -1,4 +1,4 @@
import { DynamicPageType, Icon, LensExtension } from "@lens/extensions"; // fixme: map to generated types from "extension-api.d.ts" import { DynamicPageType, Icon, LensExtension } from "@lens/extensions"; // fixme: map to generated types from "extension-api.ts"
import React from "react"; import React from "react";
import path from "path"; import path from "path";
@ -7,12 +7,18 @@ export default class ExampleExtension extends LensExtension {
onActivate() { onActivate() {
console.log('EXAMPLE EXTENSION: ACTIVATE', this.getMeta()) console.log('EXAMPLE EXTENSION: ACTIVATE', this.getMeta())
this.unRegisterPage = this.runtime.dynamicPages.register({ const { dynamicPages, components: { MainLayout } } = this.runtime;
this.unRegisterPage = dynamicPages.register({
type: DynamicPageType.CLUSTER, type: DynamicPageType.CLUSTER,
path: "/extension-example", path: "/extension-example",
menuTitle: "Example Extension", menuTitle: "Example Extension",
components: { components: {
Page: ExtensionPage, Page: () => (
<MainLayout>
<ExtensionPage/>
</MainLayout>
),
MenuIcon: ExtensionIcon, MenuIcon: ExtensionIcon,
} }
}) })

View File

@ -1,15 +1,23 @@
// Lens renderer runtime params available to the extension after activation // Lens renderer runtime params available to extensions after activation
import logger from "../main/logger"; import logger from "../main/logger";
import { dynamicPages } from "./register-page"; import { dynamicPages } from "./register-page";
import { MainLayout } from "../renderer/components/layout/main-layout";
export interface LensRuntimeRendererEnv { export interface LensRuntimeRendererEnv {
logger: typeof logger; logger: typeof logger;
dynamicPages: typeof dynamicPages dynamicPages: typeof dynamicPages
components: {
MainLayout: typeof MainLayout
}
} }
export function getLensRuntime(): LensRuntimeRendererEnv { export function getLensRuntime(): LensRuntimeRendererEnv {
return { return {
logger, logger,
dynamicPages, dynamicPages,
components: {
MainLayout // fixme: refactor, import as pure component from "@lens/extensions"
}
} }
} }

View File

@ -17,7 +17,7 @@ export interface TabRoute extends RouteProps {
url: string; url: string;
} }
interface Props { export interface MainLayoutProps {
className?: any; className?: any;
tabs?: TabRoute[]; tabs?: TabRoute[];
footer?: React.ReactNode; footer?: React.ReactNode;
@ -27,7 +27,7 @@ interface Props {
} }
@observer @observer
export class MainLayout extends React.Component<Props> { export class MainLayout extends React.Component<MainLayoutProps> {
public storage = createStorage("main_layout", { pinnedSidebar: true }); public storage = createStorage("main_layout", { pinnedSidebar: true });
@observable isPinned = this.storage.get().pinnedSidebar; @observable isPinned = this.storage.get().pinnedSidebar;