From e61258a53037054cf8c729423352b0e7ee85c042 Mon Sep 17 00:00:00 2001 From: Andres Martinez Gotor Date: Thu, 21 Nov 2019 10:58:12 +0100 Subject: [PATCH] Avoid SELECT action when requesting the deployed version (#1302) --- dashboard/src/actions/charts.test.tsx | 5 --- dashboard/src/actions/charts.ts | 51 +++++++++++++-------------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/dashboard/src/actions/charts.test.tsx b/dashboard/src/actions/charts.test.tsx index d1fa07fbdb6..a3cf8d60aa1 100644 --- a/dashboard/src/actions/charts.test.tsx +++ b/dashboard/src/actions/charts.test.tsx @@ -242,11 +242,6 @@ describe("getDeployedChartVersion", () => { response = { id: "foo" }; const expectedActions = [ { type: getType(actions.charts.requestDeployedChartVersion) }, - { type: getType(actions.charts.requestCharts) }, - { - type: getType(actions.charts.selectChartVersion), - payload: { chartVersion: response, schema: { data: response }, values: { data: response } }, - }, { type: getType(actions.charts.receiveDeployedChartVersion), payload: { chartVersion: response, schema: { data: response }, values: { data: response } }, diff --git a/dashboard/src/actions/charts.ts b/dashboard/src/actions/charts.ts index 96b1399a536..8fb9e1241fa 100644 --- a/dashboard/src/actions/charts.ts +++ b/dashboard/src/actions/charts.ts @@ -102,44 +102,37 @@ export function fetchChartVersions( }; } -function handleError(e: Error, dispatch: Dispatch): boolean { - if (e.constructor === NotFoundError) { - // Item not found, it's not mandatory so skip it - return true; - } else { - // Unexpecter error - dispatch(errorChart(e)); - return false; +async function getChart(id: string, version: string) { + let values = ""; + let schema = {}; + const chartVersion = await Chart.getChartVersion(id, version); + if (chartVersion) { + try { + values = await Chart.getValues(id, version); + schema = await Chart.getSchema(id, version); + } catch (e) { + if (e.constructor !== NotFoundError) { + throw e; + } + } } + return { chartVersion, values, schema }; } export function getChartVersion( id: string, version: string, -): ThunkAction, IStoreState, null, ChartsAction> { +): ThunkAction, IStoreState, null, ChartsAction> { return async dispatch => { try { dispatch(requestCharts()); - const chartVersion = await Chart.getChartVersion(id, version); + const { chartVersion, values, schema } = await getChart(id, version); if (chartVersion) { - let values = ""; - let schema = {}; - try { - values = await Chart.getValues(id, version); - schema = await Chart.getSchema(id, version); - } catch (e) { - const valid = handleError(e, dispatch); - if (!valid) { - return; - } - } dispatch(selectChartVersion(chartVersion, values, schema)); - return { chartVersion, values, schema }; } } catch (e) { dispatchError(dispatch, e); } - return; }; } @@ -148,10 +141,14 @@ export function getDeployedChartVersion( version: string, ): ThunkAction, IStoreState, null, ChartsAction> { return async dispatch => { - dispatch(requestDeployedChartVersion()); - const { chartVersion, values, schema } = await dispatch(getChartVersion(id, version)); - if (chartVersion) { - dispatch(receiveDeployedChartVersion(chartVersion, values, schema)); + try { + dispatch(requestDeployedChartVersion()); + const { chartVersion, values, schema } = await getChart(id, version); + if (chartVersion) { + dispatch(receiveDeployedChartVersion(chartVersion, values, schema)); + } + } catch (e) { + dispatchError(dispatch, e); } }; }