mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fixes
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
51bdfc131b
commit
ddf45c2025
@ -67,16 +67,20 @@ export class KubeWatchApi {
|
|||||||
// https://github.com/lensapp/lens/issues/1898
|
// https://github.com/lensapp/lens/issues/1898
|
||||||
protected async getQuery() {
|
protected async getQuery() {
|
||||||
const { namespaceStore } = await import("../components/+namespaces/namespace.store");
|
const { namespaceStore } = await import("../components/+namespaces/namespace.store");
|
||||||
|
|
||||||
await namespaceStore.whenReady;
|
await namespaceStore.whenReady;
|
||||||
const { isAdmin } = getHostedCluster();
|
const { isAdmin } = getHostedCluster();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
api: this.activeApis.map(api => {
|
api: this.activeApis.map(api => {
|
||||||
if (isAdmin && !api.isNamespaced) {
|
if (isAdmin && !api.isNamespaced) {
|
||||||
return api.getWatchUrl();
|
return api.getWatchUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (api.isNamespaced) {
|
if (api.isNamespaced) {
|
||||||
return namespaceStore.getContextNamespaces().map(namespace => api.getWatchUrl(namespace));
|
return namespaceStore.getContextNamespaces().map(namespace => api.getWatchUrl(namespace));
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}).flat()
|
}).flat()
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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 { autobind, createStorage } from "../../utils";
|
||||||
import { KubeObjectStore, KubeObjectStoreLoadingParams } from "../../kube-object.store";
|
import { KubeObjectStore, KubeObjectStoreLoadingParams } from "../../kube-object.store";
|
||||||
import { Namespace, namespacesApi } from "../../api/endpoints/namespaces.api";
|
import { Namespace, namespacesApi } from "../../api/endpoints/namespaces.api";
|
||||||
@ -36,7 +36,7 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
|||||||
return reaction(() => this.contextNs.toJS(), callback, {
|
return reaction(() => this.contextNs.toJS(), callback, {
|
||||||
equals: comparer.identity,
|
equals: comparer.identity,
|
||||||
...opts,
|
...opts,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async init() {
|
private async init() {
|
||||||
@ -62,10 +62,7 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
|||||||
|
|
||||||
// auto-load allowed namespaces
|
// auto-load allowed namespaces
|
||||||
disposers.push(
|
disposers.push(
|
||||||
reaction(() => this.allowedNamespaces, () => {
|
reaction(() => this.allowedNamespaces, () => this.loadAll(), {
|
||||||
this.loadAll();
|
|
||||||
this.setContext(this.initNamespaces)
|
|
||||||
}, {
|
|
||||||
fireImmediately: true,
|
fireImmediately: true,
|
||||||
equals: comparer.identity,
|
equals: comparer.identity,
|
||||||
})
|
})
|
||||||
@ -75,7 +72,7 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get allowedNamespaces(): string[] {
|
get allowedNamespaces(): string[] {
|
||||||
return getHostedCluster().allowedNamespaces;
|
return toJS(getHostedCluster().allowedNamespaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
get initNamespaces() {
|
get initNamespaces() {
|
||||||
@ -106,10 +103,12 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getContextNamespaces(): string[] {
|
getContextNamespaces(): string[] {
|
||||||
let namespaces = this.contextNs.toJS();
|
const namespaces = this.contextNs.toJS();
|
||||||
|
|
||||||
if (!namespaces.length) {
|
if (!namespaces.length) {
|
||||||
return [...this.allowedNamespaces]; // show all namespaces when nothing selected
|
return [...this.allowedNamespaces]; // show all namespaces when nothing selected
|
||||||
}
|
}
|
||||||
|
|
||||||
return namespaces;
|
return namespaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,9 +142,11 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
|||||||
if (isAdmin) {
|
if (isAdmin) {
|
||||||
return this.api.list();
|
return this.api.list();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isAllowedResource("namespaces")) {
|
if (!isAllowedResource("namespaces")) {
|
||||||
return namespaces.map(this.getDummyNamespace);
|
return namespaces.map(this.getDummyNamespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all(namespaces.map(name => this.api.get({ name })));
|
return Promise.all(namespaces.map(name => this.api.get({ name })));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,6 +31,7 @@ export class RoleBindingsStore extends KubeObjectStore<RoleBinding> {
|
|||||||
super.loadItems({ isAdmin, namespaces, api: clusterRoleBindingApi }),
|
super.loadItems({ isAdmin, namespaces, api: clusterRoleBindingApi }),
|
||||||
super.loadItems({ isAdmin, namespaces, api: roleBindingApi }),
|
super.loadItems({ isAdmin, namespaces, api: roleBindingApi }),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return items.flat();
|
return items.flat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,7 @@ export class RolesStore extends KubeObjectStore<Role> {
|
|||||||
super.loadItems({ isAdmin, namespaces, api: clusterRoleApi }),
|
super.loadItems({ isAdmin, namespaces, api: clusterRoleApi }),
|
||||||
super.loadItems({ isAdmin, namespaces, api: roleApi }),
|
super.loadItems({ isAdmin, namespaces, api: roleApi }),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return items.flat();
|
return items.flat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,6 @@ export class WorkloadsOverview extends React.Component<Props> {
|
|||||||
isAllowedResource("deployments") && deploymentStore,
|
isAllowedResource("deployments") && deploymentStore,
|
||||||
isAllowedResource("daemonsets") && daemonSetStore,
|
isAllowedResource("daemonsets") && daemonSetStore,
|
||||||
isAllowedResource("statefulsets") && statefulSetStore,
|
isAllowedResource("statefulsets") && statefulSetStore,
|
||||||
isAllowedResource("statefulsets") && statefulSetStore,
|
|
||||||
isAllowedResource("replicasets") && replicaSetStore,
|
isAllowedResource("replicasets") && replicaSetStore,
|
||||||
isAllowedResource("jobs") && jobStore,
|
isAllowedResource("jobs") && jobStore,
|
||||||
isAllowedResource("cronjobs") && cronJobStore,
|
isAllowedResource("cronjobs") && cronJobStore,
|
||||||
@ -46,8 +45,10 @@ export class WorkloadsOverview extends React.Component<Props> {
|
|||||||
|
|
||||||
const loadStores = async () => {
|
const loadStores = async () => {
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
|
|
||||||
for (const store of stores) {
|
for (const store of stores) {
|
||||||
if (this.isUnmounting) break;
|
if (this.isUnmounting) break;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
store.reset();
|
store.reset();
|
||||||
await store.loadAll();
|
await store.loadAll();
|
||||||
@ -58,7 +59,7 @@ export class WorkloadsOverview extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
}
|
};
|
||||||
|
|
||||||
namespaceStore.onContextChange(loadStores, {
|
namespaceStore.onContextChange(loadStores, {
|
||||||
fireImmediately: true,
|
fireImmediately: true,
|
||||||
@ -73,23 +74,11 @@ export class WorkloadsOverview extends React.Component<Props> {
|
|||||||
this.isUnmounting = true;
|
this.isUnmounting = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
get contents() {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<OverviewStatuses/>
|
|
||||||
{isAllowedResource("events") && <Events
|
|
||||||
compact
|
|
||||||
hideFilters
|
|
||||||
className="box grow"
|
|
||||||
/>}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="WorkloadsOverview flex column gaps">
|
<div className="WorkloadsOverview flex column gaps">
|
||||||
{this.contents}
|
<OverviewStatuses/>
|
||||||
|
{isAllowedResource("events") && <Events compact hideFilters className="box grow"/>}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,9 +95,8 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
|||||||
@observable isLoaded = false;
|
@observable isLoaded = false;
|
||||||
@observable isUnmounting = false;
|
@observable isUnmounting = false;
|
||||||
|
|
||||||
// default user settings (ui show-hide tweaks mostly)
|
|
||||||
@observable userSettings: ItemListLayoutUserSettings = {
|
@observable userSettings: ItemListLayoutUserSettings = {
|
||||||
showAppliedFilters: false,
|
showAppliedFilters: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(props: ItemListLayoutProps) {
|
constructor(props: ItemListLayoutProps) {
|
||||||
@ -140,8 +139,9 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
|||||||
this.unsubscribeStores();
|
this.unsubscribeStores();
|
||||||
|
|
||||||
// load
|
// load
|
||||||
for (let store of stores) {
|
for (const store of stores) {
|
||||||
if (this.isUnmounting) break;
|
if (this.isUnmounting) break;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
store.reset();
|
store.reset();
|
||||||
await store.loadAll();
|
await store.loadAll();
|
||||||
|
|||||||
@ -34,14 +34,14 @@ export class PageFiltersStore {
|
|||||||
namespaceStore.setContext(filteredNs);
|
namespaceStore.setContext(filteredNs);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
reaction(() => namespaceStore.contextNs.toJS(), contextNs => {
|
namespaceStore.onContextChange(namespaces => {
|
||||||
const filteredNs = this.getValues(FilterType.NAMESPACE);
|
const filteredNs = this.getValues(FilterType.NAMESPACE);
|
||||||
const isChanged = contextNs.length !== filteredNs.length;
|
const isChanged = namespaces.length !== filteredNs.length;
|
||||||
|
|
||||||
if (isChanged) {
|
if (isChanged) {
|
||||||
this.filters.replace([
|
this.filters.replace([
|
||||||
...this.filters.filter(({ type }) => type !== FilterType.NAMESPACE),
|
...this.filters.filter(({ type }) => type !== FilterType.NAMESPACE),
|
||||||
...contextNs.map(ns => ({ type: FilterType.NAMESPACE, value: ns })),
|
...namespaces.map(ns => ({ type: FilterType.NAMESPACE, value: ns })),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
@ -80,6 +80,7 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
|
|||||||
protected async loadItems({ isAdmin, namespaces, api }: KubeObjectStoreLoadingParams): Promise<T[]> {
|
protected async loadItems({ isAdmin, namespaces, api }: KubeObjectStoreLoadingParams): Promise<T[]> {
|
||||||
if (!api.isNamespaced) {
|
if (!api.isNamespaced) {
|
||||||
if (isAdmin) return api.list({}, this.query);
|
if (isAdmin) return api.list({}, this.query);
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user