mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Typed catalog category events (#2812)
* typesafe catalog category events Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * use emit Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * rename events Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
c8e2f7ca2d
commit
cd96842750
@ -361,6 +361,7 @@
|
|||||||
"ts-loader": "^7.0.5",
|
"ts-loader": "^7.0.5",
|
||||||
"ts-node": "^8.10.2",
|
"ts-node": "^8.10.2",
|
||||||
"type-fest": "^1.0.2",
|
"type-fest": "^1.0.2",
|
||||||
|
"typed-emitter": "^1.3.1",
|
||||||
"typedoc": "0.17.0-3",
|
"typedoc": "0.17.0-3",
|
||||||
"typedoc-plugin-markdown": "^2.4.0",
|
"typedoc-plugin-markdown": "^2.4.0",
|
||||||
"typeface-roboto": "^0.0.75",
|
"typeface-roboto": "^0.0.75",
|
||||||
|
|||||||
@ -165,7 +165,7 @@ export class KubernetesClusterCategory extends CatalogCategory {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.on("onCatalogAddMenu", (ctx: CatalogEntityAddMenuContext) => {
|
this.on("catalogAddMenu", (ctx: CatalogEntityAddMenuContext) => {
|
||||||
ctx.menuItems.push({
|
ctx.menuItems.push({
|
||||||
icon: "text_snippet",
|
icon: "text_snippet",
|
||||||
title: "Add from kubeconfig",
|
title: "Add from kubeconfig",
|
||||||
|
|||||||
@ -19,7 +19,8 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { EventEmitter } from "events";
|
import EventEmitter from "events";
|
||||||
|
import type TypedEmitter from "typed-emitter";
|
||||||
import { observable, makeObservable } from "mobx";
|
import { observable, makeObservable } from "mobx";
|
||||||
|
|
||||||
type ExtractEntityMetadataType<Entity> = Entity extends CatalogEntity<infer Metadata> ? Metadata : never;
|
type ExtractEntityMetadataType<Entity> = Entity extends CatalogEntity<infer Metadata> ? Metadata : never;
|
||||||
@ -47,7 +48,13 @@ export interface CatalogCategorySpec {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class CatalogCategory extends EventEmitter {
|
export interface CatalogCategoryEvents {
|
||||||
|
load: () => void;
|
||||||
|
catalogAddMenu: (context: CatalogEntityAddMenuContext) => void;
|
||||||
|
contextMenuOpen: (entity: CatalogEntity, context: CatalogEntityContextMenuContext) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export abstract class CatalogCategory extends (EventEmitter as new () => TypedEmitter<CatalogCategoryEvents>) {
|
||||||
abstract readonly apiVersion: string;
|
abstract readonly apiVersion: string;
|
||||||
abstract readonly kind: string;
|
abstract readonly kind: string;
|
||||||
abstract metadata: {
|
abstract metadata: {
|
||||||
|
|||||||
@ -55,7 +55,7 @@ export class CatalogAddButton extends React.Component<CatalogAddButtonProps> {
|
|||||||
menuItems: this.menuItems
|
menuItems: this.menuItems
|
||||||
};
|
};
|
||||||
|
|
||||||
category.emit("onCatalogAddMenu", context);
|
category.emit("catalogAddMenu", context);
|
||||||
}
|
}
|
||||||
}, { fireImmediately: true })
|
}, { fireImmediately: true })
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -23,9 +23,8 @@ import { action, computed, IReactionDisposer, makeObservable, observable, reacti
|
|||||||
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
||||||
import type { CatalogEntity, CatalogEntityActionContext } from "../../api/catalog-entity";
|
import type { CatalogEntity, CatalogEntityActionContext } from "../../api/catalog-entity";
|
||||||
import { ItemObject, ItemStore } from "../../item.store";
|
import { ItemObject, ItemStore } from "../../item.store";
|
||||||
import { CatalogCategory } from "../../../common/catalog";
|
import { CatalogCategory, catalogCategoryRegistry } from "../../../common/catalog";
|
||||||
import { autoBind } from "../../../common/utils";
|
import { autoBind } from "../../../common/utils";
|
||||||
|
|
||||||
export class CatalogEntityItem implements ItemObject {
|
export class CatalogEntityItem implements ItemObject {
|
||||||
constructor(public entity: CatalogEntity) {}
|
constructor(public entity: CatalogEntity) {}
|
||||||
|
|
||||||
@ -111,6 +110,14 @@ export class CatalogEntityStore extends ItemStore<CatalogEntityItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadAll() {
|
loadAll() {
|
||||||
|
if (this.activeCategory) {
|
||||||
|
this.activeCategory.emit("load");
|
||||||
|
} else {
|
||||||
|
for (const category of catalogCategoryRegistry.items) {
|
||||||
|
category.emit("load");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return this.loadItems(() => this.entities);
|
return this.loadItems(() => this.entities);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14413,6 +14413,11 @@ type-is@~1.6.17, type-is@~1.6.18:
|
|||||||
media-typer "0.3.0"
|
media-typer "0.3.0"
|
||||||
mime-types "~2.1.24"
|
mime-types "~2.1.24"
|
||||||
|
|
||||||
|
typed-emitter@^1.3.1:
|
||||||
|
version "1.3.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/typed-emitter/-/typed-emitter-1.3.1.tgz#c98d71551a99d5f08ba9085ee44b8fc9b2357502"
|
||||||
|
integrity sha512-2h7utWyXgd2R2u2IuL8B4yu1gqMxbgUj2VS/MGVbFhEVQNJKXoQQoS5CBMh+eW31zFeSmDfEQ3qQf4xy5SlPVQ==
|
||||||
|
|
||||||
typedarray-to-buffer@^3.1.5:
|
typedarray-to-buffer@^3.1.5:
|
||||||
version "3.1.5"
|
version "3.1.5"
|
||||||
resolved "https://registry.yarnpkg.com/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz#a97ee7a9ff42691b9f783ff1bc5112fe3fca9080"
|
resolved "https://registry.yarnpkg.com/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz#a97ee7a9ff42691b9f783ff1bc5112fe3fca9080"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user