mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* show lens-metrics on cluster settings Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove ClusterFeature Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove ClusterFeature Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * tweak resource applier/stack Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * update metrics stack components Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix drawer menu styles Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * clarify ui Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * built-in -> bundled Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * splitterError -> splitError Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * support multi-doc yamls Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * dedicated action button Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix headers Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * async file operations Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix bugs Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
168 lines
5.0 KiB
TypeScript
168 lines
5.0 KiB
TypeScript
/**
|
|
* Copyright (c) 2021 OpenLens Authors
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
* the Software without restriction, including without limitation the rights to
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
* subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
import { EventEmitter } from "events";
|
|
import { observable } from "mobx";
|
|
|
|
type ExtractEntityMetadataType<Entity> = Entity extends CatalogEntity<infer Metadata> ? Metadata : never;
|
|
type ExtractEntityStatusType<Entity> = Entity extends CatalogEntity<any, infer Status> ? Status : never;
|
|
type ExtractEntitySpecType<Entity> = Entity extends CatalogEntity<any, any, infer Spec> ? Spec : never;
|
|
|
|
export type CatalogEntityConstructor<Entity extends CatalogEntity> = (
|
|
(new (data: CatalogEntityData<
|
|
ExtractEntityMetadataType<Entity>,
|
|
ExtractEntityStatusType<Entity>,
|
|
ExtractEntitySpecType<Entity>
|
|
>) => Entity)
|
|
);
|
|
|
|
export interface CatalogCategoryVersion<Entity extends CatalogEntity> {
|
|
name: string;
|
|
entityClass: CatalogEntityConstructor<Entity>;
|
|
}
|
|
|
|
export interface CatalogCategorySpec {
|
|
group: string;
|
|
versions: CatalogCategoryVersion<CatalogEntity>[];
|
|
names: {
|
|
kind: string;
|
|
};
|
|
}
|
|
|
|
export abstract class CatalogCategory extends EventEmitter {
|
|
abstract readonly apiVersion: string;
|
|
abstract readonly kind: string;
|
|
abstract metadata: {
|
|
name: string;
|
|
icon: string;
|
|
};
|
|
abstract spec: CatalogCategorySpec;
|
|
|
|
public getId(): string {
|
|
return `${this.spec.group}/${this.spec.names.kind}`;
|
|
}
|
|
}
|
|
|
|
export interface CatalogEntityMetadata {
|
|
uid: string;
|
|
name: string;
|
|
description?: string;
|
|
source?: string;
|
|
labels: Record<string, string>;
|
|
[key: string]: string | object;
|
|
}
|
|
|
|
export interface CatalogEntityStatus {
|
|
phase: string;
|
|
reason?: string;
|
|
message?: string;
|
|
active?: boolean;
|
|
}
|
|
|
|
export interface CatalogEntityActionContext {
|
|
navigate: (url: string) => void;
|
|
setCommandPaletteContext: (context?: CatalogEntity) => void;
|
|
}
|
|
|
|
export interface CatalogEntityContextMenu {
|
|
title: string;
|
|
onlyVisibleForSource?: string; // show only if empty or if matches with entity source
|
|
onClick: () => void | Promise<void>;
|
|
confirm?: {
|
|
message: string;
|
|
}
|
|
}
|
|
|
|
export interface CatalogEntityAddMenu extends CatalogEntityContextMenu {
|
|
icon: string;
|
|
}
|
|
|
|
export interface CatalogEntitySettingsMenu {
|
|
group?: string;
|
|
title: string;
|
|
components: {
|
|
View: React.ComponentType<any>
|
|
};
|
|
}
|
|
|
|
export interface CatalogEntityContextMenuContext {
|
|
navigate: (url: string) => void;
|
|
menuItems: CatalogEntityContextMenu[];
|
|
}
|
|
|
|
export interface CatalogEntitySettingsContext {
|
|
menuItems: CatalogEntityContextMenu[];
|
|
}
|
|
|
|
export interface CatalogEntityAddMenuContext {
|
|
navigate: (url: string) => void;
|
|
menuItems: CatalogEntityAddMenu[];
|
|
}
|
|
|
|
export type CatalogEntitySpec = Record<string, any>;
|
|
|
|
export interface CatalogEntityData<
|
|
Metadata extends CatalogEntityMetadata = CatalogEntityMetadata,
|
|
Status extends CatalogEntityStatus = CatalogEntityStatus,
|
|
Spec extends CatalogEntitySpec = CatalogEntitySpec,
|
|
> {
|
|
metadata: Metadata;
|
|
status: Status;
|
|
spec: Spec;
|
|
}
|
|
|
|
export interface CatalogEntityKindData {
|
|
readonly apiVersion: string;
|
|
readonly kind: string;
|
|
}
|
|
|
|
export abstract class CatalogEntity<
|
|
Metadata extends CatalogEntityMetadata = CatalogEntityMetadata,
|
|
Status extends CatalogEntityStatus = CatalogEntityStatus,
|
|
Spec extends CatalogEntitySpec = CatalogEntitySpec,
|
|
> implements CatalogEntityKindData {
|
|
public abstract readonly apiVersion: string;
|
|
public abstract readonly kind: string;
|
|
|
|
@observable metadata: Metadata;
|
|
@observable status: Status;
|
|
@observable spec: Spec;
|
|
|
|
constructor(data: CatalogEntityData<Metadata, Status, Spec>) {
|
|
this.metadata = data.metadata;
|
|
this.status = data.status;
|
|
this.spec = data.spec;
|
|
}
|
|
|
|
public getId(): string {
|
|
return this.metadata.uid;
|
|
}
|
|
|
|
public getName(): string {
|
|
return this.metadata.name;
|
|
}
|
|
|
|
public abstract onRun?(context: CatalogEntityActionContext): void | Promise<void>;
|
|
public abstract onDetailsOpen(context: CatalogEntityActionContext): void | Promise<void>;
|
|
public abstract onContextMenuOpen(context: CatalogEntityContextMenuContext): void | Promise<void>;
|
|
public abstract onSettingsOpen(context: CatalogEntitySettingsContext): void | Promise<void>;
|
|
}
|