1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/components/+helm-releases/release-details/release-values.injectable.ts
Sebastian Malton 1cd9625faa Factor out uses of apiBase that cause test failures
Signed-off-by: Sebastian Malton <sebastian@malton.name>
2022-07-20 10:05:38 -04:00

40 lines
1.5 KiB
TypeScript

/**
* 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 { asyncComputed } from "@ogre-tools/injectable-react";
import releaseInjectable from "./release.injectable";
import userSuppliedValuesAreShownInjectable from "./user-supplied-values-are-shown.injectable";
import getHelmReleaseValuesInjectable from "../../../k8s/helm-releases.api/get-values.injectable";
import showErrorNotificationInjectable from "../../notifications/show-error-notification.injectable";
const releaseValuesInjectable = getInjectable({
id: "release-values",
instantiate: (di) => {
const getHelmReleaseValues = di.inject(getHelmReleaseValuesInjectable);
const showErrorNotification = di.inject(showErrorNotificationInjectable);
const userSuppliedValuesAreShown = di.inject(userSuppliedValuesAreShownInjectable);
return asyncComputed(async () => {
const release = di.inject(releaseInjectable).get();
// TODO: Figure out way to get rid of defensive code
if (!release) {
return "";
}
try {
return await getHelmReleaseValues(release.getName(), release.getNs(), !userSuppliedValuesAreShown.value) ?? "";
} catch (error) {
showErrorNotification(`Failed to load values for ${release.getName()}: ${error}`);
return "";
}
});
},
});
export default releaseValuesInjectable;