From 97f2ecd88de65fc754cc3679ab735963945ef4bc Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Thu, 3 Jun 2021 09:44:48 -0400 Subject: [PATCH] review comments Signed-off-by: Sebastian Malton --- src/renderer/api/api-manager.ts | 2 +- src/renderer/components/table/table.tsx | 2 +- src/renderer/kube-object.store.ts | 46 ++++++++++++------------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/renderer/api/api-manager.ts b/src/renderer/api/api-manager.ts index adfdb42572..03c85a248c 100644 --- a/src/renderer/api/api-manager.ts +++ b/src/renderer/api/api-manager.ts @@ -82,7 +82,7 @@ export class ApiManager { }); } - getStore>(api: string | KubeApi): S { + getStore>(api: string | KubeApi): S | undefined { return this.stores.get(this.resolveApi(api)?.apiBase) as S; } } diff --git a/src/renderer/components/table/table.tsx b/src/renderer/components/table/table.tsx index bf6b6d3197..bb5e63f570 100644 --- a/src/renderer/components/table/table.tsx +++ b/src/renderer/components/table/table.tsx @@ -171,7 +171,7 @@ export class Table extends React.Component> { }); } - getContent() { + private getContent() { const { items, renderRow, children } = this.props; const content = React.Children.toArray(children) as (TableRowElem | TableHeadElem)[]; diff --git a/src/renderer/kube-object.store.ts b/src/renderer/kube-object.store.ts index 0172a1bc83..ca3fff747d 100644 --- a/src/renderer/kube-object.store.ts +++ b/src/renderer/kube-object.store.ts @@ -37,10 +37,10 @@ export interface KubeObjectStoreLoadingParams { reqInit?: RequestInit; } -export abstract class KubeObjectStore extends ItemStore { +export abstract class KubeObjectStore extends ItemStore { static defaultContext = observable.box(); // TODO: support multiple cluster contexts - abstract api: KubeApi; + abstract api: KubeApi; public readonly limit?: number; public readonly bufferSize: number = 50000; @observable private loadedNamespaces?: string[]; @@ -64,7 +64,7 @@ export abstract class KubeObjectStore extends ItemStore return KubeObjectStore.defaultContext.get(); } - @computed get contextItems(): K[] { + @computed get contextItems(): T[] { const namespaces = this.context?.contextNamespaces ?? []; return this.items.filter(item => { @@ -88,9 +88,9 @@ export abstract class KubeObjectStore extends ItemStore return { limit }; } - getStatuses?(items: K[]): Record; + getStatuses?(items: T[]): Record; - getAllByNs(namespace: string | string[], strict = false): K[] { + getAllByNs(namespace: string | string[], strict = false): T[] { const namespaces: string[] = [].concat(namespace); if (namespaces.length) { @@ -108,7 +108,7 @@ export abstract class KubeObjectStore extends ItemStore return this.items.find(item => item.getId() === id); } - getByName(name: string, namespace?: string): K { + getByName(name: string, namespace?: string): T { return this.items.find(item => { return item.getName() === name && ( namespace ? item.getNs() === namespace : true @@ -116,19 +116,19 @@ export abstract class KubeObjectStore extends ItemStore }); } - getByPath(path: string): K { + getByPath(path: string): T { return this.items.find(item => item.selfLink === path); } - getByLabel(labels: string[] | { [label: string]: string }): K[] { + getByLabel(labels: string[] | { [label: string]: string }): T[] { if (Array.isArray(labels)) { - return this.items.filter((item: K) => { + return this.items.filter((item: T) => { const itemLabels = item.getLabels(); return labels.every(label => itemLabels.includes(label)); }); } else { - return this.items.filter((item: K) => { + return this.items.filter((item: T) => { const itemLabels = item.metadata.labels || {}; return Object.entries(labels) @@ -137,7 +137,7 @@ export abstract class KubeObjectStore extends ItemStore } } - protected async loadItems({ namespaces, api, reqInit }: KubeObjectStoreLoadingParams): Promise { + protected async loadItems({ namespaces, api, reqInit }: KubeObjectStoreLoadingParams): Promise { if (this.context?.cluster.isAllowedResource(api.kind)) { if (!api.isNamespaced) { return api.list({ reqInit }, this.query); @@ -163,12 +163,12 @@ export abstract class KubeObjectStore extends ItemStore return []; } - protected filterItemsOnLoad(items: K[]) { + protected filterItemsOnLoad(items: T[]) { return items; } @action - async loadAll(options: { namespaces?: string[], merge?: boolean, reqInit?: RequestInit } = {}): Promise { + async loadAll(options: { namespaces?: string[], merge?: boolean, reqInit?: RequestInit } = {}): Promise { await this.contextReady; this.isLoading = true; @@ -215,7 +215,7 @@ export abstract class KubeObjectStore extends ItemStore } @action - protected mergeItems(partialItems: K[], { replace = false, updateStore = true, sort = true, filter = true } = {}): K[] { + protected mergeItems(partialItems: T[], { replace = false, updateStore = true, sort = true, filter = true } = {}): T[] { let items = partialItems; // update existing items @@ -239,12 +239,12 @@ export abstract class KubeObjectStore extends ItemStore if (error) this.reset(); } - protected async loadItem(params: { name: string; namespace?: string }): Promise { + protected async loadItem(params: { name: string; namespace?: string }): Promise { return this.api.get(params); } @action - async load(params: { name: string; namespace?: string }): Promise { + async load(params: { name: string; namespace?: string }): Promise { const { name, namespace } = params; let item = this.getByName(name, namespace); @@ -265,11 +265,11 @@ export abstract class KubeObjectStore extends ItemStore return this.load({ name, namespace }); } - protected async createItem(params: { name: string; namespace?: string }, data?: Partial): Promise { + protected async createItem(params: { name: string; namespace?: string }, data?: Partial): Promise { return this.api.create(params, data); } - async create(params: { name: string; namespace?: string }, data?: Partial): Promise { + async create(params: { name: string; namespace?: string }, data?: Partial): Promise { const newItem = await this.createItem(params, data); const items = this.sortItems([...this.items, newItem]); @@ -278,7 +278,7 @@ export abstract class KubeObjectStore extends ItemStore return newItem; } - async update(item: K, data: Partial): Promise { + async update(item: T, data: Partial): Promise { const newItem = await item.update(data); ensureObjectSelfLink(this.api, newItem); @@ -290,7 +290,7 @@ export abstract class KubeObjectStore extends ItemStore return newItem; } - async remove(item: K) { + async remove(item: T) { await item.delete(); this.items.remove(item); this.selectedItemsIds.delete(item.getId()); @@ -352,7 +352,7 @@ export abstract class KubeObjectStore extends ItemStore }; } - private watchNamespace(api: KubeApi, namespace: string, abortController: AbortController) { + private watchNamespace(api: KubeApi, namespace: string, abortController: AbortController) { let timedRetry: NodeJS.Timeout; const watch = () => api.watch({ namespace, @@ -362,7 +362,7 @@ export abstract class KubeObjectStore extends ItemStore const { signal } = abortController; - const callback = (data: IKubeWatchEvent, error: any) => { + const callback = (data: IKubeWatchEvent, error: any) => { if (!this.isLoaded || error instanceof DOMException) return; if (error instanceof Response) { @@ -410,7 +410,7 @@ export abstract class KubeObjectStore extends ItemStore switch (type) { case "ADDED": case "MODIFIED": - const newItem = new api.objectConstructor(object) as K; + const newItem = new api.objectConstructor(object) as T; if (!item) { items.push(newItem);