Skip to content

Commit 12be601

Browse files
committed
[#26] Update how we activate and switch to a cluster
Fixes #26
1 parent be689f1 commit 12be601

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

src/cc/store/ClusterActionsProvider.js

+7-18
Original file line numberDiff line numberDiff line change
@@ -432,23 +432,12 @@ const _switchToNewWorkspace = function () {
432432
};
433433

434434
/**
435-
* Switch to the specified cluster.
436-
* @param {string} clusterId ID of the cluster in Lens.
437-
* @param {string} [workspaceId] Optional ID of the workspace that contains the
438-
* cluster. If specified, this workspace will be activated before the cluster
439-
* is activated.
435+
* [ASYNC] Switch to the specified cluster (and associated workspace).
436+
* @param {string} clusterId ID of the cluster in Lens. Can be in any workspace,
437+
* even if it's not the active one.
440438
*/
441-
const _switchToCluster = function (clusterId, workspaceId) {
442-
if (workspaceId) {
443-
Store.workspaceStore.setActive(workspaceId);
444-
}
445-
446-
Store.clusterStore.activeClusterId = clusterId;
447-
// TODO: doesn't __always__ work; bug in Lens somewhere, and feels like clusterStore
448-
// should have setActive(clusterId) like workspaceStore.setActive() and have it do
449-
// the navigation in a consistent way.
450-
// TRACKING: https://github.com/Mirantis/lens-extension-cc/issues/26
451-
extension.navigate(`/cluster/${clusterId}`);
439+
const _switchToCluster = async function (clusterId) {
440+
await Store.workspaceStore.setActiveCluster(clusterId);
452441
};
453442

454443
/**
@@ -796,6 +785,7 @@ const _addKubeCluster = async function ({
796785
_switchToNewWorkspace();
797786
}
798787

788+
// NOTE: this is async but we don't need to wait on it
799789
_switchToCluster(clusterId);
800790
}
801791
}
@@ -820,6 +810,7 @@ const _activateCluster = function ({ namespace, clusterName, clusterId }) {
820810
const lensCluster = _getLensCluster(clusterId);
821811

822812
if (lensCluster) {
813+
// NOTE: this is async but we don't need to wait on it
823814
_switchToCluster(clusterId, lensCluster.workspace);
824815
} else {
825816
pr.error = strings.clusterActionsProvider.error.clusterNotFound(
@@ -1003,10 +994,8 @@ export const useClusterActions = function () {
1003994
};
1004995

1005996
export const ClusterActionsProvider = function ({
1006-
extension: lensExtension,
1007997
...props
1008998
}) {
1009-
extension = lensExtension;
1010999

10111000
// NOTE: since the state is passed directly (by reference) into the context
10121001
// returned by the provider, even the initial state should be a clone of the

0 commit comments

Comments
 (0)