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

+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();