1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/components/+catalog/catalog-entity.store.ts
Jari Kolehmainen 65c7a183d3 refactor
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
2021-04-06 09:19:22 +03:00

70 lines
1.4 KiB
TypeScript

import { action, computed, reaction } from "mobx";
import { CatalogEntity, catalogEntityRegistry } from "../../api/catalog-entity-registry";
import { ItemObject, ItemStore } from "../../item.store";
import { autobind } from "../../utils";
export class CatalogEntityItem implements ItemObject {
constructor(public entity: CatalogEntity) {}
get name() {
return this.entity.metadata.name;
}
getName() {
return this.entity.metadata.name;
}
get id() {
return this.entity.metadata.uid;
}
getId() {
return this.id;
}
@computed get phase() {
return this.entity.status.phase;
}
get labels() {
const labels: string[] = [];
Object.keys(this.entity.metadata.labels).forEach((key) => {
const value = this.entity.metadata.labels[key];
labels.push(`${key}=${value}`);
});
return labels;
}
get source() {
return this.entity.metadata.source || "unknown";
}
onRun(ctx: any) {
this.entity.onRun(ctx);
}
@action
async onContextMenuOpen(ctx: any) {
return this.entity.onContextMenuOpen(ctx);
}
}
@autobind()
export class CatalogEntityStore extends ItemStore<CatalogEntityItem> {
@computed get entities() {
return catalogEntityRegistry.items.map(entity => new CatalogEntityItem(entity));
}
watch() {
return reaction(() => this.entities, () => this.loadAll());
}
loadAll() {
return this.loadItems(() => this.entities);
}
}