mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make base store non Singleton (#6690)
* Remove Singleton from BaseStore to remove global shared state Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove more usages of Singleton Signed-off-by: Sebastian Malton <sebastian@malton.name> * Replace use of legacy global execHelm with injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove last use of legacy global execHelm Signed-off-by: Sebastian Malton <sebastian@malton.name> * Extract BaseStore deps into constructor argument Signed-off-by: Sebastian Malton <sebastian@malton.name> * Introduce method to make store migrations injectable - Use it for ClusterStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Switch HotbarStore to injectable migrations Signed-off-by: Sebastian Malton <sebastian@malton.name> * Switch UserStore to injectable migrations Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move migration utils into common/utils/ Signed-off-by: Sebastian Malton <sebastian@malton.name> * Switch WeblinkStore to injectable migrations Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove dead code Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type error in base-store tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove tests that reference lastSeenVersion - That value is not used anywhere in code Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usage of legacy global .getInstance Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usage of legacy global ClusterStore.getInstance Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add simple migrations dependency for stores without any preexisting migrations Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix messed up import Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add typing to transient injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Cleanup formatting Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix typing in tests to satisfy requirement to have cacheFile Signed-off-by: Sebastian Malton <sebastian@malton.name> * More consistent use of BaseStore.displayName Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add catching of error while starting main application Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move initializing sentry to runnable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unneeded appPathsInjectionToken - Only had once impl, which was in common anyway Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add support for multiple "runAfter" runnables - Needed so that several dependencies can be declared Signed-off-by: Sebastian Malton <sebastian@malton.name> * Use multiple runAfter support to fix crash on renderer Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove traces Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add global override to fix tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix base store tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix runManyFor tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix hotbar store tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix user store tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add global override for getConfigurationFileModel to fix tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove overrides for configuration stores - Now that there is an override for getConfiguration Signed-off-by: Sebastian Malton <sebastian@malton.name> * Overhaul FS fakes with full in-memory filesystem - This increases our confidence in fs related logic Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of global shared Electron.App Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add fake access support Signed-off-by: Sebastian Malton <sebastian@malton.name> * Handle copy as part of fake FS Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add ensureDir/Sync support to fake FS Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type error Signed-off-by: Sebastian Malton <sebastian@malton.name> * Use pathExistsSync instead of fsInjectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add createReadStream to fake FS Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add stat to fake FS Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove dead code Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix test failures due to incomplete overrides Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fully injectable-ize BaseStore so that ApplicationBuilder tests work Signed-off-by: Sebastian Malton <sebastian@malton.name> * Consolidate more bootstrapping into startFrame Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move initializing CatalogCategories to runnable in bootstrap Signed-off-by: Sebastian Malton <sebastian@malton.name> * Convert contextMenuOpen initializers into runnables Signed-off-by: Sebastian Malton <sebastian@malton.name> * Convert navigateForExtension init to runnable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make cluster state sync fully injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move init hotbar store into runnables Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make LensTheme fully injectable and runnable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Cleanup old code from missed from previous commit Signed-off-by: Sebastian Malton <sebastian@malton.name> * Manually split out terminal color names and fully type LensTheme Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix old imports Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unnecessart awaits Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove dead code Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fully cherry pick injectablizing custom monaco themes Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix duplicate mock warning Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix incorrectly fully cherry picking new runnable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Complete cherry-pick of current cluster injcetablization Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix override file name Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix injecting before app paths are set up Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix injecting before app paths are set up Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix ordering of runnable and order of injection Signed-off-by: Sebastian Malton <sebastian@malton.name> * Convert all renderer runnables to late-inject style - To help fix issues around injection time Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix react-beautiful-dnd mocks Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update and fix WriteJson(Sync) to fix error in tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix HotbarStore.load being called twice is being buggy Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update listing-active-helm-repositories-in-preferences snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix sidebar-and-tab-navigation-tests - Move enabling extensions in tests to a proper location - Fix flushing promises Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove props from dnd mock to make snapshot diffs smaller Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix import Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests by overriding things that are no longer overriden by default - NOTE: They are overridden when using ApplicationBuilder Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix hotbar store tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix cluster store tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix extension-loader tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix extension-discovery tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix cluster-role-dialog tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix user store tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix kubeconfig sync tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix sidebar and tab tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unused code Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix pick paths import type error and simplify signature Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type error in legacy ipc registration Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove another use of legacy requestOpenPathPicker Signed-off-by: Sebastian Malton <sebastian@malton.name> * Replace use of legacy global PathPicker.Pick Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix usage in light of changed prop names Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix catalog tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix more type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix test flakiness by removing side effects from userStore preferences Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix loading Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type error Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix crash Signed-off-by: Sebastian Malton <sebastian@malton.name> * Cherry pick updated startFrameInjectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add tests to verify runMany behaviour in new possible incorrect configuration Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix init ordering during start frame Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix cluster state sync Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshots after removing side-effects Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add override for technical test Signed-off-by: Sebastian Malton <sebastian@malton.name> * Correctly mark currentlyInClusterFrame as causedSideEffects Signed-off-by: Sebastian Malton <sebastian@malton.name> * Better formatting Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix behaviour regression Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add better logging Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix BaseStore sync Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update last snapshot Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add global override for randomBytes Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make startMainApplication not an injection time side effect Signed-off-by: Sebastian Malton <sebastian@malton.name> * Choose better names for start-frame runnable tokens Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove duplication of code in RunManyFor Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add unit tests and fix handling empty runAfter array Signed-off-by: Sebastian Malton <sebastian@malton.name> * Replace use of mobx from runManyFor with custom barrier Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add missing test Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
7c5faaaf1d
commit
25f37ac1d1
364 files changed
+10035
-5246
No files matched your search
+90
-10
@@ -476,7 +476,23 @@ exports[`Deleting a cluster when an internal kubeconfig cluster is used when the
|
||||
<div
|
||||
class="HotbarCell isDraggingOwner animateDown"
|
||||
index="0"
|
||||
/>
|
||||
>
|
||||
<div
|
||||
style="z-index: 12; position: absolute;"
|
||||
>
|
||||
<div
|
||||
class="HotbarIcon contextMenuAvailable"
|
||||
>
|
||||
<div
|
||||
class="Avatar rounded disabled avatar"
|
||||
id="hotbarIcon-hotbar-icon-catalog-entity"
|
||||
style="width: 40px; height: 40px; background: rgb(5, 1, 130);"
|
||||
>
|
||||
Ca
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="HotbarCell isDraggingOwner animateDown"
|
||||
index="1"
|
||||
@@ -543,7 +559,7 @@ exports[`Deleting a cluster when an internal kubeconfig cluster is used when the
|
||||
class="badge Badge small clickable"
|
||||
id="hotbarIndex"
|
||||
>
|
||||
0
|
||||
1
|
||||
</div>
|
||||
</div>
|
||||
<i
|
||||
@@ -1112,7 +1128,23 @@ exports[`Deleting a cluster when the kubeconfig has multiple clusters when the d
|
||||
<div
|
||||
class="HotbarCell isDraggingOwner animateDown"
|
||||
index="0"
|
||||
/>
|
||||
>
|
||||
<div
|
||||
style="z-index: 12; position: absolute;"
|
||||
>
|
||||
<div
|
||||
class="HotbarIcon contextMenuAvailable"
|
||||
>
|
||||
<div
|
||||
class="Avatar rounded disabled avatar"
|
||||
id="hotbarIcon-hotbar-icon-catalog-entity"
|
||||
style="width: 40px; height: 40px; background: rgb(5, 1, 130);"
|
||||
>
|
||||
Ca
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="HotbarCell isDraggingOwner animateDown"
|
||||
index="1"
|
||||
@@ -1179,7 +1211,7 @@ exports[`Deleting a cluster when the kubeconfig has multiple clusters when the d
|
||||
class="badge Badge small clickable"
|
||||
id="hotbarIndex"
|
||||
>
|
||||
0
|
||||
1
|
||||
</div>
|
||||
</div>
|
||||
<i
|
||||
@@ -1781,7 +1813,23 @@ exports[`Deleting a cluster when the kubeconfig has multiple clusters when the d
|
||||
<div
|
||||
class="HotbarCell isDraggingOwner animateDown"
|
||||
index="0"
|
||||
/>
|
||||
>
|
||||
<div
|
||||
style="z-index: 12; position: absolute;"
|
||||
>
|
||||
<div
|
||||
class="HotbarIcon contextMenuAvailable"
|
||||
>
|
||||
<div
|
||||
class="Avatar rounded disabled avatar"
|
||||
id="hotbarIcon-hotbar-icon-catalog-entity"
|
||||
style="width: 40px; height: 40px; background: rgb(5, 1, 130);"
|
||||
>
|
||||
Ca
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="HotbarCell isDraggingOwner animateDown"
|
||||
index="1"
|
||||
@@ -1848,7 +1896,7 @@ exports[`Deleting a cluster when the kubeconfig has multiple clusters when the d
|
||||
class="badge Badge small clickable"
|
||||
id="hotbarIndex"
|
||||
>
|
||||
0
|
||||
1
|
||||
</div>
|
||||
</div>
|
||||
<i
|
||||
@@ -2529,7 +2577,23 @@ exports[`Deleting a cluster when the kubeconfig has multiple clusters when the d
|
||||
<div
|
||||
class="HotbarCell isDraggingOwner animateDown"
|
||||
index="0"
|
||||
/>
|
||||
>
|
||||
<div
|
||||
style="z-index: 12; position: absolute;"
|
||||
>
|
||||
<div
|
||||
class="HotbarIcon contextMenuAvailable"
|
||||
>
|
||||
<div
|
||||
class="Avatar rounded disabled avatar"
|
||||
id="hotbarIcon-hotbar-icon-catalog-entity"
|
||||
style="width: 40px; height: 40px; background: rgb(5, 1, 130);"
|
||||
>
|
||||
Ca
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="HotbarCell isDraggingOwner animateDown"
|
||||
index="1"
|
||||
@@ -2596,7 +2660,7 @@ exports[`Deleting a cluster when the kubeconfig has multiple clusters when the d
|
||||
class="badge Badge small clickable"
|
||||
id="hotbarIndex"
|
||||
>
|
||||
0
|
||||
1
|
||||
</div>
|
||||
</div>
|
||||
<i
|
||||
@@ -3277,7 +3341,23 @@ exports[`Deleting a cluster when the kubeconfig has only one cluster when the di
|
||||
<div
|
||||
class="HotbarCell isDraggingOwner animateDown"
|
||||
index="0"
|
||||
/>
|
||||
>
|
||||
<div
|
||||
style="z-index: 12; position: absolute;"
|
||||
>
|
||||
<div
|
||||
class="HotbarIcon contextMenuAvailable"
|
||||
>
|
||||
<div
|
||||
class="Avatar rounded disabled avatar"
|
||||
id="hotbarIcon-hotbar-icon-catalog-entity"
|
||||
style="width: 40px; height: 40px; background: rgb(5, 1, 130);"
|
||||
>
|
||||
Ca
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="HotbarCell isDraggingOwner animateDown"
|
||||
index="1"
|
||||
@@ -3344,7 +3424,7 @@ exports[`Deleting a cluster when the kubeconfig has only one cluster when the di
|
||||
class="badge Badge small clickable"
|
||||
id="hotbarIndex"
|
||||
>
|
||||
0
|
||||
1
|
||||
</div>
|
||||
</div>
|
||||
<i
|
||||
|
||||
@@ -6,7 +6,7 @@ import emitAppEventInjectable from "../../../../common/app-event-bus/emit-event.
|
||||
import clusterFramesInjectable from "../../../../common/cluster-frames.injectable";
|
||||
import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable";
|
||||
import directoryForLensLocalStorageInjectable from "../../../../common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable";
|
||||
import deleteFileInjectable from "../../../../common/fs/delete-file.injectable";
|
||||
import removePathInjectable from "../../../../common/fs/remove.injectable";
|
||||
import joinPathsInjectable from "../../../../common/path/join-paths.injectable";
|
||||
import { noop } from "../../../../common/utils";
|
||||
import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens";
|
||||
@@ -20,7 +20,7 @@ const deleteClusterChannelListenerInjectable = getRequestChannelListenerInjectab
|
||||
const clusterFrames = di.inject(clusterFramesInjectable);
|
||||
const joinPaths = di.inject(joinPathsInjectable);
|
||||
const directoryForLensLocalStorage = di.inject(directoryForLensLocalStorageInjectable);
|
||||
const deleteFile = di.inject(deleteFileInjectable);
|
||||
const deleteFile = di.inject(removePathInjectable);
|
||||
|
||||
return async (clusterId) => {
|
||||
emitAppEvent({ name: "cluster", action: "remove" });
|
||||
|
||||
@@ -24,6 +24,7 @@ import { navigateToRouteInjectionToken } from "../../common/front-end-routing/na
|
||||
import sidebarStorageInjectable from "../../renderer/components/layout/sidebar-storage/sidebar-storage.injectable";
|
||||
import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time";
|
||||
import storageSaveDelayInjectable from "../../renderer/utils/create-storage/storage-save-delay.injectable";
|
||||
import { flushPromises } from "../../common/test-utils/flush-promises";
|
||||
|
||||
describe("cluster - sidebar and tab navigation for core", () => {
|
||||
let builder: ApplicationBuilder;
|
||||
@@ -283,6 +284,8 @@ describe("cluster - sidebar and tab navigation for core", () => {
|
||||
|
||||
const readJsonFileFake = windowDi.inject(readJsonFileInjectable);
|
||||
|
||||
await flushPromises();
|
||||
|
||||
const actual = await readJsonFileFake(
|
||||
"/some-directory-for-lens-local-storage/some-cluster-id.json",
|
||||
);
|
||||
|
||||
@@ -20,6 +20,7 @@ import type { IObservableValue } from "mobx";
|
||||
import { runInAction, computed, observable } from "mobx";
|
||||
import storageSaveDelayInjectable from "../../renderer/utils/create-storage/storage-save-delay.injectable";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import { flushPromises } from "../../common/test-utils/flush-promises";
|
||||
|
||||
describe("cluster - sidebar and tab navigation for extensions", () => {
|
||||
let applicationBuilder: ApplicationBuilder;
|
||||
@@ -399,6 +400,8 @@ describe("cluster - sidebar and tab navigation for extensions", () => {
|
||||
|
||||
const readJsonFileFake = windowDi.inject(readJsonFileInjectable);
|
||||
|
||||
await flushPromises(); // Needed because of several async calls
|
||||
|
||||
const actual = await readJsonFileFake(
|
||||
"/some-directory-for-lens-local-storage/some-cluster-id.json",
|
||||
);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { ClusterId, ClusterState } from "../../../../common/cluster-types";
|
||||
import type { MessageChannel } from "../../../../common/utils/channel/message-channel-listener-injection-token";
|
||||
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||
|
||||
export interface ClusterStateSync {
|
||||
clusterId: ClusterId;
|
||||
state: ClusterState;
|
||||
}
|
||||
|
||||
export const clusterStateSyncChannel: MessageChannel<ClusterStateSync> = {
|
||||
id: "cluster-state-sync",
|
||||
};
|
||||
|
||||
export const initialClusterStatesChannel: RequestChannel<void, ClusterStateSync[]> = {
|
||||
id: "initial-cluster-state-sync",
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { MessageChannelHandler } from "../../../../common/utils/channel/message-channel-listener-injection-token";
|
||||
import { sendMessageToChannelInjectionToken } from "../../../../common/utils/channel/message-to-channel-injection-token";
|
||||
import { clusterStateSyncChannel } from "../common/channels";
|
||||
|
||||
export type EmitClusterStateUpdate = MessageChannelHandler<typeof clusterStateSyncChannel>;
|
||||
|
||||
const emitClusterStateUpdateInjectable = getInjectable({
|
||||
id: "emit-cluster-state-update",
|
||||
instantiate: (di): EmitClusterStateUpdate => {
|
||||
const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken);
|
||||
|
||||
return (message) => sendMessageToChannel(clusterStateSyncChannel, message);
|
||||
},
|
||||
});
|
||||
|
||||
export default emitClusterStateUpdateInjectable;
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable";
|
||||
import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens";
|
||||
import { initialClusterStatesChannel } from "../common/channels";
|
||||
|
||||
const handleInitialClusterStateSyncInjectable = getRequestChannelListenerInjectable({
|
||||
channel: initialClusterStatesChannel,
|
||||
handler: (di) => {
|
||||
const clusterStore = di.inject(clusterStoreInjectable);
|
||||
|
||||
return () => clusterStore.clustersList.map(cluster => ({
|
||||
clusterId: cluster.id,
|
||||
state: cluster.getState(),
|
||||
}));
|
||||
},
|
||||
});
|
||||
|
||||
export default handleInitialClusterStateSyncInjectable;
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { isEqual } from "lodash";
|
||||
import { autorun } from "mobx";
|
||||
import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable";
|
||||
import type { ClusterId, ClusterState } from "../../../../common/cluster-types";
|
||||
import { beforeApplicationIsLoadingInjectionToken } from "../../../../main/start-main-application/runnable-tokens/before-application-is-loading-injection-token";
|
||||
import initClusterStoreInjectable from "../../store/main/init.injectable";
|
||||
import emitClusterStateUpdateInjectable from "./emit-update.injectable";
|
||||
|
||||
const setupClusterStateBroadcastingInjectable = getInjectable({
|
||||
id: "setup-cluster-state-broadcasting",
|
||||
instantiate: (di) => ({
|
||||
id: "setup-cluster-state-broadcasting",
|
||||
run: () => {
|
||||
const emitClusterStateUpdate = di.inject(emitClusterStateUpdateInjectable);
|
||||
const clusterStore = di.inject(clusterStoreInjectable);
|
||||
const prevStates = new Map<ClusterId, ClusterState>();
|
||||
|
||||
autorun(() => {
|
||||
for (const cluster of clusterStore.clusters.values()) {
|
||||
const prevState = prevStates.get(cluster.id);
|
||||
const curState = cluster.getState();
|
||||
|
||||
if (!prevState || !isEqual(prevState, curState)) {
|
||||
prevStates.set(cluster.id, curState);
|
||||
|
||||
emitClusterStateUpdate({
|
||||
clusterId: cluster.id,
|
||||
state: cluster.getState(),
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
runAfter: di.inject(initClusterStoreInjectable),
|
||||
}),
|
||||
injectionToken: beforeApplicationIsLoadingInjectionToken,
|
||||
});
|
||||
|
||||
export default setupClusterStateBroadcastingInjectable;
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable";
|
||||
import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token";
|
||||
import { clusterStateSyncChannel } from "../common/channels";
|
||||
|
||||
const clusterStateListenerInjectable = getMessageChannelListenerInjectable({
|
||||
channel: clusterStateSyncChannel,
|
||||
id: "main",
|
||||
handler: (di) => {
|
||||
const getClusterById = di.inject(getClusterByIdInjectable);
|
||||
|
||||
return ({ clusterId, state }) => getClusterById(clusterId)?.setState(state);
|
||||
},
|
||||
});
|
||||
|
||||
export default clusterStateListenerInjectable;
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { RequestChannelHandler } from "../../../../main/utils/channel/channel-listeners/listener-tokens";
|
||||
import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable";
|
||||
import { initialClusterStatesChannel } from "../common/channels";
|
||||
|
||||
export type RequestInitialClusterStates = RequestChannelHandler<typeof initialClusterStatesChannel>;
|
||||
|
||||
const requestInitialClusterStatesInjectable = getInjectable({
|
||||
id: "request-initial-cluster-states",
|
||||
instantiate: (di): RequestInitialClusterStates => {
|
||||
const requestFromChannel = di.inject(requestFromChannelInjectable);
|
||||
|
||||
return () => requestFromChannel(initialClusterStatesChannel);
|
||||
},
|
||||
});
|
||||
|
||||
export default requestInitialClusterStatesInjectable;
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable";
|
||||
import { beforeFrameStartsInjectionToken } from "../../../../renderer/before-frame-starts/tokens";
|
||||
import initClusterStoreInjectable from "../../store/renderer/init.injectable";
|
||||
import requestInitialClusterStatesInjectable from "./request-initial.injectable";
|
||||
|
||||
const setupClusterStateSyncInjectable = getInjectable({
|
||||
id: "setup-cluster-state-sync",
|
||||
instantiate: (di) => ({
|
||||
id: "setup-cluster-state-sync",
|
||||
run: async () => {
|
||||
const requestInitialClusterStates = di.inject(requestInitialClusterStatesInjectable);
|
||||
const getClusterById = di.inject(getClusterByIdInjectable);
|
||||
const initalStates = await requestInitialClusterStates();
|
||||
|
||||
for (const { clusterId, state } of initalStates) {
|
||||
getClusterById(clusterId)?.setState(state);
|
||||
}
|
||||
},
|
||||
runAfter: di.inject(initClusterStoreInjectable),
|
||||
}),
|
||||
injectionToken: beforeFrameStartsInjectionToken,
|
||||
});
|
||||
|
||||
export default setupClusterStateSyncInjectable;
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable";
|
||||
import { beforeApplicationIsLoadingInjectionToken } from "../../../../main/start-main-application/runnable-tokens/before-application-is-loading-injection-token";
|
||||
import initUserStoreInjectable from "../../../../main/stores/init-user-store.injectable";
|
||||
|
||||
const initClusterStoreInjectable = getInjectable({
|
||||
id: "init-cluster-store",
|
||||
instantiate: (di) => {
|
||||
const clusterStore = di.inject(clusterStoreInjectable);
|
||||
|
||||
return {
|
||||
id: "init-cluster-store",
|
||||
run: () => {
|
||||
clusterStore.load();
|
||||
},
|
||||
runAfter: di.inject(initUserStoreInjectable),
|
||||
};
|
||||
},
|
||||
injectionToken: beforeApplicationIsLoadingInjectionToken,
|
||||
});
|
||||
|
||||
export default initClusterStoreInjectable;
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable";
|
||||
import { beforeFrameStartsInjectionToken } from "../../../../renderer/before-frame-starts/tokens";
|
||||
import initUserStoreInjectable from "../../../../renderer/stores/init-user-store.injectable";
|
||||
|
||||
const initClusterStoreInjectable = getInjectable({
|
||||
id: "init-cluster-store",
|
||||
instantiate: (di) => ({
|
||||
id: "init-cluster-store",
|
||||
run: () => {
|
||||
const clusterStore = di.inject(clusterStoreInjectable);
|
||||
|
||||
clusterStore.load();
|
||||
},
|
||||
runAfter: di.inject(initUserStoreInjectable),
|
||||
}),
|
||||
injectionToken: beforeFrameStartsInjectionToken,
|
||||
});
|
||||
|
||||
export default initClusterStoreInjectable;
|
||||
Reference in new issue
Block a user