mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fixes / responding to comments
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
ddf45c2025
commit
62e0f575c7
@ -60,12 +60,11 @@ export class ReleaseStore extends ItemStore<HelmRelease> {
|
|||||||
@action
|
@action
|
||||||
async loadAll() {
|
async loadAll() {
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
let items: HelmRelease[];
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
items = await this.loadItems(namespaceStore.getContextNamespaces());
|
const items = await this.loadItems(namespaceStore.getContextNamespaces());
|
||||||
items = this.sortItems(items);
|
|
||||||
this.items.replace(items);
|
this.items.replace(this.sortItems(items));
|
||||||
this.isLoaded = true;
|
this.isLoaded = true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Loading Helm Chart releases has failed: ${error}`);
|
console.error(`Loading Helm Chart releases has failed: ${error}`);
|
||||||
|
|||||||
@ -18,6 +18,19 @@ export const namespaceUrlParam = createPageParam<string[]>({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export function getDummyNamespace(name: string) {
|
||||||
|
return new Namespace({
|
||||||
|
kind: Namespace.kind,
|
||||||
|
apiVersion: "v1",
|
||||||
|
metadata: {
|
||||||
|
name,
|
||||||
|
uid: "",
|
||||||
|
resourceVersion: "",
|
||||||
|
selfLink: `/api/v1/namespaces/${name}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@autobind()
|
@autobind()
|
||||||
export class NamespaceStore extends KubeObjectStore<Namespace> {
|
export class NamespaceStore extends KubeObjectStore<Namespace> {
|
||||||
api = namespacesApi;
|
api = namespacesApi;
|
||||||
@ -59,7 +72,7 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
|||||||
equals: comparer.identity,
|
equals: comparer.identity,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// auto-load allowed namespaces
|
// auto-load allowed namespaces
|
||||||
disposers.push(
|
disposers.push(
|
||||||
reaction(() => this.allowedNamespaces, () => this.loadAll(), {
|
reaction(() => this.allowedNamespaces, () => this.loadAll(), {
|
||||||
@ -112,15 +125,6 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
|||||||
return namespaces;
|
return namespaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
getContextParams() {
|
|
||||||
return {
|
|
||||||
namespaces: this.getContextNamespaces(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
subscribe(apis = [this.api]) {
|
subscribe(apis = [this.api]) {
|
||||||
const { accessibleNamespaces } = getHostedCluster();
|
const { accessibleNamespaces } = getHostedCluster();
|
||||||
|
|
||||||
@ -144,25 +148,12 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isAllowedResource("namespaces")) {
|
if (!isAllowedResource("namespaces")) {
|
||||||
return namespaces.map(this.getDummyNamespace);
|
return namespaces.map(getDummyNamespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all(namespaces.map(name => this.api.get({ name })));
|
return Promise.all(namespaces.map(name => this.api.get({ name })));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getDummyNamespace(name: string) {
|
|
||||||
return new Namespace({
|
|
||||||
kind: "Namespace",
|
|
||||||
apiVersion: "v1",
|
|
||||||
metadata: {
|
|
||||||
name,
|
|
||||||
uid: "",
|
|
||||||
resourceVersion: "",
|
|
||||||
selfLink: `/api/v1/namespaces/${name}`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
setContext(namespaces: string[]) {
|
setContext(namespaces: string[]) {
|
||||||
this.contextNs.replace(namespaces);
|
this.contextNs.replace(namespaces);
|
||||||
|
|||||||
@ -39,9 +39,7 @@ export class WorkloadsOverview extends React.Component<Props> {
|
|||||||
isAllowedResource("events") && eventStore,
|
isAllowedResource("events") && eventStore,
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
|
|
||||||
const unsubscribeMap = new Map<KubeObjectStore, Function>(
|
const unsubscribeMap = new Map<KubeObjectStore, () => void>();
|
||||||
stores.map(store => [store, Function])
|
|
||||||
);
|
|
||||||
|
|
||||||
const loadStores = async () => {
|
const loadStores = async () => {
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
@ -52,7 +50,7 @@ export class WorkloadsOverview extends React.Component<Props> {
|
|||||||
try {
|
try {
|
||||||
store.reset();
|
store.reset();
|
||||||
await store.loadAll();
|
await store.loadAll();
|
||||||
unsubscribeMap.get(store)(); // unsubscribe previous watcher
|
unsubscribeMap.get(store)?.(); // unsubscribe previous watcher
|
||||||
unsubscribeMap.set(store, store.subscribe());
|
unsubscribeMap.set(store, store.subscribe());
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("loading store error", error);
|
console.error("loading store error", error);
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import "./item-list-layout.scss";
|
|||||||
import groupBy from "lodash/groupBy";
|
import groupBy from "lodash/groupBy";
|
||||||
|
|
||||||
import React, { ReactNode } from "react";
|
import React, { ReactNode } from "react";
|
||||||
import { computed, IReactionDisposer, observable, reaction, toJS, when } from "mobx";
|
import { computed, IReactionDisposer, observable, reaction, toJS } from "mobx";
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { ConfirmDialog, ConfirmDialogParams } from "../confirm-dialog";
|
import { ConfirmDialog, ConfirmDialogParams } from "../confirm-dialog";
|
||||||
import { Table, TableCell, TableCellProps, TableHead, TableProps, TableRow, TableRowProps, TableSortCallback } from "../table";
|
import { Table, TableCell, TableCellProps, TableHead, TableProps, TableRow, TableRowProps, TableSortCallback } from "../table";
|
||||||
@ -92,7 +92,6 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
|||||||
|
|
||||||
private watchDisposers: IReactionDisposer[] = [];
|
private watchDisposers: IReactionDisposer[] = [];
|
||||||
|
|
||||||
@observable isLoaded = false;
|
|
||||||
@observable isUnmounting = false;
|
@observable isUnmounting = false;
|
||||||
|
|
||||||
@observable userSettings: ItemListLayoutUserSettings = {
|
@observable userSettings: ItemListLayoutUserSettings = {
|
||||||
@ -122,7 +121,6 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
|||||||
|
|
||||||
async componentWillUnmount() {
|
async componentWillUnmount() {
|
||||||
this.isUnmounting = true;
|
this.isUnmounting = true;
|
||||||
await when(() => this.isLoaded);
|
|
||||||
this.unsubscribeStores();
|
this.unsubscribeStores();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,12 +133,14 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// reset
|
// reset
|
||||||
this.isLoaded = false;
|
|
||||||
this.unsubscribeStores();
|
this.unsubscribeStores();
|
||||||
|
|
||||||
// load
|
// load
|
||||||
for (const store of stores) {
|
for (const store of stores) {
|
||||||
if (this.isUnmounting) break;
|
if (this.isUnmounting) {
|
||||||
|
this.unsubscribeStores();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
store.reset();
|
store.reset();
|
||||||
@ -150,7 +150,6 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
|||||||
console.error("loading store error", error);
|
console.error("loading store error", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.isLoaded = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsubscribeStores() {
|
unsubscribeStores() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user