1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

migration additions -- part 1

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2021-04-19 17:29:59 +03:00
parent 2eb512a85c
commit 9ca7104a2a
21 changed files with 54 additions and 90 deletions

View File

@ -42,8 +42,6 @@ export class ExamplePreferencesStore extends Store.ExtensionStore<ExamplePrefere
toJSON(): ExamplePreferencesModel { toJSON(): ExamplePreferencesModel {
return toJS({ return toJS({
enabled: this.enabled enabled: this.enabled
}, {
recurseEverything: true
}); });
} }
} }

View File

@ -27,8 +27,6 @@ export class SurveyPreferencesStore extends Store.ExtensionStore<SurveyPreferenc
toJSON(): SurveyPreferencesModel { toJSON(): SurveyPreferencesModel {
return toJS({ return toJS({
enabled: this.enabled enabled: this.enabled
}, {
recurseEverything: true
}); });
} }
} }

View File

@ -25,8 +25,6 @@ export class TelemetryPreferencesStore extends Store.ExtensionStore<TelemetryPre
toJSON(): TelemetryPreferencesModel { toJSON(): TelemetryPreferencesModel {
return toJS({ return toJS({
enabled: this.enabled enabled: this.enabled
}, {
recurseEverything: true
}); });
} }
} }

View File

@ -331,8 +331,6 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
return toJS({ return toJS({
activeCluster: this.activeCluster, activeCluster: this.activeCluster,
clusters: this.clustersList.map(cluster => cluster.toJSON()), clusters: this.clustersList.map(cluster => cluster.toJSON()),
}, {
recurseEverything: true
}); });
} }
} }

View File

@ -54,12 +54,8 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
} }
toJSON(): HotbarStoreModel { toJSON(): HotbarStoreModel {
const model: HotbarStoreModel = { return toJS({
hotbars: this.hotbars hotbars: this.hotbars
};
return toJS(model, {
recurseEverything: true,
}); });
} }
} }

View File

@ -18,7 +18,7 @@ export async function requestMain(channel: string, ...args: any[]) {
} }
function getSubFrames(): ClusterFrameInfo[] { function getSubFrames(): ClusterFrameInfo[] {
return toJS(Array.from(clusterFrameMap.values()), { recurseEverything: true }); return toJS(Array.from(clusterFrameMap.values()));
} }
export async function broadcastMessage(channel: string, ...args: any[]) { export async function broadcastMessage(channel: string, ...args: any[]) {

View File

@ -175,15 +175,11 @@ export class UserStore extends BaseStore<UserStoreModel> {
} }
toJSON(): UserStoreModel { toJSON(): UserStoreModel {
const model: UserStoreModel = { return toJS({
kubeConfigPath: this.kubeConfigPath, kubeConfigPath: this.kubeConfigPath,
lastSeenAppVersion: this.lastSeenAppVersion, lastSeenAppVersion: this.lastSeenAppVersion,
seenContexts: Array.from(this.seenContexts), seenContexts: Array.from(this.seenContexts),
preferences: this.preferences, preferences: this.preferences,
};
return toJS(model, {
recurseEverything: true,
}); });
} }
} }

View File

