Skip to content
This repository has been archived by the owner on May 17, 2022. It is now read-only.

Commit

Permalink
Fix for parameter mapping bug getredash#3581 (getredash#3582)
Browse files Browse the repository at this point in the history
* Fix for parameter mapping bug getredash#3581

* Must run original snapshot with original dashboard params
  • Loading branch information
ranbena authored and arikfr committed Mar 13, 2019
1 parent f1cb010 commit adf935b
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions client/app/components/dashboards/EditParameterMappingsDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ 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(
sortBy(mappings, m => m.name),
(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
Expand All @@ -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,
};
}

Expand All @@ -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 = [
Expand Down

0 comments on commit adf935b

Please sign in to comment.