Skip to content

Commit

Permalink
Avoid SELECT action when requesting the deployed version (#1302)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Martinez Gotor authored Nov 21, 2019
1 parent 11658d8 commit e61258a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 32 deletions.
5 changes: 0 additions & 5 deletions dashboard/src/actions/charts.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 } },
Expand Down
51 changes: 24 additions & 27 deletions dashboard/src/actions/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Promise<any | void>, IStoreState, null, ChartsAction> {
): ThunkAction<Promise<void>, 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;
};
}

Expand All @@ -148,10 +141,14 @@ export function getDeployedChartVersion(
version: string,
): ThunkAction<Promise<void>, 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);
}
};
}
Expand Down

0 comments on commit e61258a

Please sign in to comment.