Fix reference error when opening cluster view (#3824)

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-09-20 13:01:05 +03:00
1 parent 8b3d237f3b
commit e251194cb5
2 files changed
+19 -9

No files matched your search

+17 -1
View File
@@ -31,7 +31,7 @@ import { once } from "lodash";
export type EntityFilter = (entity: CatalogEntity) => any;
export class CatalogEntityRegistry {
@observable.ref activeEntity: CatalogEntity;
@observable protected activeEntityId: string | undefined = undefined;
protected _entities = observable.map<string, CatalogEntity>([], { deep: true });
protected filters = observable.set<EntityFilter>([], {
deep: false,
@@ -46,6 +46,22 @@ export class CatalogEntityRegistry {
makeObservable(this);
}
get activeEntity(): CatalogEntity | null {
return this._entities.get(this.activeEntityId) || null;
}
set activeEntity(raw: CatalogEntity | string | null) {
if (raw) {
const id = typeof raw === "string"
? raw
: raw.getId();
this.activeEntityId = id;
} else {
this.activeEntityId = undefined;
}
}
init() {
ipcRendererOn("catalog:items", (event, items: (CatalogEntityData & CatalogEntityKindData)[]) => {
this.updateItems(items);