mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove last usage of legacy global
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
ff46d4fc64
commit
1243dd5e6e
@ -9,24 +9,36 @@ import React from "react";
|
|||||||
import { autorun, makeObservable, observable } from "mobx";
|
import { autorun, makeObservable, observable } 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 type { ShowNotification } from "../notifications";
|
||||||
import { Input } from "../input";
|
import { Input } from "../input";
|
||||||
import { Button } from "../button";
|
import { Button } from "../button";
|
||||||
import { configMapStore } from "./legacy-store";
|
|
||||||
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
||||||
import { ConfigMap } from "../../../common/k8s-api/endpoints";
|
import { ConfigMap } from "../../../common/k8s-api/endpoints";
|
||||||
import { KubeObjectMeta } from "../kube-object-meta";
|
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<ConfigMap> {
|
export interface ConfigMapDetailsProps extends KubeObjectDetailsProps<ConfigMap> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Dependencies {
|
||||||
|
configMapStore: ConfigMapStore;
|
||||||
|
logger: Logger;
|
||||||
|
showSuccessNotification: ShowNotification;
|
||||||
|
showErrorNotification: ShowNotification;
|
||||||
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class ConfigMapDetails extends React.Component<ConfigMapDetailsProps> {
|
class NonInjectedConfigMapDetails extends React.Component<ConfigMapDetailsProps & Dependencies> {
|
||||||
@observable isSaving = false;
|
@observable isSaving = false;
|
||||||
@observable data = observable.map<string, string | undefined>();
|
@observable data = observable.map<string, string | undefined>();
|
||||||
|
|
||||||
constructor(props: ConfigMapDetailsProps) {
|
constructor(props: ConfigMapDetailsProps & Dependencies) {
|
||||||
super(props);
|
super(props);
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
}
|
}
|
||||||
@ -44,7 +56,7 @@ export class ConfigMapDetails extends React.Component<ConfigMapDetailsProps> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
save = async () => {
|
save = async () => {
|
||||||
const { object: configMap } = this.props;
|
const { object: configMap, configMapStore } = this.props;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.isSaving = true;
|
this.isSaving = true;
|
||||||
@ -52,7 +64,7 @@ export class ConfigMapDetails extends React.Component<ConfigMapDetailsProps> {
|
|||||||
...configMap,
|
...configMap,
|
||||||
data: Object.fromEntries(this.data),
|
data: Object.fromEntries(this.data),
|
||||||
});
|
});
|
||||||
Notifications.ok((
|
this.props.showSuccessNotification((
|
||||||
<p>
|
<p>
|
||||||
{"ConfigMap "}
|
{"ConfigMap "}
|
||||||
<b>{configMap.getName()}</b>
|
<b>{configMap.getName()}</b>
|
||||||
@ -60,14 +72,14 @@ export class ConfigMapDetails extends React.Component<ConfigMapDetailsProps> {
|
|||||||
</p>
|
</p>
|
||||||
));
|
));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Notifications.error(`Failed to save config map: ${error}`);
|
this.props.showErrorNotification(`Failed to save config map: ${error}`);
|
||||||
} finally {
|
} finally {
|
||||||
this.isSaving = false;
|
this.isSaving = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { object: configMap } = this.props;
|
const { object: configMap, logger } = this.props;
|
||||||
|
|
||||||
if (!configMap) {
|
if (!configMap) {
|
||||||
return null;
|
return null;
|
||||||
@ -118,3 +130,13 @@ export class ConfigMapDetails extends React.Component<ConfigMapDetailsProps> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const ConfigMapDetails = withInjectables<Dependencies, ConfigMapDetailsProps>(NonInjectedConfigMapDetails, {
|
||||||
|
getProps: (di, props) => ({
|
||||||
|
...props,
|
||||||
|
configMapStore: di.inject(configMapStoreInjectable),
|
||||||
|
showSuccessNotification: di.inject(showSuccessNotificationInjectable),
|
||||||
|
showErrorNotification: di.inject(showErrorNotificationInjectable),
|
||||||
|
logger: di.inject(loggerInjectable),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|||||||
@ -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);
|
|
||||||
Loading…
Reference in New Issue
Block a user