@ -453,8 +453,6 @@ export class ExtensionDiscovery {
toJSON(): ExtensionDiscoveryChannelMessage { toJSON(): ExtensionDiscoveryChannelMessage {
return toJS({ return toJS({
isLoaded: this.isLoaded isLoaded: this.isLoaded
}, {
recurseEverything: true
}); });
} }

View File

@ -319,10 +319,7 @@ export class ExtensionLoader {
} }
toJSON(): Map<LensExtensionId, InstalledExtension> { toJSON(): Map<LensExtensionId, InstalledExtension> {
return toJS(this.extensions, { return toJS(this.extensions);
exportMapsAsObjects: false,
recurseEverything: true,
});
} }
broadcastExtensions(main = true) { broadcastExtensions(main = true) {

View File

@ -47,9 +47,7 @@ export class ExtensionsStore extends BaseStore<LensExtensionsStoreModel> {
toJSON(): LensExtensionsStoreModel { toJSON(): LensExtensionsStoreModel {
return toJS({ return toJS({
extensions: this.state.toJSON(), extensions: Object.fromEntries(this.state),
}, {
recurseEverything: true
}); });
} }
} }

View File

@ -1,7 +1,7 @@
// Extensions API -> Commands // Extensions API -> Commands
import { BaseRegistry } from "./base-registry"; import { BaseRegistry } from "./base-registry";
import { action, observable } from "mobx"; import { observable } from "mobx";
import { LensExtension } from "../lens-extension"; import { LensExtension } from "../lens-extension";
import { CatalogEntity } from "../../common/catalog-entity"; import { CatalogEntity } from "../../common/catalog-entity";
@ -20,7 +20,6 @@ export interface CommandRegistration {
export class CommandRegistry extends BaseRegistry<CommandRegistration> { export class CommandRegistry extends BaseRegistry<CommandRegistration> {
@observable activeEntity: CatalogEntity; @observable activeEntity: CatalogEntity;
@action
add(items: CommandRegistration | CommandRegistration[], extension?: LensExtension) { add(items: CommandRegistration | CommandRegistration[], extension?: LensExtension) {
const itemArray = [items].flat(); const itemArray = [items].flat();

View File

@ -27,6 +27,6 @@ export class CatalogPusher {
} }
broadcast() { broadcast() {
broadcastMessage("catalog:items", toJS(this.catalog.items, { recurseEverything: true })); broadcastMessage("catalog:items", toJS(this.catalog.items));
} }
} }

View File

@ -31,7 +31,7 @@ export class ClusterManager extends Singleton {
}, { fireImmediately: true }); }, { fireImmediately: true });
reaction(() => toJS(clusterStore.enabledClustersList, { recurseEverything: true }), () => { reaction(() => toJS(clusterStore.enabledClustersList), () => {
this.updateCatalogSource(clusterStore.enabledClustersList); this.updateCatalogSource(clusterStore.enabledClustersList);
}, { fireImmediately: true }); }, { fireImmediately: true });

View File

