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

Finish up CatalogEntity.getId() replacements

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-01-27 09:44:12 -05:00
parent 609861091c
commit 682d3211ce
8 changed files with 20 additions and 20 deletions

View File

@ -67,22 +67,22 @@ export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata,
async connect(): Promise<void> { async connect(): Promise<void> {
if (app) { if (app) {
await ClusterStore.getInstance().getById(this.metadata.uid)?.activate(); await ClusterStore.getInstance().getById(this.getId())?.activate();
} else { } else {
await requestMain(clusterActivateHandler, this.metadata.uid, false); await requestMain(clusterActivateHandler, this.getId(), false);
} }
} }
async disconnect(): Promise<void> { async disconnect(): Promise<void> {
if (app) { if (app) {
ClusterStore.getInstance().getById(this.metadata.uid)?.disconnect(); ClusterStore.getInstance().getById(this.getId())?.disconnect();
} else { } else {
await requestMain(clusterDisconnectHandler, this.metadata.uid, false); await requestMain(clusterDisconnectHandler, this.getId(), false);
} }
} }
async onRun(context: CatalogEntityActionContext) { async onRun(context: CatalogEntityActionContext) {
context.navigate(`/cluster/${this.metadata.uid}`); context.navigate(`/cluster/${this.getId()}`);
} }
onDetailsOpen(): void { onDetailsOpen(): void {
@ -100,7 +100,7 @@ export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata,
icon: "settings", icon: "settings",
onClick: () => broadcastMessage( onClick: () => broadcastMessage(
IpcRendererNavigationEvents.NAVIGATE_IN_APP, IpcRendererNavigationEvents.NAVIGATE_IN_APP,
`/entity/${this.metadata.uid}/settings`, `/entity/${this.getId()}/settings`,
), ),
}); });
} }
@ -111,14 +111,14 @@ export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata,
context.menuItems.push({ context.menuItems.push({
title: "Disconnect", title: "Disconnect",
icon: "link_off", icon: "link_off",
onClick: () => requestMain(clusterDisconnectHandler, this.metadata.uid), onClick: () => requestMain(clusterDisconnectHandler, this.getId()),
}); });
break; break;
case LensKubernetesClusterStatus.DISCONNECTED: case LensKubernetesClusterStatus.DISCONNECTED:
context.menuItems.push({ context.menuItems.push({
title: "Connect", title: "Connect",
icon: "link", icon: "link",
onClick: () => context.navigate(`/cluster/${this.metadata.uid}`), onClick: () => context.navigate(`/cluster/${this.getId()}`),
}); });
break; break;
} }

View File

