diff --git a/src/renderer/components/+config-maps/config-map-details.tsx b/src/renderer/components/+config-maps/config-map-details.tsx index 1b7c88eed4..36c479ad99 100644 --- a/src/renderer/components/+config-maps/config-map-details.tsx +++ b/src/renderer/components/+config-maps/config-map-details.tsx @@ -9,24 +9,36 @@ import React from "react"; import { autorun, makeObservable, observable } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; import { DrawerTitle } from "../drawer"; -import { Notifications } from "../notifications"; +import type { ShowNotification } from "../notifications"; import { Input } from "../input"; import { Button } from "../button"; -import { configMapStore } from "./legacy-store"; import type { KubeObjectDetailsProps } from "../kube-object-details"; import { ConfigMap } from "../../../common/k8s-api/endpoints"; import { KubeObjectMeta } from "../kube-object-meta"; -import logger from "../../../common/logger"; +import type { Logger } from "../../../common/logger"; +import type { ConfigMapStore } from "./store"; +import { withInjectables } from "@ogre-tools/injectable-react"; +import configMapStoreInjectable from "./store.injectable"; +import showSuccessNotificationInjectable from "../notifications/show-success-notification.injectable"; +import showErrorNotificationInjectable from "../notifications/show-error-notification.injectable"; +import loggerInjectable from "../../../common/logger.injectable"; export interface ConfigMapDetailsProps extends KubeObjectDetailsProps { } +interface Dependencies { + configMapStore: ConfigMapStore; + logger: Logger; + showSuccessNotification: ShowNotification; + showErrorNotification: ShowNotification; +} + @observer -export class ConfigMapDetails extends React.Component { +class NonInjectedConfigMapDetails extends React.Component { @observable isSaving = false; @observable data = observable.map(); - constructor(props: ConfigMapDetailsProps) { + constructor(props: ConfigMapDetailsProps & Dependencies) { super(props); makeObservable(this); } @@ -44,7 +56,7 @@ export class ConfigMapDetails extends React.Component { } save = async () => { - const { object: configMap } = this.props; + const { object: configMap, configMapStore } = this.props; try { this.isSaving = true; @@ -52,7 +64,7 @@ export class ConfigMapDetails extends React.Component { ...configMap, data: Object.fromEntries(this.data), }); - Notifications.ok(( + this.props.showSuccessNotification((

{"ConfigMap "} {configMap.getName()} @@ -60,14 +72,14 @@ export class ConfigMapDetails extends React.Component {

)); } catch (error) { - Notifications.error(`Failed to save config map: ${error}`); + this.props.showErrorNotification(`Failed to save config map: ${error}`); } finally { this.isSaving = false; } }; render() { - const { object: configMap } = this.props; + const { object: configMap, logger } = this.props; if (!configMap) { return null; @@ -118,3 +130,13 @@ export class ConfigMapDetails extends React.Component { ); } } + +export const ConfigMapDetails = withInjectables(NonInjectedConfigMapDetails, { + getProps: (di, props) => ({ + ...props, + configMapStore: di.inject(configMapStoreInjectable), + showSuccessNotification: di.inject(showSuccessNotificationInjectable), + showErrorNotification: di.inject(showErrorNotificationInjectable), + logger: di.inject(loggerInjectable), + }), +}); diff --git a/src/renderer/components/+config-maps/legacy-store.ts b/src/renderer/components/+config-maps/legacy-store.ts deleted file mode 100644 index d655de6d1c..0000000000 --- a/src/renderer/components/+config-maps/legacy-store.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - -import { asLegacyGlobalForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api"; -import configMapStoreInjectable from "./store.injectable"; - -/** - * @deprecated use `di.inject(configMapStoreInjectable)` instead - */ -export const configMapStore = asLegacyGlobalForExtensionApi(configMapStoreInjectable);