Update variable and function names to reduce the amount of comment explanation
parent
a8a9ab9870
commit
d87054df74
|
@ -195,7 +195,7 @@ export const getDashboardsAsync = () => async dispatch => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const dashboardWithOnlySelectedTemplateValues = dashboard => {
|
const removeUnselectedTemplateValues = dashboard => {
|
||||||
const templates = dashboard.templates.map(template => {
|
const templates = dashboard.templates.map(template => {
|
||||||
const values =
|
const values =
|
||||||
template.type === 'csv'
|
template.type === 'csv'
|
||||||
|
@ -208,13 +208,23 @@ const dashboardWithOnlySelectedTemplateValues = dashboard => {
|
||||||
|
|
||||||
export const putDashboard = dashboard => async dispatch => {
|
export const putDashboard = dashboard => async dispatch => {
|
||||||
try {
|
try {
|
||||||
// for server, template var values should be all values for csv
|
// save only selected template values to server
|
||||||
// and should be only the selected value for non csv types
|
const templatesWithOnlySelectedValues = removeUnselectedTemplateValues(
|
||||||
const templates = dashboardWithOnlySelectedTemplateValues(dashboard)
|
dashboard
|
||||||
const {data} = await updateDashboardAJAX({...dashboard, templates})
|
)
|
||||||
// updateDashboardAJAX removed the values for the template variables
|
const {
|
||||||
// when saving to the server
|
data: dashboardWithOnlySelectedTemplateValues,
|
||||||
dispatch(updateDashboard({...data, templates: dashboard.templates}))
|
} = await updateDashboardAJAX({
|
||||||
|
...dashboard,
|
||||||
|
templates: templatesWithOnlySelectedValues,
|
||||||
|
})
|
||||||
|
// save all template values to redux
|
||||||
|
dispatch(
|
||||||
|
updateDashboard({
|
||||||
|
...dashboardWithOnlySelectedTemplateValues,
|
||||||
|
templates: dashboard.templates,
|
||||||
|
})
|
||||||
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
dispatch(errorThrown(error))
|
dispatch(errorThrown(error))
|
||||||
|
@ -225,7 +235,7 @@ export const putDashboardByID = dashboardID => async (dispatch, getState) => {
|
||||||
try {
|
try {
|
||||||
const {dashboardUI: {dashboards}} = getState()
|
const {dashboardUI: {dashboards}} = getState()
|
||||||
const dashboard = dashboards.find(d => d.id === +dashboardID)
|
const dashboard = dashboards.find(d => d.id === +dashboardID)
|
||||||
const templates = dashboardWithOnlySelectedTemplateValues(dashboard)
|
const templates = removeUnselectedTemplateValues(dashboard)
|
||||||
await updateDashboardAJAX({...dashboard, templates})
|
await updateDashboardAJAX({...dashboard, templates})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
|
Loading…
Reference in New Issue