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();
|
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[] {
|
||||||
|
|||||||
@ -112,11 +112,13 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
disposeOnUnmount(this, [
|
if (!this.props.isClusterScoped) {
|
||||||
namespaceStore.onContextChange(() => this.loadStores(), {
|
disposeOnUnmount(this, [
|
||||||
fireImmediately: true,
|
namespaceStore.onContextChange(() => this.loadStores(), {
|
||||||
})
|
fireImmediately: true,
|
||||||
]);
|
})
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentWillUnmount() {
|
async componentWillUnmount() {
|
||||||
@ -124,7 +126,7 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
|||||||
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;
|
||||||
|
|||||||
@ -99,8 +99,14 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
|
|||||||
let items: T[];
|
let items: T[];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { namespaceStore } = await import("./components/+namespaces/namespace.store");
|
let contextNamespaces = params.namespaces;
|
||||||
const contextNamespaces = params.namespaces || namespaceStore.getContextNamespaces();
|
|
||||||
|
if (!params.namespaces) {
|
||||||
|
const { namespaceStore } = await import("./components/+namespaces/namespace.store");
|
||||||
|
|
||||||
|
await namespaceStore.whenReady;
|
||||||
|
contextNamespaces = namespaceStore.getContextNamespaces();
|
||||||
|
}
|
||||||
|
|
||||||
items = await this.loadItems({
|
items = await this.loadItems({
|
||||||
isAdmin: getHostedCluster().isAdmin,
|
isAdmin: getHostedCluster().isAdmin,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user