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:
parent
62e0f575c7
commit
4a8079debc
@ -45,13 +45,6 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
||||
this.init();
|
||||
}
|
||||
|
||||
onContextChange(callback: (contextNamespaces: string[]) => void, opts: IReactionOptions = {}): IReactionDisposer {
|
||||
return reaction(() => this.contextNs.toJS(), callback, {
|
||||
equals: comparer.identity,
|
||||
...opts,
|
||||
});
|
||||
}
|
||||
|
||||
private async init() {
|
||||
await clusterStore.whenLoaded;
|
||||
if (!getHostedCluster()) return;
|
||||
@ -59,29 +52,32 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
||||
this.isReady = true;
|
||||
|
||||
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
|
||||
disposers.push(
|
||||
this.onContextChange(namespaces => {
|
||||
storage.set(namespaces);
|
||||
namespaceUrlParam.set(namespaces, { replaceHistory: true });
|
||||
}, {
|
||||
fireImmediately: true,
|
||||
equals: comparer.identity,
|
||||
})
|
||||
);
|
||||
private onSelectedNamespacesChange(): IReactionDisposer {
|
||||
return this.onContextChange(namespaces => {
|
||||
storage.set(namespaces); // save to local-storage
|
||||
namespaceUrlParam.set(namespaces, { replaceHistory: true }); // update url
|
||||
}, {
|
||||
fireImmediately: true,
|
||||
equals: comparer.identity,
|
||||
});
|
||||
}
|
||||
|
||||
// auto-load allowed namespaces
|
||||
disposers.push(
|
||||
reaction(() => this.allowedNamespaces, () => this.loadAll(), {
|
||||
fireImmediately: true,
|
||||
equals: comparer.identity,
|
||||
})
|
||||
);
|
||||
|
||||
return disposers;
|
||||
private onAllowedNamespacesChange(): IReactionDisposer {
|
||||
return reaction(() => this.allowedNamespaces, () => this.loadAll(), {
|
||||
fireImmediately: true,
|
||||
equals: comparer.identity,
|
||||
});
|
||||
}
|
||||
|
||||
get allowedNamespaces(): string[] {
|
||||
|
||||
@ -112,11 +112,13 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
disposeOnUnmount(this, [
|
||||
namespaceStore.onContextChange(() => this.loadStores(), {
|
||||
fireImmediately: true,
|
||||
})
|
||||
]);
|
||||
if (!this.props.isClusterScoped) {
|
||||
disposeOnUnmount(this, [
|
||||
namespaceStore.onContextChange(() => this.loadStores(), {
|
||||
fireImmediately: true,
|
||||
})
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
async componentWillUnmount() {
|
||||
@ -124,7 +126,7 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
||||
this.unsubscribeStores();
|
||||
}
|
||||
|
||||
async loadStores() {
|
||||
@computed get stores() {
|
||||
const { store, dependentStores, isClusterScoped } = this.props;
|
||||
const stores = new Set([store, ...dependentStores]);
|
||||
|
||||
@ -132,11 +134,14 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
||||
stores.add(namespaceStore);
|
||||
}
|
||||
|
||||
// reset
|
||||
this.unsubscribeStores();
|
||||
return stores;
|
||||
}
|
||||
|
||||
async loadStores() {
|
||||
this.unsubscribeStores(); // reset first
|
||||
|
||||
// load
|
||||
for (const store of stores) {
|
||||
for (const store of this.stores) {
|
||||
if (this.isUnmounting) {
|
||||
this.unsubscribeStores();
|
||||
break;
|
||||
|
||||
@ -99,8 +99,14 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
|
||||
let items: T[];
|
||||
|
||||
try {
|
||||
const { namespaceStore } = await import("./components/+namespaces/namespace.store");
|
||||
const contextNamespaces = params.namespaces || namespaceStore.getContextNamespaces();
|
||||
let contextNamespaces = params.namespaces;
|
||||
|
||||
if (!params.namespaces) {
|
||||
const { namespaceStore } = await import("./components/+namespaces/namespace.store");
|
||||
|
||||
await namespaceStore.whenReady;
|
||||
contextNamespaces = namespaceStore.getContextNamespaces();
|
||||
}
|
||||
|
||||
items = await this.loadItems({
|
||||
isAdmin: getHostedCluster().isAdmin,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user