@ -240,9 +240,7 @@ export class Cluster implements ClusterModel, ClusterState {
@computed get prometheusPreferences(): ClusterPrometheusPreferences { @computed get prometheusPreferences(): ClusterPrometheusPreferences {
const { prometheus, prometheusProvider } = this.preferences; const { prometheus, prometheusProvider } = this.preferences;
return toJS({ prometheus, prometheusProvider }, { return toJS({ prometheus, prometheusProvider });
recurseEverything: true,
});
} }
/** /**
@ -616,9 +614,7 @@ export class Cluster implements ClusterModel, ClusterState {
accessibleNamespaces: this.accessibleNamespaces, accessibleNamespaces: this.accessibleNamespaces,
}; };
return toJS(model, { return toJS(model);
recurseEverything: true
});
} }
/** /**
@ -640,9 +636,7 @@ export class Cluster implements ClusterModel, ClusterState {
isGlobalWatchEnabled: this.isGlobalWatchEnabled, isGlobalWatchEnabled: this.isGlobalWatchEnabled,
}; };
return toJS(state, { return toJS(state);
recurseEverything: true
});
} }
/** /**

View File

@ -50,9 +50,7 @@ export class FilesystemProvisionerStore extends BaseStore<FSProvisionModel> {
toJSON(): FSProvisionModel { toJSON(): FSProvisionModel {
return toJS({ return toJS({
extensions: this.registeredExtensions.toJSON(), extensions: Object.fromEntries(this.registeredExtensions.toJSON()),
}, {
recurseEverything: true
}); });
} }
} }

View File

@ -3,6 +3,8 @@ import { KubeJsonApiData } from "../kube-json-api";
import { autobind } from "../../utils"; import { autobind } from "../../utils";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
export type ConfigMapData = Record<string, string>;
@autobind() @autobind()
export class ConfigMap extends KubeObject { export class ConfigMap extends KubeObject {
static kind = "ConfigMap"; static kind = "ConfigMap";
@ -14,9 +16,7 @@ export class ConfigMap extends KubeObject {
this.data = this.data || {}; this.data = this.data || {};
} }
data: { data: ConfigMapData;
[param: string]: string;
};
getKeys(): string[] { getKeys(): string[] {
return Object.keys(this.data); return Object.keys(this.data);

View File

@ -1,7 +1,7 @@
import "./config-map-details.scss"; import "./config-map-details.scss";
import React from "react"; import React from "react";
import { autorun, observable } from "mobx"; import { observable, reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react"; import { disposeOnUnmount, observer } from "mobx-react";
import { DrawerTitle } from "../drawer"; import { DrawerTitle } from "../drawer";
import { Notifications } from "../notifications"; import { Notifications } from "../notifications";
@ -10,7 +10,7 @@ import { Button } from "../button";
import { KubeEventDetails } from "../+events/kube-event-details"; import { KubeEventDetails } from "../+events/kube-event-details";
import { configMapsStore } from "./config-maps.store"; import { configMapsStore } from "./config-maps.store";
import { KubeObjectDetailsProps } from "../kube-object"; import { KubeObjectDetailsProps } from "../kube-object";
import { ConfigMap } from "../../api/endpoints"; import { ConfigMap, ConfigMapData } from "../../api/endpoints";
import { KubeObjectMeta } from "../kube-object/kube-object-meta"; import { KubeObjectMeta } from "../kube-object/kube-object-meta";
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry"; import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
@ -20,26 +20,21 @@ interface Props extends KubeObjectDetailsProps<ConfigMap> {
@observer @observer
export class ConfigMapDetails extends React.Component<Props> { export class ConfigMapDetails extends React.Component<Props> {
@observable isSaving = false; @observable isSaving = false;
@observable data = observable.map(); @observable data: ConfigMapData = {};
async componentDidMount() { @disposeOnUnmount
disposeOnUnmount(this, [ autoCopyData = reaction(() => this.props.object, configMap => {
autorun(() => { this.data = configMap?.data ?? {}; // copy-or-update config-map's data for editing
const { object: configMap } = this.props; }, {
fireImmediately: true,
if (configMap) { });
this.data.replace(configMap.data); // refresh
}
})
]);
}
save = async () => { save = async () => {
const { object: configMap } = this.props; const { object: configMap } = this.props;
try { try {
this.isSaving = true; this.isSaving = true;
await configMapsStore.update(configMap, { ...configMap, data: this.data.toJSON() }); await configMapsStore.update(configMap, { ...configMap, data: this.data });
Notifications.ok( Notifications.ok(
<p> <p>
<>ConfigMap <b>{configMap.getName()}</b> successfully updated.</> <>ConfigMap <b>{configMap.getName()}</b> successfully updated.</>
@ -53,18 +48,21 @@ export class ConfigMapDetails extends React.Component<Props> {
render() { render() {
const { object: configMap } = this.props; const { object: configMap } = this.props;
if (!configMap) return null; if (!configMap) {
const data = Object.entries(this.data.toJSON()); return null;
}
const dataEntries = Object.entries(this.data);
return ( return (
<div className="ConfigMapDetails"> <div className="ConfigMapDetails">
<KubeObjectMeta object={configMap}/> <KubeObjectMeta object={configMap}/>
{ {
data.length > 0 && ( dataEntries.length > 0 && (
<> <>
<DrawerTitle title="Data"/> <DrawerTitle title="Data"/>
{ {
data.map(([name, value]) => { dataEntries.map(([name, value]) => {
return ( return (
<div key={name} className="data"> <div key={name} className="data">
<div className="name">{name}</div> <div className="name">{name}</div>
@ -74,7 +72,7 @@ export class ConfigMapDetails extends React.Component<Props> {
theme="round-black" theme="round-black"
className="box grow" className="box grow"
value={value} value={value}
onChange={v => this.data.set(name, v)} onChange={v => this.data[name] = v}
/> />
</div> </div>
</div> </div>

View File

@ -54,7 +54,7 @@ export class DockTabStore<T> {
} }
protected getStorableData(): DockTabStorageState<T> { protected getStorableData(): DockTabStorageState<T> {
const allTabsData = toJS(this.data, { recurseEverything: true }); const allTabsData = toJS(this.data);
return Object.fromEntries( return Object.fromEntries(
Object.entries(allTabsData).map(([tabId, tabData]) => { Object.entries(allTabsData).map(([tabId, tabData]) => {

View File

@ -349,7 +349,7 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
@action @action
protected updateFromEventsBuffer() { protected updateFromEventsBuffer() {
const items = this.items.toJS(); const items = this.items.toJSON();
for (const { type, object } of this.eventsBuffer.clear()) { for (const { type, object } of this.eventsBuffer.clear()) {
const index = items.findIndex(item => item.getId() === object.metadata?.uid); const index = items.findIndex(item => item.getId() === object.metadata?.uid);

View File

@ -1,9 +1,8 @@
// Helper for working with storages (e.g. window.localStorage, NodeJS/file-system, etc.) // Helper for working with storages (e.g. window.localStorage, NodeJS/file-system, etc.)
import type { CreateObservableOptions } from "mobx"; import { action, comparer, CreateObservableOptions, IObservableValue, observable, reaction, toJS, when } from "mobx";
import { action, comparer, observable, toJS, when } from "mobx";
import produce, { Draft, enableMapSet, setAutoFreeze } from "immer"; import produce, { Draft, enableMapSet, setAutoFreeze } from "immer";
import { isEqual, isFunction, isPlainObject } from "lodash"; import { isEqual, isFunction, isPlainObject, merge } from "lodash";
import logger from "../../main/logger"; import logger from "../../main/logger";
setAutoFreeze(false); // allow to merge observables setAutoFreeze(false); // allow to merge observables
@ -33,7 +32,7 @@ export class StorageHelper<T> {
} }
}; };
@observable private data = observable.box<T>(); private data: IObservableValue<T>;
@observable initialized = false; @observable initialized = false;
whenReady = when(() => this.initialized); whenReady = when(() => this.initialized);
@ -46,9 +45,8 @@ export class StorageHelper<T> {
} }
constructor(readonly key: string, private options: StorageHelperOptions<T>) { constructor(readonly key: string, private options: StorageHelperOptions<T>) {
this.options = { ...StorageHelper.defaultOptions, ...options }; this.options = merge({}, StorageHelper.defaultOptions, options);
this.configureObservable(); this.observeData();
this.reset();
if (this.options.autoInit) { if (this.options.autoInit) {
this.init(); this.init();
@ -99,17 +97,17 @@ export class StorageHelper<T> {
return isEqual(value, this.defaultValue); return isEqual(value, this.defaultValue);
} }
@action private observeData(value = this.options.defaultValue) {
private configureObservable(options = this.options.observable) { const observableOptions: CreateObservableOptions = {
this.data = observable.box<T>(this.data.get(), {
...StorageHelper.defaultOptions.observable, // inherit default observability options ...StorageHelper.defaultOptions.observable, // inherit default observability options
...(options ?? {}), ...this.options.observable,
}); };
this.data.observe(change => {
const { newValue, oldValue } = toJS(change, { recurseEverything: true });
this.data = observable.box<T>(value, observableOptions);
return reaction(() => toJS(this.data.get()), (newValue, oldValue) => {
this.onChange(newValue, oldValue); this.onChange(newValue, oldValue);
}); }, observableOptions);
} }
protected onChange(value: T, oldValue?: T) { protected onChange(value: T, oldValue?: T) {
@ -158,6 +156,6 @@ export class StorageHelper<T> {
} }
toJS() { toJS() {
return toJS(this.get(), { recurseEverything: true }); return toJS(this.get());
} }
} }

View File

@ -9495,17 +9495,17 @@ mobx-observable-history@^1.0.3:
history "^4.10.1" history "^4.10.1"
mobx "^5.15.4" mobx "^5.15.4"
mobx-react-lite@>=2.2.0: mobx-react-lite@^2.2.0:
version "2.2.2" version "2.2.2"
resolved "https://registry.yarnpkg.com/mobx-react-lite/-/mobx-react-lite-2.2.2.tgz#87c217dc72b4e47b22493daf155daf3759f868a6" resolved "https://registry.yarnpkg.com/mobx-react-lite/-/mobx-react-lite-2.2.2.tgz#87c217dc72b4e47b22493daf155daf3759f868a6"
integrity sha512-2SlXALHIkyUPDsV4VTKVR9DW7K3Ksh1aaIv3NrNJygTbhXe2A9GrcKHZ2ovIiOp/BXilOcTYemfHHZubP431dg== integrity sha512-2SlXALHIkyUPDsV4VTKVR9DW7K3Ksh1aaIv3NrNJygTbhXe2A9GrcKHZ2ovIiOp/BXilOcTYemfHHZubP431dg==
mobx-react@^6.2.2: mobx-react@^6.2.2:
version "6.3.0" version "6.3.1"
resolved "https://registry.yarnpkg.com/mobx-react/-/mobx-react-6.3.0.tgz#7d11799f988bbdadc49e725081993b18baa20329" resolved "https://registry.yarnpkg.com/mobx-react/-/mobx-react-6.3.1.tgz#204f9756e42e19d91cb6598837063b7e7de87c52"
integrity sha512-C14yya2nqEBRSEiJjPkhoWJLlV8pcCX3m2JRV7w1KivwANJqipoiPx9UMH4pm6QNMbqDdvJqoyl+LqNu9AhvEQ== integrity sha512-IOxdJGnRSNSJrL2uGpWO5w9JH5q5HoxEqwOF4gye1gmZYdjoYkkMzSGMDnRCUpN/BNzZcFoMdHXrjvkwO7KgaQ==
dependencies: dependencies:
mobx-react-lite ">=2.2.0" mobx-react-lite "^2.2.0"
mobx@^5.15.4: mobx@^5.15.4:
version "5.15.4" version "5.15.4"