1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add default getId and getName impls

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-04-23 11:37:04 -04:00
parent 987b12d1e0
commit 3a7f53f400
3 changed files with 13 additions and 29 deletions

View File

@ -19,14 +19,6 @@ export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, Kube
public readonly apiVersion = "entity.k8slens.dev/v1alpha1"; public readonly apiVersion = "entity.k8slens.dev/v1alpha1";
public readonly kind = "KubernetesCluster"; public readonly kind = "KubernetesCluster";
getId() {
return this.metadata.uid;
}
getName() {
return this.metadata.name;
}
async onRun(context: CatalogEntityActionContext) { async onRun(context: CatalogEntityActionContext) {
context.navigate(`/cluster/${this.metadata.uid}`); context.navigate(`/cluster/${this.metadata.uid}`);
} }
@ -108,10 +100,6 @@ export class KubernetesClusterCategory extends CatalogCategory {
}); });
}); });
} }
getId() {
return `${this.spec.group}/${this.spec.names.kind}`;
}
} }
catalogCategoryRegistry.add(new KubernetesClusterCategory()); catalogCategoryRegistry.add(new KubernetesClusterCategory());

View File

@ -13,14 +13,6 @@ export class WebLink extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus,
public readonly apiVersion = "entity.k8slens.dev/v1alpha1"; public readonly apiVersion = "entity.k8slens.dev/v1alpha1";
public readonly kind = "KubernetesCluster"; public readonly kind = "KubernetesCluster";
getId() {
return this.metadata.uid;
}
getName() {
return this.metadata.name;
}
async onRun() { async onRun() {
window.open(this.spec.url, "_blank"); window.open(this.spec.url, "_blank");
} }
@ -33,7 +25,7 @@ export class WebLink extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus,
return; return;
} }
public onContextMenuOpen() { public onContextMenuOpen(): void {
return; return;
} }
} }
@ -57,10 +49,6 @@ export class WebLinkCategory extends CatalogCategory {
kind: "WebLink" kind: "WebLink"
} }
}; };
getId() {
return `${this.spec.group}/${this.spec.names.kind}`;
}
} }
catalogCategoryRegistry.add(new WebLinkCategory()); catalogCategoryRegistry.add(new WebLinkCategory());

View File

@ -35,7 +35,9 @@ export abstract class CatalogCategory extends EventEmitter {
}; };
abstract spec: CatalogCategorySpec; abstract spec: CatalogCategorySpec;
public abstract getId(): string; public getId(): string {
return `${this.spec.group}/${this.spec.names.kind}`;
}
} }
export interface CatalogEntityMetadata { export interface CatalogEntityMetadata {
@ -126,9 +128,15 @@ export abstract class CatalogEntity<
this.spec = data.spec; this.spec = data.spec;
} }
public abstract getId(): string; public getId(): string {
public abstract getName(): string; return this.metadata.uid;
public abstract onRun(context: CatalogEntityActionContext): void | Promise<void>; }
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 onDetailsOpen(context: CatalogEntityActionContext): void | Promise<void>;
public abstract onContextMenuOpen(context: CatalogEntityContextMenuContext): void | Promise<void>; public abstract onContextMenuOpen(context: CatalogEntityContextMenuContext): void | Promise<void>;
public abstract onSettingsOpen(context: CatalogEntitySettingsContext): void | Promise<void>; public abstract onSettingsOpen(context: CatalogEntitySettingsContext): void | Promise<void>;