mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
more fixes & refactoring
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
6159ebf9d3
commit
a489d9aabe
@ -100,7 +100,6 @@ import { ExamplePage } from "./src/example-page"
|
|||||||
export default class ExampleRendererExtension extends LensRendererExtension {
|
export default class ExampleRendererExtension extends LensRendererExtension {
|
||||||
globalPages = [
|
globalPages = [
|
||||||
{
|
{
|
||||||
routePath: "/items/:id?",
|
|
||||||
components: {
|
components: {
|
||||||
Page: ExamplePage,
|
Page: ExamplePage,
|
||||||
}
|
}
|
||||||
@ -109,7 +108,6 @@ export default class ExampleRendererExtension extends LensRendererExtension {
|
|||||||
|
|
||||||
globalPageMenus = [
|
globalPageMenus = [
|
||||||
{
|
{
|
||||||
url: "/items/1",
|
|
||||||
title: "Example page", // used in icon's tooltip
|
title: "Example page", // used in icon's tooltip
|
||||||
components: {
|
components: {
|
||||||
Icon: () => <Component.Icon material="arrow"/>,
|
Icon: () => <Component.Icon material="arrow"/>,
|
||||||
@ -155,8 +153,8 @@ import { ExampleIcon, ExamplePage } from "./src/page"
|
|||||||
export default class ExampleExtension extends LensRendererExtension {
|
export default class ExampleExtension extends LensRendererExtension {
|
||||||
clusterPages = [
|
clusterPages = [
|
||||||
{
|
{
|
||||||
routePath: "/extension-example",
|
routePath: "/extension-example", // optional
|
||||||
exact: true,
|
exact: true, // optional
|
||||||
components: {
|
components: {
|
||||||
Page: () => <ExamplePage extension={this}/>,
|
Page: () => <ExamplePage extension={this}/>,
|
||||||
}
|
}
|
||||||
@ -165,7 +163,7 @@ export default class ExampleExtension extends LensRendererExtension {
|
|||||||
|
|
||||||
clusterPageMenus = [
|
clusterPageMenus = [
|
||||||
{
|
{
|
||||||
url: "/extension-example",
|
url: "/extension-example", // optional
|
||||||
title: "Example Extension",
|
title: "Example Extension",
|
||||||
components: {
|
components: {
|
||||||
Icon: ExampleIcon,
|
Icon: ExampleIcon,
|
||||||
@ -217,11 +215,8 @@ export default class ExampleExtension extends LensRendererExtension {
|
|||||||
statusBarItems = [
|
statusBarItems = [
|
||||||
{
|
{
|
||||||
item: (
|
item: (
|
||||||
<div
|
<div className="flex align-center gaps hover-highlight" onClick={() => this.navigate("/example-page")} >
|
||||||
className="flex align-center gaps hover-highlight"
|
<Component.Icon material="favorite" />
|
||||||
onClick={() => Navigation.navigate("/example-page")}
|
|
||||||
>
|
|
||||||
<Component.Icon material="favorite" smallest />
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ export default class SupportPageRendererExtension extends LensRendererExtension
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
statusBarItems = [
|
statusBarItems: Interface.StatusBarRegistration[] = [
|
||||||
{
|
{
|
||||||
item: (
|
item: (
|
||||||
<div className="flex align-center gaps hover-highlight" onClick={() => this.navigate(pageUrl)}>
|
<div className="flex align-center gaps hover-highlight" onClick={() => this.navigate(pageUrl)}>
|
||||||
|
|||||||
@ -241,8 +241,6 @@
|
|||||||
"openid-client": "^3.15.2",
|
"openid-client": "^3.15.2",
|
||||||
"path-to-regexp": "^6.1.0",
|
"path-to-regexp": "^6.1.0",
|
||||||
"proper-lockfile": "^4.1.1",
|
"proper-lockfile": "^4.1.1",
|
||||||
"react": "^16.14.0",
|
|
||||||
"react-router": "^5.2.0",
|
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
"request-promise-native": "^1.0.8",
|
"request-promise-native": "^1.0.8",
|
||||||
"semver": "^7.3.2",
|
"semver": "^7.3.2",
|
||||||
@ -363,9 +361,11 @@
|
|||||||
"postinstall-postinstall": "^2.1.0",
|
"postinstall-postinstall": "^2.1.0",
|
||||||
"progress-bar-webpack-plugin": "^2.1.0",
|
"progress-bar-webpack-plugin": "^2.1.0",
|
||||||
"raw-loader": "^4.0.1",
|
"raw-loader": "^4.0.1",
|
||||||
|
"react": "^16.14.0",
|
||||||
"react-beautiful-dnd": "^13.0.0",
|
"react-beautiful-dnd": "^13.0.0",
|
||||||
"react-dom": "^16.13.1",
|
"react-dom": "^16.13.1",
|
||||||
"react-refresh": "^0.9.0",
|
"react-refresh": "^0.9.0",
|
||||||
|
"react-router": "^5.2.0",
|
||||||
"react-router-dom": "^5.2.0",
|
"react-router-dom": "^5.2.0",
|
||||||
"react-select": "^3.1.0",
|
"react-select": "^3.1.0",
|
||||||
"react-window": "^1.8.5",
|
"react-window": "^1.8.5",
|
||||||
|
|||||||
@ -57,29 +57,29 @@ export class ExtensionLoader {
|
|||||||
loadOnMain() {
|
loadOnMain() {
|
||||||
logger.info('[EXTENSIONS-LOADER]: load on main')
|
logger.info('[EXTENSIONS-LOADER]: load on main')
|
||||||
this.autoInitExtensions((ext: LensMainExtension) => [
|
this.autoInitExtensions((ext: LensMainExtension) => [
|
||||||
registries.menuRegistry.add(ext.appMenus, { ext })
|
registries.menuRegistry.add(ext.appMenus, { key: ext })
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadOnClusterManagerRenderer() {
|
loadOnClusterManagerRenderer() {
|
||||||
logger.info('[EXTENSIONS-LOADER]: load on main renderer (cluster manager)')
|
logger.info('[EXTENSIONS-LOADER]: load on main renderer (cluster manager)')
|
||||||
this.autoInitExtensions((ext: LensRendererExtension) => [
|
this.autoInitExtensions((ext: LensRendererExtension) => [
|
||||||
registries.globalPageRegistry.add(ext.globalPages, { ext }),
|
registries.globalPageRegistry.add(ext.globalPages, { key: ext }),
|
||||||
registries.globalPageMenuRegistry.add(ext.globalPageMenus, { ext }),
|
registries.globalPageMenuRegistry.add(ext.globalPageMenus, { key: ext }),
|
||||||
registries.appPreferenceRegistry.add(ext.appPreferences, { ext }),
|
registries.appPreferenceRegistry.add(ext.appPreferences, { key: ext }),
|
||||||
registries.clusterFeatureRegistry.add(ext.clusterFeatures, { ext }),
|
registries.clusterFeatureRegistry.add(ext.clusterFeatures, { key: ext }),
|
||||||
registries.statusBarRegistry.add(ext.statusBarItems, { ext }),
|
registries.statusBarRegistry.add(ext.statusBarItems, { key: ext }),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadOnClusterRenderer() {
|
loadOnClusterRenderer() {
|
||||||
logger.info('[EXTENSIONS-LOADER]: load on cluster renderer (dashboard)')
|
logger.info('[EXTENSIONS-LOADER]: load on cluster renderer (dashboard)')
|
||||||
this.autoInitExtensions((ext: LensRendererExtension) => [
|
this.autoInitExtensions((ext: LensRendererExtension) => [
|
||||||
registries.clusterPageRegistry.add(ext.clusterPages, { ext }),
|
registries.clusterPageRegistry.add(ext.clusterPages, { key: ext }),
|
||||||
registries.clusterPageMenuRegistry.add(ext.clusterPageMenus, { ext }),
|
registries.clusterPageMenuRegistry.add(ext.clusterPageMenus, { key: ext }),
|
||||||
registries.kubeObjectMenuRegistry.add(ext.kubeObjectMenuItems, { ext }),
|
registries.kubeObjectMenuRegistry.add(ext.kubeObjectMenuItems, { key: ext }),
|
||||||
registries.kubeObjectDetailRegistry.add(ext.kubeObjectDetailItems, { ext }),
|
registries.kubeObjectDetailRegistry.add(ext.kubeObjectDetailItems, { key: ext }),
|
||||||
registries.kubeObjectStatusRegistry.add(ext.kubeObjectStatusTexts, { ext })
|
registries.kubeObjectStatusRegistry.add(ext.kubeObjectStatusTexts, { key: ext })
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -44,11 +44,11 @@ export class LensExtension {
|
|||||||
return this.manifest.description
|
return this.manifest.description
|
||||||
}
|
}
|
||||||
|
|
||||||
getPageUrl(baseUrl: string) {
|
getPageUrl(baseUrl = "") {
|
||||||
return compile(this.routePrefix)({ name: this.name }) + baseUrl
|
return compile(this.routePrefix)({ name: this.name }) + baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
getPageRoute(baseRoute: string) {
|
getPageRoute(baseRoute = "") {
|
||||||
return this.routePrefix + baseRoute;
|
return this.routePrefix + baseRoute;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,7 @@
|
|||||||
import type {
|
import type { AppPreferenceRegistration, ClusterFeatureRegistration, KubeObjectDetailRegistration, KubeObjectMenuRegistration, KubeObjectStatusRegistration, PageMenuRegistration, PageRegistration, StatusBarRegistration, } from "./registries"
|
||||||
AppPreferenceRegistration, ClusterFeatureRegistration,
|
import { ipcRenderer } from "electron"
|
||||||
KubeObjectMenuRegistration, KubeObjectDetailRegistration, StatusBarRegistration, KubeObjectStatusRegistration,
|
|
||||||
PageRegistration, PageMenuRegistration,
|
|
||||||
} from "./registries"
|
|
||||||
import { observable } from "mobx";
|
import { observable } from "mobx";
|
||||||
import { LensExtension } from "./lens-extension"
|
import { LensExtension } from "./lens-extension"
|
||||||
import { ipcRenderer } from "electron"
|
|
||||||
|
|
||||||
export class LensRendererExtension extends LensExtension {
|
export class LensRendererExtension extends LensExtension {
|
||||||
@observable.shallow globalPages: PageRegistration[] = []
|
@observable.shallow globalPages: PageRegistration[] = []
|
||||||
@ -20,6 +16,6 @@ export class LensRendererExtension extends LensExtension {
|
|||||||
@observable.shallow kubeObjectMenuItems: KubeObjectMenuRegistration[] = []
|
@observable.shallow kubeObjectMenuItems: KubeObjectMenuRegistration[] = []
|
||||||
|
|
||||||
navigate(location: string) {
|
navigate(location: string) {
|
||||||
ipcRenderer.emit("renderer:navigate", location)
|
ipcRenderer.emit("renderer:navigate", this.getPageUrl(location))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
import type React from "react"
|
import type React from "react"
|
||||||
import { BaseRegistry } from "./base-registry";
|
import { BaseRegistry, BaseRegistryItem } from "./base-registry";
|
||||||
|
|
||||||
export interface AppPreferenceComponents {
|
export interface AppPreferenceComponents {
|
||||||
Hint: React.ComponentType<any>;
|
Hint: React.ComponentType<any>;
|
||||||
Input: React.ComponentType<any>;
|
Input: React.ComponentType<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AppPreferenceRegistration {
|
export interface AppPreferenceRegistration extends BaseRegistryItem {
|
||||||
title: string;
|
title: string;
|
||||||
components: AppPreferenceComponents;
|
components: AppPreferenceComponents;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,24 @@
|
|||||||
// Base class for extensions-api registries
|
// Base class for extensions-api registries
|
||||||
import { action, observable } from "mobx";
|
import { action, observable } from "mobx";
|
||||||
import { LensExtension } from "../lens-extension";
|
import { LensExtension } from "../lens-extension";
|
||||||
|
import { getRandId } from "../../common/utils";
|
||||||
|
|
||||||
|
export type BaseRegistryKey = LensExtension | null;
|
||||||
|
export type BaseRegistryItemId = string | symbol;
|
||||||
|
|
||||||
|
export interface BaseRegistryItem {
|
||||||
|
id?: BaseRegistryItemId; // uniq id, generated automatically when not provided
|
||||||
|
}
|
||||||
|
|
||||||
export interface BaseRegistryAddMeta {
|
export interface BaseRegistryAddMeta {
|
||||||
ext?: LensExtension | null;
|
key?: BaseRegistryKey;
|
||||||
merge?: boolean
|
merge?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BaseRegistry<T extends object = any> {
|
export class BaseRegistry<T extends BaseRegistryItem = any> {
|
||||||
private items = observable.map<LensExtension, T[]>([], { deep: false });
|
private items = observable.map<BaseRegistryKey, T[]>([], { deep: false });
|
||||||
|
|
||||||
getItems(): (T & { extension?: LensExtension })[] {
|
getItems(): (T & { extension?: LensExtension | null })[] {
|
||||||
return Array.from(this.items).map(([ext, items]) => {
|
return Array.from(this.items).map(([ext, items]) => {
|
||||||
return items.map(item => ({
|
return items.map(item => ({
|
||||||
...item,
|
...item,
|
||||||
@ -19,29 +27,39 @@ export class BaseRegistry<T extends object = any> {
|
|||||||
}).flat()
|
}).flat()
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
getById(itemId: BaseRegistryItemId, key?: BaseRegistryKey): T {
|
||||||
add(items: T | T[], { ext = null, merge = true }: BaseRegistryAddMeta = {}) {
|
const byId = (item: BaseRegistryItem) => item.id === itemId;
|
||||||
const itemsList: T[] = Array.isArray(items) ? items : [items];
|
if (key) {
|
||||||
if (merge && this.items.has(ext)) {
|
return this.items.get(key)?.find(byId)
|
||||||
const newItems = new Set(this.items.get(ext));
|
|
||||||
itemsList.forEach(item => newItems.add(item))
|
|
||||||
this.items.set(ext, [...newItems]);
|
|
||||||
} else {
|
|
||||||
this.items.set(ext, itemsList);
|
|
||||||
}
|
}
|
||||||
return () => this.remove(itemsList, ext)
|
return this.getItems().find(byId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
remove(items: T[], key: LensExtension = null) {
|
add(items: T | T[], { key = null, merge = true }: BaseRegistryAddMeta = {}) {
|
||||||
|
const normalizedItems = (Array.isArray(items) ? items : [items]).map((item: T) => {
|
||||||
|
item.id = item.id || getRandId();
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
if (merge && this.items.has(key)) {
|
||||||
|
const newItems = new Set(this.items.get(key));
|
||||||
|
normalizedItems.forEach(item => newItems.add(item))
|
||||||
|
this.items.set(key, [...newItems]);
|
||||||
|
} else {
|
||||||
|
this.items.set(key, normalizedItems);
|
||||||
|
}
|
||||||
|
return () => this.remove(normalizedItems, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
remove(items: T[], key: BaseRegistryKey = null) {
|
||||||
const storedItems = this.items.get(key);
|
const storedItems = this.items.get(key);
|
||||||
if (storedItems) {
|
if (!storedItems) return;
|
||||||
const newItems = storedItems.filter(item => !items.includes(item)); // works because of {deep: false};
|
const newItems = storedItems.filter(item => !items.includes(item)); // works because of {deep: false};
|
||||||
if (newItems.length > 0) {
|
if (newItems.length > 0) {
|
||||||
this.items.set(key, newItems)
|
this.items.set(key, newItems)
|
||||||
} else {
|
} else {
|
||||||
this.items.delete(key);
|
this.items.delete(key);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,18 @@
|
|||||||
import type React from "react"
|
import type React from "react"
|
||||||
import { BaseRegistry } from "./base-registry";
|
import { BaseRegistry, BaseRegistryItem } from "./base-registry";
|
||||||
import { ClusterFeature } from "../cluster-feature";
|
import { ClusterFeature } from "../cluster-feature";
|
||||||
|
|
||||||
export interface ClusterFeatureComponents {
|
export interface ClusterFeatureComponents {
|
||||||
Description: React.ComponentType<any>;
|
Description: React.ComponentType<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ClusterFeatureRegistration {
|
export interface ClusterFeatureRegistration extends BaseRegistryItem {
|
||||||
title: string;
|
title: string;
|
||||||
components: ClusterFeatureComponents
|
components: ClusterFeatureComponents
|
||||||
feature: ClusterFeature
|
feature: ClusterFeature
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ClusterFeatureRegistry extends BaseRegistry<ClusterFeatureRegistration> {}
|
export class ClusterFeatureRegistry extends BaseRegistry<ClusterFeatureRegistration> {
|
||||||
|
}
|
||||||
|
|
||||||
export const clusterFeatureRegistry = new ClusterFeatureRegistry()
|
export const clusterFeatureRegistry = new ClusterFeatureRegistry()
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import { BaseRegistry } from "./base-registry";
|
import { BaseRegistry, BaseRegistryItem } from "./base-registry";
|
||||||
|
|
||||||
export interface KubeObjectDetailComponents {
|
export interface KubeObjectDetailComponents {
|
||||||
Details: React.ComponentType<any>;
|
Details: React.ComponentType<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface KubeObjectDetailRegistration {
|
export interface KubeObjectDetailRegistration extends BaseRegistryItem {
|
||||||
kind: string;
|
kind: string;
|
||||||
apiVersions: string[];
|
apiVersions: string[];
|
||||||
components: KubeObjectDetailComponents;
|
components: KubeObjectDetailComponents;
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import { BaseRegistry } from "./base-registry";
|
import { BaseRegistry, BaseRegistryItem } from "./base-registry";
|
||||||
|
|
||||||
export interface KubeObjectMenuComponents {
|
export interface KubeObjectMenuComponents {
|
||||||
MenuItem: React.ComponentType<any>;
|
MenuItem: React.ComponentType<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface KubeObjectMenuRegistration {
|
export interface KubeObjectMenuRegistration extends BaseRegistryItem {
|
||||||
kind: string;
|
kind: string;
|
||||||
apiVersions: string[];
|
apiVersions: string[];
|
||||||
components: KubeObjectMenuComponents;
|
components: KubeObjectMenuComponents;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { KubeObject, KubeObjectStatus } from "../renderer-api/k8s-api";
|
import { KubeObject, KubeObjectStatus } from "../renderer-api/k8s-api";
|
||||||
import { BaseRegistry } from "./base-registry";
|
import { BaseRegistry, BaseRegistryItem } from "./base-registry";
|
||||||
|
|
||||||
export interface KubeObjectStatusRegistration {
|
export interface KubeObjectStatusRegistration extends BaseRegistryItem {
|
||||||
kind: string;
|
kind: string;
|
||||||
apiVersions: string[];
|
apiVersions: string[];
|
||||||
resolve: (object: KubeObject) => KubeObjectStatus;
|
resolve: (object: KubeObject) => KubeObjectStatus;
|
||||||
|
|||||||
@ -2,28 +2,26 @@
|
|||||||
|
|
||||||
import type React from "react";
|
import type React from "react";
|
||||||
import type { IconProps } from "../../renderer/components/icon";
|
import type { IconProps } from "../../renderer/components/icon";
|
||||||
import { BaseRegistry } from "./base-registry";
|
import { BaseRegistry, BaseRegistryItem, BaseRegistryItemId } from "./base-registry";
|
||||||
import { matchPath } from "react-router";
|
|
||||||
|
|
||||||
export interface PageMenuRegistration {
|
export interface PageMenuRegistration extends BaseRegistryItem {
|
||||||
url: string;
|
id: BaseRegistryItemId; // required id from page-registry item to match with
|
||||||
|
url?: string; // when not provided initial extension's path used, e.g. "/extension/lens-extension-name"
|
||||||
title: React.ReactNode;
|
title: React.ReactNode;
|
||||||
components: PageMenuComponents;
|
components: PageMenuComponents;
|
||||||
subMenus?: Omit<PageMenuRegistration, "components" | "subMenus">[];
|
subMenus?: PageSubMenuRegistration[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PageSubMenuRegistration {
|
||||||
|
url: string;
|
||||||
|
title: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PageMenuComponents {
|
export interface PageMenuComponents {
|
||||||
Icon: React.ComponentType<IconProps>;
|
Icon: React.ComponentType<IconProps>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PageMenuRegistry extends BaseRegistry<PageMenuRegistration> {
|
export class PageMenuRegistry<T extends PageMenuRegistration> extends BaseRegistry<T> {
|
||||||
getByMatchingRoute(routePath: string | string[], exact?: boolean) {
|
|
||||||
return this.getItems().find(item => !!matchPath(item.url, {
|
|
||||||
path: routePath,
|
|
||||||
exact,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
getItems() {
|
getItems() {
|
||||||
return super.getItems().map(item => {
|
return super.getItems().map(item => {
|
||||||
item.url = item.extension.getPageUrl(item.url)
|
item.url = item.extension.getPageUrl(item.url)
|
||||||
|
|||||||
@ -1,14 +1,19 @@
|
|||||||
// Extensions-api -> Custom page registration
|
// Extensions-api -> Custom page registration
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { matchPath } from "react-router";
|
import { BaseRegistry, BaseRegistryItem } from "./base-registry";
|
||||||
import { BaseRegistry } from "./base-registry";
|
|
||||||
|
|
||||||
export interface PageRegistration {
|
export interface PageRegistration extends BaseRegistryItem {
|
||||||
routePath: string; // react-router's path, e.g. "/page/:id"
|
routePath?: string; // additional (suffix) route path to base extension's route: "/extension/:name"
|
||||||
exact?: boolean; // route matching flag, see: https://reactrouter.com/web/api/NavLink/exact-bool
|
exact?: boolean; // route matching flag, see: https://reactrouter.com/web/api/NavLink/exact-bool
|
||||||
components: PageComponents;
|
components: PageComponents;
|
||||||
subPages?: Omit<PageRegistration, "subPages">[];
|
subPages?: SubPageRegistration[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SubPageRegistration {
|
||||||
|
routePath: string; // required for sub-pages
|
||||||
|
exact?: boolean;
|
||||||
|
components: PageComponents;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PageComponents {
|
export interface PageComponents {
|
||||||
@ -16,12 +21,6 @@ export interface PageComponents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class PageRegistry extends BaseRegistry<PageRegistration> {
|
export class PageRegistry extends BaseRegistry<PageRegistration> {
|
||||||
getByMatchingUrl(baseUrl: string) {
|
|
||||||
return this.getItems().find(({ routePath: path, exact }) => {
|
|
||||||
return !!matchPath(baseUrl, { path, exact });
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
getItems() {
|
getItems() {
|
||||||
return super.getItems().map(item => {
|
return super.getItems().map(item => {
|
||||||
item.routePath = item.extension.getPageRoute(item.routePath)
|
item.routePath = item.extension.getPageRoute(item.routePath)
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
// Extensions API -> Status bar customizations
|
// Extensions API -> Status bar customizations
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { BaseRegistry } from "./base-registry";
|
import { BaseRegistry, BaseRegistryItem } from "./base-registry";
|
||||||
|
|
||||||
export interface StatusBarRegistration {
|
export interface StatusBarRegistration extends BaseRegistryItem {
|
||||||
item?: React.ReactNode;
|
item?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -74,17 +74,17 @@ export class App extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderExtensionRoutes() {
|
renderExtensionRoutes() {
|
||||||
return clusterPageRegistry.getItems().map(({ components: { Page }, exact, routePath, subPages }) => {
|
return clusterPageRegistry.getItems().map(({ id: pageId, components: { Page }, exact, routePath, subPages }) => {
|
||||||
const Component = () => {
|
const Component = () => {
|
||||||
if (subPages) {
|
if (subPages) {
|
||||||
const tabs: TabLayoutRoute[] = subPages.map(({ exact, routePath, components: { Page } }) => {
|
const tabs: TabLayoutRoute[] = subPages.map(({ exact, routePath, components: { Page } }) => {
|
||||||
const matchingUrl = clusterPageMenuRegistry.getByMatchingRoute(routePath, exact)
|
const menuItem = clusterPageMenuRegistry.getById(pageId);
|
||||||
if (!matchingUrl) return;
|
if (!menuItem) return;
|
||||||
return {
|
return {
|
||||||
routePath, exact,
|
routePath, exact,
|
||||||
component: Page,
|
component: Page,
|
||||||
url: matchingUrl.url,
|
url: menuItem.url,
|
||||||
title: matchingUrl.title,
|
title: menuItem.title,
|
||||||
}
|
}
|
||||||
}).filter(Boolean);
|
}).filter(Boolean);
|
||||||
if (tabs.length > 0) {
|
if (tabs.length > 0) {
|
||||||
|
|||||||
@ -149,8 +149,8 @@ export class ClustersMenu extends React.Component<Props> {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="extensions">
|
<div className="extensions">
|
||||||
{globalPageMenuRegistry.getItems().map(({ title, url, components: { Icon } }) => {
|
{globalPageMenuRegistry.getItems().map(({ id: menuItemId, title, url, components: { Icon } }) => {
|
||||||
const registeredPage = globalPageRegistry.getByMatchingUrl(url);
|
const registeredPage = globalPageRegistry.getById(menuItemId);
|
||||||
if (!registeredPage) return;
|
if (!registeredPage) return;
|
||||||
const { routePath, exact } = registeredPage;
|
const { routePath, exact } = registeredPage;
|
||||||
const isActive = !!matchPath(navigation.location.pathname, { path: routePath, exact });
|
const isActive = !!matchPath(navigation.location.pathname, { path: routePath, exact });
|
||||||
|
|||||||
@ -180,8 +180,8 @@ export class Sidebar extends React.Component<Props> {
|
|||||||
>
|
>
|
||||||
{this.renderCustomResources()}
|
{this.renderCustomResources()}
|
||||||
</SidebarNavItem>
|
</SidebarNavItem>
|
||||||
{clusterPageMenuRegistry.getItems().map(({ title, url, components: { Icon } }) => {
|
{clusterPageMenuRegistry.getItems().map(({ id: menuItemId, title, url, components: { Icon } }) => {
|
||||||
const registeredPage = clusterPageRegistry.getByMatchingUrl(url);
|
const registeredPage = clusterPageRegistry.getById(menuItemId);
|
||||||
if (!registeredPage) return;
|
if (!registeredPage) return;
|
||||||
const { routePath, exact } = registeredPage;
|
const { routePath, exact } = registeredPage;
|
||||||
return (
|
return (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user