@ -41,7 +41,7 @@ export class ResourceStack {
} }
protected async applyResources(resources: string[], extraArgs?: string[]): Promise<string> { protected async applyResources(resources: string[], extraArgs?: string[]): Promise<string> {
const clusterModel = ClusterStore.getInstance().getById(this.cluster.metadata.uid); const clusterModel = ClusterStore.getInstance().getById(this.cluster.getId());
if (!clusterModel) { if (!clusterModel) {
throw new Error(`cluster not found`); throw new Error(`cluster not found`);
@ -54,7 +54,7 @@ export class ResourceStack {
if (app) { if (app) {
return await new ResourceApplier(clusterModel).kubectlApplyAll(resources, kubectlArgs); return await new ResourceApplier(clusterModel).kubectlApplyAll(resources, kubectlArgs);
} else { } else {
const response = await requestMain(clusterKubectlApplyAllHandler, this.cluster.metadata.uid, resources, kubectlArgs); const response = await requestMain(clusterKubectlApplyAllHandler, this.cluster.getId(), resources, kubectlArgs);
if (response.stderr) { if (response.stderr) {
throw new Error(response.stderr); throw new Error(response.stderr);
@ -65,7 +65,7 @@ export class ResourceStack {
} }
protected async deleteResources(resources: string[], extraArgs?: string[]): Promise<string> { protected async deleteResources(resources: string[], extraArgs?: string[]): Promise<string> {
const clusterModel = ClusterStore.getInstance().getById(this.cluster.metadata.uid); const clusterModel = ClusterStore.getInstance().getById(this.cluster.getId());
if (!clusterModel) { if (!clusterModel) {
throw new Error(`cluster not found`); throw new Error(`cluster not found`);
@ -78,7 +78,7 @@ export class ResourceStack {
if (app) { if (app) {
return await new ResourceApplier(clusterModel).kubectlDeleteAll(resources, kubectlArgs); return await new ResourceApplier(clusterModel).kubectlDeleteAll(resources, kubectlArgs);
} else { } else {
const response = await requestMain(clusterKubectlDeleteAllHandler, this.cluster.metadata.uid, resources, kubectlArgs); const response = await requestMain(clusterKubectlDeleteAllHandler, this.cluster.getId(), resources, kubectlArgs);
if (response.stderr) { if (response.stderr) {
throw new Error(response.stderr); throw new Error(response.stderr);

View File

@ -36,7 +36,7 @@ export class CatalogEntityRegistry {
} }
getById<T extends CatalogEntity>(id: string): T | undefined { getById<T extends CatalogEntity>(id: string): T | undefined {
return this.items.find((entity) => entity.metadata.uid === id) as T | undefined; return this.items.find(entity => entity.getId() === id) as T | undefined;
} }
getItemsForApiKind<T extends CatalogEntity>(apiVersion: string, kind: string): T[] { getItemsForApiKind<T extends CatalogEntity>(apiVersion: string, kind: string): T[] {

View File

@ -85,7 +85,7 @@ export class ClusterManager extends Singleton {
} }
protected updateEntityFromCluster(cluster: Cluster) { protected updateEntityFromCluster(cluster: Cluster) {
const index = catalogEntityRegistry.items.findIndex((entity) => entity.metadata.uid === cluster.id); const index = catalogEntityRegistry.items.findIndex((entity) => entity.getId() === cluster.id);
if (index === -1) { if (index === -1) {
return; return;
@ -169,11 +169,11 @@ export class ClusterManager extends Singleton {
@action @action
protected syncClustersFromCatalog(entities: KubernetesCluster[]) { protected syncClustersFromCatalog(entities: KubernetesCluster[]) {
for (const entity of entities) { for (const entity of entities) {
const cluster = this.store.getById(entity.metadata.uid); const cluster = this.store.getById(entity.getId());
if (!cluster) { if (!cluster) {
const model = { const model = {
id: entity.metadata.uid, id: entity.getId(),
kubeConfigPath: entity.spec.kubeconfigPath, kubeConfigPath: entity.spec.kubeconfigPath,
contextName: entity.spec.kubeconfigContext, contextName: entity.spec.kubeconfigContext,
accessibleNamespaces: entity.spec.accessibleNamespaces ?? [], accessibleNamespaces: entity.spec.accessibleNamespaces ?? [],

View File

@ -16,7 +16,7 @@ export default {
for (const hotbar of hotbars) { for (const hotbar of hotbars) {
for (let i = 0; i < hotbar.items.length; i += 1) { for (let i = 0; i < hotbar.items.length; i += 1) {
const item = hotbar.items[i]; const item = hotbar.items[i];
const entity = catalogEntityRegistry.items.find((entity) => entity.metadata.uid === item?.entity.uid); const entity = catalogEntityRegistry.items.find((entity) => entity.getId() === item?.entity.uid);
if (!entity) { if (!entity) {
// Clear disabled item // Clear disabled item

View File

@ -120,7 +120,7 @@ export class CatalogEntityRegistry {
const entity = this.categoryRegistry.getEntityForData(item); const entity = this.categoryRegistry.getEntityForData(item);
if (entity) { if (entity) {
this._entities.set(entity.metadata.uid, entity); this._entities.set(entity.getId(), entity);
} else { } else {
this.rawEntities.push(item); this.rawEntities.push(item);
} }

View File

@ -11,7 +11,7 @@ import type { CatalogEntity } from "../../api/catalog-entity";
import * as components from "./components"; import * as components from "./components";
function getClusterForEntity(entity: CatalogEntity) { function getClusterForEntity(entity: CatalogEntity) {
return ClusterStore.getInstance().getById(entity.metadata.uid); return ClusterStore.getInstance().getById(entity.getId());
} }
export function GeneralSettings({ entity }: EntitySettingViewProps) { export function GeneralSettings({ entity }: EntitySettingViewProps) {

View File

@ -50,7 +50,7 @@ export function initCatalog({ openCommandDialog }: Dependencies) {
context.menuItems.push({ context.menuItems.push({
title: "Delete", title: "Delete",
icon: "delete", icon: "delete",
onClick: () => onClusterDelete(entity.metadata.uid), onClick: () => onClusterDelete(entity.getId()),
}); });
} }
}); });