mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fixes, reverted logic for selecting default namespaces
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
76f9f3981d
commit
8709bc2a2e
@ -6,14 +6,14 @@ import { Namespace, namespacesApi } from "../../api/endpoints/namespaces.api";
|
|||||||
import { createPageParam } from "../../navigation";
|
import { createPageParam } from "../../navigation";
|
||||||
import { apiManager } from "../../api/api-manager";
|
import { apiManager } from "../../api/api-manager";
|
||||||
|
|
||||||
const selectedNamespaces = createStorage("selected_namespaces", ["default"]);
|
const selectedNamespaces = createStorage<string[]>("selected_namespaces");
|
||||||
|
|
||||||
export const namespaceUrlParam = createPageParam<string[]>({
|
export const namespaceUrlParam = createPageParam<string[]>({
|
||||||
name: "namespaces",
|
name: "namespaces",
|
||||||
isSystem: true,
|
isSystem: true,
|
||||||
multiValues: true,
|
multiValues: true,
|
||||||
get defaultValue() {
|
get defaultValue() {
|
||||||
return selectedNamespaces.get();
|
return selectedNamespaces.get() ?? []; // initial namespaces coming from URL or local-storage (default)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -42,8 +42,8 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async init() {
|
private async init() {
|
||||||
await selectedNamespaces.whenReady;
|
|
||||||
await this.contextReady;
|
await this.contextReady;
|
||||||
|
await selectedNamespaces.whenReady;
|
||||||
|
|
||||||
this.setContext(this.initialNamespaces);
|
this.setContext(this.initialNamespaces);
|
||||||
this.autoLoadAllowedNamespaces();
|
this.autoLoadAllowedNamespaces();
|
||||||
@ -59,8 +59,8 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
|||||||
|
|
||||||
private autoUpdateUrlAndLocalStorage(): IReactionDisposer {
|
private autoUpdateUrlAndLocalStorage(): IReactionDisposer {
|
||||||
return this.onContextChange(namespaces => {
|
return this.onContextChange(namespaces => {
|
||||||
selectedNamespaces.set(namespaces);
|
selectedNamespaces.set(namespaces); // save to local-storage
|
||||||
namespaceUrlParam.set(namespaces, { replaceHistory: true });
|
namespaceUrlParam.set(namespaces, { replaceHistory: true }); // update url
|
||||||
}, {
|
}, {
|
||||||
fireImmediately: true,
|
fireImmediately: true,
|
||||||
});
|
});
|
||||||
@ -74,10 +74,22 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private get initialNamespaces(): string[] {
|
private get initialNamespaces(): string[] {
|
||||||
const namespaces = this.allowedNamespaces;
|
const namespaces = new Set(this.allowedNamespaces);
|
||||||
|
const prevSelectedNamespaces = selectedNamespaces.get();
|
||||||
|
|
||||||
// return all namespaces (empty list) if "default" namespace doesn't exist
|
// return previously saved namespaces from local-storage (if any)
|
||||||
return selectedNamespaces.get().filter(namespace => namespaces.includes(namespace));
|
if (prevSelectedNamespaces) {
|
||||||
|
return prevSelectedNamespaces.filter(namespace => namespaces.has(namespace));
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise select "default" or first allowed namespace
|
||||||
|
if (namespaces.has("default")) {
|
||||||
|
return ["default"];
|
||||||
|
} else if (namespaces.size) {
|
||||||
|
return [Array.from(namespaces)[0]];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get allowedNamespaces(): string[] {
|
@computed get allowedNamespaces(): string[] {
|
||||||
|
|||||||
@ -11,7 +11,7 @@ export class LensLocalStorage {
|
|||||||
private folderPath = path.resolve((app || remote.app).getPath("userData"), "lens-local-storage");
|
private folderPath = path.resolve((app || remote.app).getPath("userData"), "lens-local-storage");
|
||||||
private filePath: string;
|
private filePath: string;
|
||||||
|
|
||||||
@observable state = observable.map<string, any>();
|
@observable state = observable.map<string, any>([], { deep: false });
|
||||||
@observable isLoaded = false;
|
@observable isLoaded = false;
|
||||||
whenReady = when(() => this.isLoaded);
|
whenReady = when(() => this.isLoaded);
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
import type { CreateObservableOptions } from "mobx/lib/api/observable";
|
import type { CreateObservableOptions } from "mobx/lib/api/observable";
|
||||||
import { action, comparer, observable, toJS, when } from "mobx";
|
import { action, comparer, observable, toJS, when } from "mobx";
|
||||||
import produce, { Draft, setAutoFreeze } from "immer";
|
import produce, { Draft, setAutoFreeze } from "immer";
|
||||||
import { isEmpty, isEqual, isFunction } from "lodash";
|
import { isEqual, isFunction, isObject } from "lodash";
|
||||||
|
|
||||||
setAutoFreeze(false); // allow to merge observables
|
setAutoFreeze(false); // allow to merge observables
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ export class StorageHelper<T = any> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const value = await this.load();
|
const value = await this.load();
|
||||||
const notEmpty = this.hasValue(value);
|
const notEmpty = value != null;
|
||||||
const notDefault = !this.isDefaultValue(value);
|
const notDefault = !this.isDefaultValue(value);
|
||||||
|
|
||||||
if (notEmpty && notDefault) {
|
if (notEmpty && notDefault) {
|
||||||
@ -79,11 +79,7 @@ export class StorageHelper<T = any> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hasValue(value: T) {
|
isDefaultValue(value: T): boolean {
|
||||||
return !isEmpty(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
isDefaultValue(value: T) {
|
|
||||||
return isEqual(value, this.defaultValue);
|
return isEqual(value, this.defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +132,11 @@ export class StorageHelper<T = any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
merge(value: Partial<T> | ((draft: Draft<T>) => Partial<T> | void)) {
|
merge(value: Partial<T> | ((draft: Draft<T>) => Partial<T> | void)) {
|
||||||
const updater = isFunction(value) ? value : (state: Draft<T>) => Object.assign(state, value);
|
const updater = isFunction(value) ? value : (state: Draft<T>) => {
|
||||||
|
if (isObject(state)) return Object.assign(state, value);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
};
|
||||||
const currentValue = this.toJS();
|
const currentValue = this.toJS();
|
||||||
const nextValue = produce(currentValue, updater) as T;
|
const nextValue = produce(currentValue, updater) as T;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user