From 46765e9ed06a9310d9ddeec389466909bfc9f709 Mon Sep 17 00:00:00 2001 From: Iris Scholten Date: Wed, 21 Feb 2018 10:03:44 -0800 Subject: [PATCH] Update variable and function names to reduce the amount of comment explanation --- ui/src/dashboards/actions/index.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/ui/src/dashboards/actions/index.js b/ui/src/dashboards/actions/index.js index 1419d50b1..8400d638b 100644 --- a/ui/src/dashboards/actions/index.js +++ b/ui/src/dashboards/actions/index.js @@ -195,7 +195,7 @@ export const getDashboardsAsync = () => async dispatch => { } } -const dashboardWithOnlySelectedTemplateValues = dashboard => { +const removeUnselectedTemplateValues = dashboard => { const templates = dashboard.templates.map(template => { const values = template.type === 'csv' @@ -208,13 +208,23 @@ const dashboardWithOnlySelectedTemplateValues = dashboard => { export const putDashboard = dashboard => async dispatch => { try { - // for server, template var values should be all values for csv - // and should be only the selected value for non csv types - const templates = dashboardWithOnlySelectedTemplateValues(dashboard) - const {data} = await updateDashboardAJAX({...dashboard, templates}) - // updateDashboardAJAX removed the values for the template variables - // when saving to the server - dispatch(updateDashboard({...data, templates: dashboard.templates})) + // save only selected template values to server + const templatesWithOnlySelectedValues = removeUnselectedTemplateValues( + dashboard + ) + const { + data: dashboardWithOnlySelectedTemplateValues, + } = await updateDashboardAJAX({ + ...dashboard, + templates: templatesWithOnlySelectedValues, + }) + // save all template values to redux + dispatch( + updateDashboard({ + ...dashboardWithOnlySelectedTemplateValues, + templates: dashboard.templates, + }) + ) } catch (error) { console.error(error) dispatch(errorThrown(error)) @@ -225,7 +235,7 @@ export const putDashboardByID = dashboardID => async (dispatch, getState) => { try { const {dashboardUI: {dashboards}} = getState() const dashboard = dashboards.find(d => d.id === +dashboardID) - const templates = dashboardWithOnlySelectedTemplateValues(dashboard) + const templates = removeUnselectedTemplateValues(dashboard) await updateDashboardAJAX({...dashboard, templates}) } catch (error) { console.error(error)