Refactor PageRegistration to separate registries/interfaces #1130 (#1144)

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman authored and GitHub committed 2020-10-26 15:40:34 +02:00
1 parent 48d8d985ae
commit 9b9bf47970
9 files changed
+35 -37

No files matched your search

+3 -3
View File
@@ -6,7 +6,7 @@ import { broadcastIpc } from "../common/ipc"
import { observable, reaction, toJS, } from "mobx"
import logger from "../main/logger"
import { app, ipcRenderer, remote } from "electron"
import { appPreferenceRegistry, kubeObjectMenuRegistry, menuRegistry, pageRegistry, statusBarRegistry, clusterFeatureRegistry } from "./registries";
import { appPreferenceRegistry, clusterFeatureRegistry, clusterPageRegistry, globalPageRegistry, kubeObjectMenuRegistry, menuRegistry, statusBarRegistry } from "./registries";
export interface InstalledExtension extends ExtensionModel {
manifestPath: string;
@@ -44,7 +44,7 @@ export class ExtensionLoader {
loadOnClusterManagerRenderer() {
logger.info('[EXTENSIONS-LOADER]: load on main renderer (cluster manager)')
this.autoloadExtensions((instance: LensRendererExtension) => {
instance.registerPages(pageRegistry)
instance.registerGlobalPage(globalPageRegistry)
instance.registerAppPreferences(appPreferenceRegistry)
instance.registerClusterFeatures(clusterFeatureRegistry)
instance.registerStatusBarIcon(statusBarRegistry)
@@ -54,7 +54,7 @@ export class ExtensionLoader {
loadOnClusterRenderer() {
logger.info('[EXTENSIONS-LOADER]: load on cluster renderer (dashboard)')
this.autoloadExtensions((instance: LensRendererExtension) => {
instance.registerPages(pageRegistry)
instance.registerClusterPage(clusterPageRegistry)
instance.registerKubeObjectMenus(kubeObjectMenuRegistry)
})
}
+6 -2
View File
@@ -1,8 +1,12 @@
import { LensExtension } from "./lens-extension"
import type { PageRegistry, AppPreferenceRegistry, StatusBarRegistry, KubeObjectMenuRegistry, ClusterFeatureRegistry } from "./registries"
import type { GlobalPageRegistry, ClusterPageRegistry, AppPreferenceRegistry, StatusBarRegistry, KubeObjectMenuRegistry, ClusterFeatureRegistry } from "./registries"
export class LensRendererExtension extends LensExtension {
registerPages(registry: PageRegistry) {
registerGlobalPage(registry: GlobalPageRegistry) {
return
}
registerClusterPage(registry: ClusterPageRegistry) {
return
}
+9 -18
View File
@@ -1,4 +1,4 @@
// Extensions-api -> Dynamic pages
// Extensions-api -> Custom page registration
import type React from "react";
import type { RouteProps } from "react-router";
@@ -6,20 +6,14 @@ import type { IconProps } from "../../renderer/components/icon";
import type { IClassName } from "../../renderer/utils";
import type { TabRoute } from "../../renderer/components/layout/tab-layout";
import { BaseRegistry } from "./base-registry";
import { computed } from "mobx";
export enum PageRegistryType {
GLOBAL = "lens-scope",
CLUSTER = "cluster-view-scope",
}
export interface PageRegistration extends RouteProps {
type: PageRegistryType;
components: PageComponents;
className?: IClassName;
url?: string; // initial url to be used for building menus and tabs, otherwise "path" applied by default
title?: React.ReactNode; // used in sidebar's & tabs-layout if provided
hideInMenu?: boolean; // hide element within app's navigation menu
subPages?: (PageRegistration & TabRoute)[];
components: PageComponents;
}
export interface PageComponents {
@@ -27,14 +21,11 @@ export interface PageComponents {
MenuIcon?: React.ComponentType<IconProps>;
}
export class PageRegistry extends BaseRegistry<PageRegistration> {
@computed get globalPages() {
return this.items.filter(page => page.type === PageRegistryType.GLOBAL);
}
@computed get clusterPages() {
return this.items.filter(page => page.type === PageRegistryType.CLUSTER);
}
export class GlobalPageRegistry extends BaseRegistry<PageRegistration> {
}
export const pageRegistry = new PageRegistry();
export class ClusterPageRegistry extends BaseRegistry<PageRegistration> {
}
export const globalPageRegistry = new GlobalPageRegistry();
export const clusterPageRegistry = new ClusterPageRegistry();