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

chore / small fixes

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2021-01-12 13:37:20 +02:00
parent 62e0f575c7
commit 4a8079debc
3 changed files with 45 additions and 38 deletions

View File

@ -45,13 +45,6 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
this.init(); this.init();
} }
onContextChange(callback: (contextNamespaces: string[]) => void, opts: IReactionOptions = {}): IReactionDisposer {
return reaction(() => this.contextNs.toJS(), callback, {
equals: comparer.identity,
...opts,
});
}
private async init() { private async init() {
await clusterStore.whenLoaded; await clusterStore.whenLoaded;
if (!getHostedCluster()) return; if (!getHostedCluster()) return;
@ -59,29 +52,32 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
this.isReady = true; this.isReady = true;
this.setContext(this.initNamespaces); this.setContext(this.initNamespaces);
this.onSelectedNamespacesChange();
this.onAllowedNamespacesChange();
}
const disposers: IReactionDisposer[] = []; public onContextChange(callback: (contextNamespaces: string[]) => void, opts: IReactionOptions = {}): IReactionDisposer {
return reaction(() => this.contextNs.toJS(), callback, {
equals: comparer.identity,
...opts,
});
}
// save selected namespaces to local-storage and update URL private onSelectedNamespacesChange(): IReactionDisposer {
disposers.push( return this.onContextChange(namespaces => {
this.onContextChange(namespaces => { storage.set(namespaces); // save to local-storage
storage.set(namespaces); namespaceUrlParam.set(namespaces, { replaceHistory: true }); // update url
namespaceUrlParam.set(namespaces, { replaceHistory: true });
}, { }, {
fireImmediately: true, fireImmediately: true,
equals: comparer.identity, equals: comparer.identity,
}) });
); }
// auto-load allowed namespaces private onAllowedNamespacesChange(): IReactionDisposer {
disposers.push( return reaction(() => this.allowedNamespaces, () => this.loadAll(), {
reaction(() => this.allowedNamespaces, () => this.loadAll(), {
fireImmediately: true, fireImmediately: true,
equals: comparer.identity, equals: comparer.identity,
}) });
);
return disposers;
} }
get allowedNamespaces(): string[] { get allowedNamespaces(): string[] {

View File

@ -112,19 +112,21 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
} }
async componentDidMount() { async componentDidMount() {
if (!this.props.isClusterScoped) {
disposeOnUnmount(this, [ disposeOnUnmount(this, [
namespaceStore.onContextChange(() => this.loadStores(), { namespaceStore.onContextChange(() => this.loadStores(), {
fireImmediately: true, fireImmediately: true,
}) })
]); ]);
} }
}
async componentWillUnmount() { async componentWillUnmount() {
this.isUnmounting = true; this.isUnmounting = true;
this.unsubscribeStores(); this.unsubscribeStores();
} }
async loadStores() { @computed get stores() {
const { store, dependentStores, isClusterScoped } = this.props; const { store, dependentStores, isClusterScoped } = this.props;
const stores = new Set([store, ...dependentStores]); const stores = new Set([store, ...dependentStores]);
@ -132,11 +134,14 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
stores.add(namespaceStore); stores.add(namespaceStore);
} }
// reset return stores;
this.unsubscribeStores(); }
async loadStores() {
this.unsubscribeStores(); // reset first
// load // load
for (const store of stores) { for (const store of this.stores) {
if (this.isUnmounting) { if (this.isUnmounting) {
this.unsubscribeStores(); this.unsubscribeStores();
break; break;

View File

@ -99,8 +99,14 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
let items: T[]; let items: T[];
try { try {
let contextNamespaces = params.namespaces;
if (!params.namespaces) {
const { namespaceStore } = await import("./components/+namespaces/namespace.store"); const { namespaceStore } = await import("./components/+namespaces/namespace.store");
const contextNamespaces = params.namespaces || namespaceStore.getContextNamespaces();
await namespaceStore.whenReady;
contextNamespaces = namespaceStore.getContextNamespaces();
}
items = await this.loadItems({ items = await this.loadItems({
isAdmin: getHostedCluster().isAdmin, isAdmin: getHostedCluster().isAdmin,