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

Remove last usage of legacy global secretsStore

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-11-30 08:31:07 -05:00
parent 4ff4b5e7af
commit 1d431666f3
3 changed files with 60 additions and 33 deletions

View File

@ -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 secretStoreInjectable from "./store.injectable";
/**
* @deprecated use `di.inject(secretStoreInjectable)` instead
*/
export const secretStore = asLegacyGlobalForExtensionApi(secretStoreInjectable);

View File

@ -11,25 +11,38 @@ import { disposeOnUnmount, observer } from "mobx-react";
import { DrawerItem, DrawerTitle } from "../drawer";
import { Input } from "../input";
import { Button } from "../button";
import { Notifications } from "../notifications";
import type { ShowNotification } from "../notifications";
import { base64, toggle } from "../../utils";
import { Icon } from "../icon";
import { secretStore } from "./legacy-store";
import type { KubeObjectDetailsProps } from "../kube-object-details";
import { Secret } from "../../../common/k8s-api/endpoints";
import { KubeObjectMeta } from "../kube-object-meta";
import logger from "../../../common/logger";
import type { Logger } from "../../../common/logger";
import type { SecretStore } from "./store";
import { withInjectables } from "@ogre-tools/injectable-react";
import loggerInjectable from "../../../common/logger.injectable";
import secretStoreInjectable from "./store.injectable";
import showSuccessNotificationInjectable from "../notifications/show-success-notification.injectable";
import type { ShowCheckedErrorNotification } from "../notifications/show-checked-error.injectable";
import showCheckedErrorNotificationInjectable from "../notifications/show-checked-error.injectable";
export interface SecretDetailsProps extends KubeObjectDetailsProps<Secret> {
}
interface Dependencies {
secretStore: SecretStore;
logger: Logger;
showSuccessNotification: ShowNotification;
showCheckedErrorNotification: ShowCheckedErrorNotification;
}
@observer
export class SecretDetails extends React.Component<SecretDetailsProps> {
class NonInjectedSecretDetails extends React.Component<SecretDetailsProps & Dependencies> {
@observable isSaving = false;
@observable data: Partial<Record<string, string>> = {};
@observable revealSecret = observable.set<string>();
constructor(props: SecretDetailsProps) {
constructor(props: SecretDetailsProps & Dependencies) {
super(props);
makeObservable(this);
}
@ -53,10 +66,10 @@ export class SecretDetails extends React.Component<SecretDetailsProps> {
this.isSaving = true;
try {
await secretStore.update(secret, { ...secret, data: this.data });
Notifications.ok("Secret successfully updated.");
await this.props.secretStore.update(secret, { ...secret, data: this.data });
this.props.showSuccessNotification("Secret successfully updated.");
} catch (err) {
Notifications.checkedError(err, "Unknown error occured while updating the secret");
this.props.showCheckedErrorNotification(err, "Unknown error occured while updating the secret");
}
this.isSaving = false;
};
@ -134,7 +147,7 @@ export class SecretDetails extends React.Component<SecretDetailsProps> {
}
render() {
const { object: secret } = this.props;
const { object: secret, logger } = this.props;
if (!secret) {
return null;
@ -157,3 +170,13 @@ export class SecretDetails extends React.Component<SecretDetailsProps> {
);
}
}
export const SecretDetails = withInjectables<Dependencies, SecretDetailsProps>(NonInjectedSecretDetails, {
getProps: (di, props) => ({
...props,
logger: di.inject(loggerInjectable),
secretStore: di.inject(secretStoreInjectable),
showCheckedErrorNotification: di.inject(showCheckedErrorNotificationInjectable),
showSuccessNotification: di.inject(showSuccessNotificationInjectable),
}),
});

View File

@ -10,7 +10,6 @@ import { disposeOnUnmount, observer } from "mobx-react";
import React from "react";
import { Link } from "react-router-dom";
import { secretStore } from "../../+config-secrets/legacy-store";
import type { Secret, ServiceAccount } from "../../../../common/k8s-api/endpoints";
import { DrawerItem, DrawerTitle } from "../../drawer";
import { Icon } from "../../icon";
@ -18,23 +17,32 @@ import type { KubeObjectDetailsProps } from "../../kube-object-details";
import { KubeObjectMeta } from "../../kube-object-meta";
import { Spinner } from "../../spinner";
import { ServiceAccountsSecret } from "./secret";
import { getDetailsUrl } from "../../kube-detail-params";
import type { SecretStore } from "../../+config-secrets/store";
import type { GetDetailsUrl } from "../../kube-detail-params/get-details-url.injectable";
import { withInjectables } from "@ogre-tools/injectable-react";
import getDetailsUrlInjectable from "../../kube-detail-params/get-details-url.injectable";
import secretStoreInjectable from "../../+config-secrets/store.injectable";
export interface ServiceAccountsDetailsProps extends KubeObjectDetailsProps<ServiceAccount> {
}
const defensiveLoadSecretIn = (namespace: string) => (
({ name }: { name: string }) => (
secretStore.load({ name, namespace })
.catch(() => name)
)
);
interface Dependencies {
secretStore: SecretStore;
getDetailsUrl: GetDetailsUrl;
}
@observer
export class ServiceAccountsDetails extends React.Component<ServiceAccountsDetailsProps> {
class NonInjectedServiceAccountsDetails extends React.Component<ServiceAccountsDetailsProps & Dependencies> {
readonly secrets = observable.array<Secret | string>();
readonly imagePullSecrets = observable.array<Secret | string>();
private defensiveLoadSecretIn = (namespace: string) => (
({ name }: { name: string }) => (
this.props.secretStore.load({ name, namespace })
.catch(() => name)
)
);
componentDidMount(): void {
disposeOnUnmount(this, [
autorun(async () => {
@ -50,7 +58,7 @@ export class ServiceAccountsDetails extends React.Component<ServiceAccountsDetai
return;
}
const defensiveLoadSecret = defensiveLoadSecretIn(namespace);
const defensiveLoadSecret = this.defensiveLoadSecretIn(namespace);
const secretLoaders = Promise.all(serviceAccount.getSecrets().map(defensiveLoadSecret));
const imagePullSecretLoaders = Promise.all(serviceAccount.getImagePullSecrets().map(defensiveLoadSecret));
@ -108,7 +116,7 @@ export class ServiceAccountsDetails extends React.Component<ServiceAccountsDetai
}
return (
<Link key={secret.getId()} to={getDetailsUrl(secret.selfLink)}>
<Link key={secret.getId()} to={this.props.getDetailsUrl(secret.selfLink)}>
{secret.getName()}
</Link>
);
@ -116,7 +124,7 @@ export class ServiceAccountsDetails extends React.Component<ServiceAccountsDetai
}
render() {
const { object: serviceAccount } = this.props;
const { object: serviceAccount, secretStore } = this.props;
if (!serviceAccount) {
return null;
@ -150,3 +158,11 @@ export class ServiceAccountsDetails extends React.Component<ServiceAccountsDetai
);
}
}
export const ServiceAccountsDetails = withInjectables<Dependencies, ServiceAccountsDetailsProps>(NonInjectedServiceAccountsDetails, {
getProps: (di, props) => ({
...props,
getDetailsUrl: di.inject(getDetailsUrlInjectable),
secretStore: di.inject(secretStoreInjectable),
}),
});