mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix app crash opening Install Chart dock tab (#6782)
* Change type of RequestHelmChartValues to be AsyncResult Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Fixing tests Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Linter fix Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
8b752981a0
commit
e0bccfabd4
@ -3,12 +3,13 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import type { AsyncResult } from "../../../utils/async-result";
|
||||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||||
import apiBaseInjectable from "../../api-base.injectable";
|
import apiBaseInjectable from "../../api-base.injectable";
|
||||||
|
|
||||||
const requestValuesEndpoint = urlBuilderFor("/v2/charts/:repo/:name/values");
|
const requestValuesEndpoint = urlBuilderFor("/v2/charts/:repo/:name/values");
|
||||||
|
|
||||||
export type RequestHelmChartValues = (repo: string, name: string, version: string) => Promise<string>;
|
export type RequestHelmChartValues = (repo: string, name: string, version: string) => Promise<AsyncResult<string>>;
|
||||||
|
|
||||||
const requestHelmChartValuesInjectable = getInjectable({
|
const requestHelmChartValuesInjectable = getInjectable({
|
||||||
id: "request-helm-chart-values",
|
id: "request-helm-chart-values",
|
||||||
|
|||||||
@ -240,9 +240,10 @@ describe("installing helm chart from new tab", () => {
|
|||||||
|
|
||||||
describe("when default configuration and versions resolve", () => {
|
describe("when default configuration and versions resolve", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await requestHelmChartValuesMock.resolve(
|
await requestHelmChartValuesMock.resolve({
|
||||||
"some-default-configuration",
|
callWasSuccessful: true,
|
||||||
);
|
response: "some-default-configuration",
|
||||||
|
});
|
||||||
|
|
||||||
await requestHelmChartVersionsMock.resolve([
|
await requestHelmChartVersionsMock.resolve([
|
||||||
HelmChart.create({
|
HelmChart.create({
|
||||||
@ -537,9 +538,10 @@ describe("installing helm chart from new tab", () => {
|
|||||||
|
|
||||||
describe("when configuration and versions resolve", () => {
|
describe("when configuration and versions resolve", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await requestHelmChartValuesMock.resolve(
|
await requestHelmChartValuesMock.resolve({
|
||||||
"some-other-default-configuration",
|
callWasSuccessful: true,
|
||||||
);
|
response: "some-other-default-configuration",
|
||||||
|
});
|
||||||
|
|
||||||
await requestHelmChartVersionsMock.resolve([]);
|
await requestHelmChartVersionsMock.resolve([]);
|
||||||
});
|
});
|
||||||
@ -702,9 +704,10 @@ describe("installing helm chart from new tab", () => {
|
|||||||
|
|
||||||
describe("when default configuration resolves", () => {
|
describe("when default configuration resolves", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await requestHelmChartValuesMock.resolve(
|
await requestHelmChartValuesMock.resolve({
|
||||||
"some-default-configuration-for-other-version",
|
callWasSuccessful: true,
|
||||||
);
|
response: "some-default-configuration-for-other-version",
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders", () => {
|
it("renders", () => {
|
||||||
@ -847,9 +850,10 @@ describe("installing helm chart from new tab", () => {
|
|||||||
)
|
)
|
||||||
.selectOption("some-other-version");
|
.selectOption("some-other-version");
|
||||||
|
|
||||||
await requestHelmChartValuesMock.resolve(
|
await requestHelmChartValuesMock.resolve({
|
||||||
"some-default-configuration-for-other-version",
|
callWasSuccessful: true,
|
||||||
);
|
response: "some-default-configuration-for-other-version",
|
||||||
|
});
|
||||||
|
|
||||||
expect(installButton).not.toHaveAttribute("disabled");
|
expect(installButton).not.toHaveAttribute("disabled");
|
||||||
});
|
});
|
||||||
@ -920,9 +924,10 @@ describe("installing helm chart from new tab", () => {
|
|||||||
)
|
)
|
||||||
.selectOption("some-other-version");
|
.selectOption("some-other-version");
|
||||||
|
|
||||||
await requestHelmChartValuesMock.resolve(
|
await requestHelmChartValuesMock.resolve({
|
||||||
"some-default-configuration-for-other-version",
|
callWasSuccessful: true,
|
||||||
);
|
response: "some-default-configuration-for-other-version",
|
||||||
|
});
|
||||||
|
|
||||||
const input = rendered.getByTestId(
|
const input = rendered.getByTestId(
|
||||||
"monaco-editor-for-some-first-tab-id",
|
"monaco-editor-for-some-first-tab-id",
|
||||||
|
|||||||
@ -149,9 +149,10 @@ describe("installing helm chart from previously opened tab", () => {
|
|||||||
|
|
||||||
describe("when configuration and version resolves", () => {
|
describe("when configuration and version resolves", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await requestHelmChartValuesMock.resolve(
|
await requestHelmChartValuesMock.resolve({
|
||||||
"some-default-configuration",
|
callWasSuccessful: true,
|
||||||
);
|
response: "some-default-configuration",
|
||||||
|
});
|
||||||
|
|
||||||
await requestHelmChartVersionsMock.resolve([
|
await requestHelmChartVersionsMock.resolve([
|
||||||
HelmChart.create({
|
HelmChart.create({
|
||||||
|
|||||||
@ -122,14 +122,18 @@ export class InstallChartModel {
|
|||||||
this.configuration.isLoading.set(true);
|
this.configuration.isLoading.set(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
const configuration = await this.dependencies.requestHelmChartValues(
|
const chartValuesRequest = await this.dependencies.requestHelmChartValues(
|
||||||
this.chart.repo,
|
this.chart.repo,
|
||||||
this.chart.name,
|
this.chart.name,
|
||||||
version,
|
version,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!chartValuesRequest.callWasSuccessful) {
|
||||||
|
throw chartValuesRequest.error;
|
||||||
|
}
|
||||||
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.configuration.onChange(configuration);
|
this.configuration.onChange(chartValuesRequest.response);
|
||||||
this.configuration.isLoading.set(false);
|
this.configuration.isLoading.set(false);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -187,7 +191,7 @@ export class InstallChartModel {
|
|||||||
load = async () => {
|
load = async () => {
|
||||||
await this.dependencies.waitForChart();
|
await this.dependencies.waitForChart();
|
||||||
|
|
||||||
const [defaultConfiguration, versions] = await Promise.all([
|
const [defaultConfigurationRequest, versions] = await Promise.all([
|
||||||
this.dependencies.requestHelmChartValues(
|
this.dependencies.requestHelmChartValues(
|
||||||
this.chart.repo,
|
this.chart.repo,
|
||||||
this.chart.name,
|
this.chart.name,
|
||||||
@ -203,13 +207,14 @@ export class InstallChartModel {
|
|||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
// TODO: Make "default" not hard-coded
|
// TODO: Make "default" not hard-coded
|
||||||
const namespace = this.chart.namespace || "default";
|
const namespace = this.chart.namespace || "default";
|
||||||
|
const values = this.chart.values || (defaultConfigurationRequest.callWasSuccessful ? defaultConfigurationRequest.response : "");
|
||||||
|
|
||||||
this.versions.replace(versions);
|
this.versions.replace(versions);
|
||||||
|
|
||||||
this.save({
|
this.save({
|
||||||
version: this.chart.version,
|
version: this.chart.version,
|
||||||
namespace,
|
namespace,
|
||||||
values: this.chart.values || defaultConfiguration,
|
values,
|
||||||
releaseName: this.chart.releaseName,
|
releaseName: this.chart.releaseName,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user