From adf935b1dfec9543599a49beec7b3b625cdb9dc4 Mon Sep 17 00:00:00 2001 From: Ran Byron Date: Wed, 13 Mar 2019 16:41:03 +0200 Subject: [PATCH] Fix for parameter mapping bug #3581 (#3582) * Fix for parameter mapping bug #3581 * Must run original snapshot with original dashboard params --- .../EditParameterMappingsDialog.jsx | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/client/app/components/dashboards/EditParameterMappingsDialog.jsx b/client/app/components/dashboards/EditParameterMappingsDialog.jsx index 48b48eff11..b26d01baa3 100644 --- a/client/app/components/dashboards/EditParameterMappingsDialog.jsx +++ b/client/app/components/dashboards/EditParameterMappingsDialog.jsx @@ -4,12 +4,12 @@ import PropTypes from 'prop-types'; import Modal from 'antd/lib/modal'; import { wrap as wrapDialog, DialogPropType } from '@/components/DialogWrapper'; import { + MappingType, ParameterMappingListInput, parameterMappingsToEditableMappings, editableMappingsToParameterMappings, synchronizeWidgetTitles, } from '@/components/ParameterMappingInput'; -import { ParameterMappingType } from '@/services/widget'; export function getParamValuesSnapshot(mappings, dashboardParameters) { return map( @@ -17,11 +17,12 @@ export function getParamValuesSnapshot(mappings, dashboardParameters) { (m) => { let param; switch (m.type) { - case ParameterMappingType.StaticValue: + case MappingType.StaticValue: return [m.name, m.value]; - case ParameterMappingType.WidgetLevel: + case MappingType.WidgetLevel: return [m.name, m.param.value]; - case ParameterMappingType.DashboardLevel: + case MappingType.DashboardAddNew: + case MappingType.DashboardMapToExisting: param = find(dashboardParameters, p => p.name === m.mapTo); return [m.name, param ? param.value : null]; // no default @@ -37,16 +38,25 @@ class EditParameterMappingsDialog extends React.Component { dialog: DialogPropType.isRequired, }; + originalParamValuesSnapshot = null + constructor(props) { super(props); + const parameterMappings = parameterMappingsToEditableMappings( + props.widget.options.parameterMappings, + props.widget.query.getParametersDefs(), + map(this.props.dashboard.getParametersDefs(), p => p.name), + ); + + this.originalParamValuesSnapshot = getParamValuesSnapshot( + parameterMappings, + this.props.dashboard.getParametersDefs(), + ); + this.state = { saveInProgress: false, - parameterMappings: parameterMappingsToEditableMappings( - props.widget.options.parameterMappings, - props.widget.query.getParametersDefs(), - map(this.props.dashboard.getParametersDefs(), p => p.name), - ), + parameterMappings, }; } @@ -56,14 +66,12 @@ class EditParameterMappingsDialog extends React.Component { this.setState({ saveInProgress: true }); - const prevMappings = widget.options.parameterMappings; const newMappings = editableMappingsToParameterMappings(this.state.parameterMappings); widget.options.parameterMappings = newMappings; - const dashboardParameters = this.props.dashboard.getParametersDefs(); const valuesChanged = !isMatch( - getParamValuesSnapshot(prevMappings, dashboardParameters), - getParamValuesSnapshot(newMappings, dashboardParameters), + this.originalParamValuesSnapshot, + getParamValuesSnapshot(this.state.parameterMappings, this.props.dashboard.getParametersDefs()), ); const widgetsToSave = [