1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2021-01-08 14:29:00 +02:00
parent 51bdfc131b
commit ddf45c2025
8 changed files with 28 additions and 31 deletions

View File

@ -67,16 +67,20 @@ export class KubeWatchApi {
// https://github.com/lensapp/lens/issues/1898
protected async getQuery() {
const { namespaceStore } = await import("../components/+namespaces/namespace.store");
await namespaceStore.whenReady;
const { isAdmin } = getHostedCluster();
return {
api: this.activeApis.map(api => {
if (isAdmin && !api.isNamespaced) {
return api.getWatchUrl();
}
if (api.isNamespaced) {
return namespaceStore.getContextNamespaces().map(namespace => api.getWatchUrl(namespace));
}
return [];
}).flat()
};

View File

@ -1,4 +1,4 @@
import { action, comparer, IReactionDisposer, IReactionOptions, observable, reaction, when } from "mobx";
import { action, comparer, IReactionDisposer, IReactionOptions, observable, reaction, toJS, when } from "mobx";
import { autobind, createStorage } from "../../utils";
import { KubeObjectStore, KubeObjectStoreLoadingParams } from "../../kube-object.store";
import { Namespace, namespacesApi } from "../../api/endpoints/namespaces.api";
@ -36,7 +36,7 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
return reaction(() => this.contextNs.toJS(), callback, {
equals: comparer.identity,
...opts,
})
});
}
private async init() {
@ -59,13 +59,10 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
equals: comparer.identity,
})
);
// auto-load allowed namespaces
disposers.push(
reaction(() => this.allowedNamespaces, () => {
this.loadAll();
this.setContext(this.initNamespaces)
}, {
reaction(() => this.allowedNamespaces, () => this.loadAll(), {
fireImmediately: true,
equals: comparer.identity,
})
@ -75,7 +72,7 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
}
get allowedNamespaces(): string[] {
return getHostedCluster().allowedNamespaces;
return toJS(getHostedCluster().allowedNamespaces);
}
get initNamespaces() {
@ -106,10 +103,12 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
}
getContextNamespaces(): string[] {
let namespaces = this.contextNs.toJS();
const namespaces = this.contextNs.toJS();
if (!namespaces.length) {
return [...this.allowedNamespaces]; // show all namespaces when nothing selected
}
return namespaces;
}
@ -143,9 +142,11 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
if (isAdmin) {
return this.api.list();
}
if (!isAllowedResource("namespaces")) {
return namespaces.map(this.getDummyNamespace);
}
return Promise.all(namespaces.map(name => this.api.get({ name })));
}

View File

@ -31,6 +31,7 @@ export class RoleBindingsStore extends KubeObjectStore<RoleBinding> {
super.loadItems({ isAdmin, namespaces, api: clusterRoleBindingApi }),
super.loadItems({ isAdmin, namespaces, api: roleBindingApi }),
]);
return items.flat();
}

View File

@ -29,6 +29,7 @@ export class RolesStore extends KubeObjectStore<Role> {
super.loadItems({ isAdmin, namespaces, api: clusterRoleApi }),
super.loadItems({ isAdmin, namespaces, api: roleApi }),
]);
return items.flat();
}

View File

@ -33,7 +33,6 @@ export class WorkloadsOverview extends React.Component<Props> {
isAllowedResource("deployments") && deploymentStore,
isAllowedResource("daemonsets") && daemonSetStore,
isAllowedResource("statefulsets") && statefulSetStore,
isAllowedResource("statefulsets") && statefulSetStore,
isAllowedResource("replicasets") && replicaSetStore,
isAllowedResource("jobs") && jobStore,
isAllowedResource("cronjobs") && cronJobStore,
@ -46,8 +45,10 @@ export class WorkloadsOverview extends React.Component<Props> {
const loadStores = async () => {
this.isLoading = true;
for (const store of stores) {
if (this.isUnmounting) break;
try {
store.reset();
await store.loadAll();
@ -58,7 +59,7 @@ export class WorkloadsOverview extends React.Component<Props> {
}
}
this.isLoading = false;
}
};
namespaceStore.onContextChange(loadStores, {
fireImmediately: true,
@ -73,23 +74,11 @@ export class WorkloadsOverview extends React.Component<Props> {
this.isUnmounting = true;
}
get contents() {
return (
<>
<OverviewStatuses/>
{isAllowedResource("events") && <Events
compact
hideFilters
className="box grow"
/>}
</>
);
}
render() {
return (
<div className="WorkloadsOverview flex column gaps">
{this.contents}
<OverviewStatuses/>
{isAllowedResource("events") && <Events compact hideFilters className="box grow"/>}
</div>
);
}

View File

@ -95,9 +95,8 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
@observable isLoaded = false;
@observable isUnmounting = false;
// default user settings (ui show-hide tweaks mostly)
@observable userSettings: ItemListLayoutUserSettings = {
showAppliedFilters: false,
showAppliedFilters: true,
};
constructor(props: ItemListLayoutProps) {
@ -140,8 +139,9 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
this.unsubscribeStores();
// load
for (let store of stores) {
for (const store of stores) {
if (this.isUnmounting) break;
try {
store.reset();
await store.loadAll();

View File

@ -34,14 +34,14 @@ export class PageFiltersStore {
namespaceStore.setContext(filteredNs);
}
}),
reaction(() => namespaceStore.contextNs.toJS(), contextNs => {
namespaceStore.onContextChange(namespaces => {
const filteredNs = this.getValues(FilterType.NAMESPACE);
const isChanged = contextNs.length !== filteredNs.length;
const isChanged = namespaces.length !== filteredNs.length;
if (isChanged) {
this.filters.replace([
...this.filters.filter(({ type }) => type !== FilterType.NAMESPACE),
...contextNs.map(ns => ({ type: FilterType.NAMESPACE, value: ns })),
...namespaces.map(ns => ({ type: FilterType.NAMESPACE, value: ns })),
]);
}
}, {

View File

@ -80,6 +80,7 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
protected async loadItems({ isAdmin, namespaces, api }: KubeObjectStoreLoadingParams): Promise<T[]> {
if (!api.isNamespaced) {
if (isAdmin) return api.list({}, this.query);
return [];
}