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

Choose remove method in namespace store again

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2023-03-03 17:03:53 +03:00
parent a279e09bb6
commit e4b6541727
3 changed files with 32 additions and 1 deletions

View File

@ -0,0 +1,23 @@
/**
* 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 removeSubnamespaceInjectable from "./remove-subnamespace.injectable";
// A wrapper injectable to avoid circular dependency loop caused by injection of
// removeSubnamespaceInjectable into namespace store.
const deleteSubnamespaceInjectable = getInjectable({
id: "delete-subnamespace",
instantiate: (di) => {
const removeSubnamespace = di.inject(removeSubnamespaceInjectable);
return async (namespace: string) => (
removeSubnamespace(namespace)
)
}
});
export default deleteSubnamespaceInjectable;

View File

@ -12,6 +12,7 @@ import storesAndApisCanBeCreatedInjectable from "../../stores-apis-can-be-create
import clusterFrameContextForClusterScopedResourcesInjectable from "../../cluster-frame-context/for-cluster-scoped-resources.injectable"; import clusterFrameContextForClusterScopedResourcesInjectable from "../../cluster-frame-context/for-cluster-scoped-resources.injectable";
import clusterConfiguredAccessibleNamespacesInjectable from "../../cluster/accessible-namespaces.injectable"; import clusterConfiguredAccessibleNamespacesInjectable from "../../cluster/accessible-namespaces.injectable";
import loggerInjectable from "../../../common/logger.injectable"; import loggerInjectable from "../../../common/logger.injectable";
import deleteSubnamespaceInjectable from "./delete-subnamespace.injectable";
const namespaceStoreInjectable = getInjectable({ const namespaceStoreInjectable = getInjectable({
id: "namespace-store", id: "namespace-store",
@ -27,6 +28,7 @@ const namespaceStoreInjectable = getInjectable({
storage: createStorage<string[] | undefined>("selected_namespaces", undefined), storage: createStorage<string[] | undefined>("selected_namespaces", undefined),
clusterConfiguredAccessibleNamespaces: di.inject(clusterConfiguredAccessibleNamespacesInjectable), clusterConfiguredAccessibleNamespaces: di.inject(clusterConfiguredAccessibleNamespacesInjectable),
logger: di.inject(loggerInjectable), logger: di.inject(loggerInjectable),
deleteSubnamespace: di.inject(deleteSubnamespaceInjectable)
}, api); }, api);
}, },
injectionToken: kubeObjectStoreInjectionToken, injectionToken: kubeObjectStoreInjectionToken,

View File

@ -21,6 +21,7 @@ export interface NamespaceTree {
interface Dependencies extends KubeObjectStoreDependencies { interface Dependencies extends KubeObjectStoreDependencies {
readonly storage: StorageLayer<string[] | undefined>; readonly storage: StorageLayer<string[] | undefined>;
readonly clusterConfiguredAccessibleNamespaces: IComputedValue<string[]>; readonly clusterConfiguredAccessibleNamespaces: IComputedValue<string[]>;
deleteSubnamespace: (name: string) => Promise<void>
} }
export class NamespaceStore extends KubeObjectStore<Namespace, NamespaceApi> { export class NamespaceStore extends KubeObjectStore<Namespace, NamespaceApi> {
@ -220,7 +221,12 @@ export class NamespaceStore extends KubeObjectStore<Namespace, NamespaceApi> {
@action @action
async remove(item: Namespace) { async remove(item: Namespace) {
if (item.isSubnamespace()) {
this.dependencies.deleteSubnamespace(item.getName())
} else {
await super.remove(item); await super.remove(item);
}
this.clearSelected(item.getName()); this.clearSelected(item.getName());
} }
} }