Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: widget oblivious to updated parameter values #3445

Merged
merged 6 commits into from
Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions client/app/components/dashboards/EditParameterMappingsDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import Modal from 'antd/lib/modal';
import { wrap as wrapDialog, DialogPropType } from '@/components/DialogWrapper';
import {
MappingType,
ParameterMappingListInput,
parameterMappingsToEditableMappings,
editableMappingsToParameterMappings,
Expand All @@ -17,18 +18,32 @@ class EditParameterMappingsDialog extends React.Component {
dialog: DialogPropType.isRequired,
};

originalParamValuesSig = 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.originalParamValuesSig = this.constructor.getParamValuesSignature(parameterMappings);

this.state = {
saveInProgress: false,
parameterMappings: parameterMappingsToEditableMappings(
props.widget.options.parameterMappings,
props.widget.query.getParametersDefs(),
map(this.props.dashboard.getParametersDefs(), p => p.name),
),
parameterMappings,
};
}

static getParamValuesSignature(mappings) {
const s = JSON.stringify;
return mappings
.map(m => (m.type === MappingType.StaticValue ? s(m.value) : s(m.param.value)))
.join();
}

saveWidget() {
const toastr = this.props.toastr; // eslint-disable-line react/prop-types
const widget = this.props.widget;
Expand All @@ -44,7 +59,9 @@ class EditParameterMappingsDialog extends React.Component {

Promise.all(map(widgetsToSave, w => w.save()))
.then(() => {
this.props.dialog.close();
const paramValuesSig = this.constructor.getParamValuesSignature(this.state.parameterMappings);
ranbena marked this conversation as resolved.
Show resolved Hide resolved
const valuesChanged = this.originalParamValuesSig !== paramValuesSig;
this.props.dialog.close(valuesChanged);
})
.catch(() => {
toastr.error('Widget cannot be updated');
Expand Down
7 changes: 6 additions & 1 deletion client/app/components/dashboards/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@ function DashboardWidgetCtrl($scope, $location, $uibModal, $window, $rootScope,
EditParameterMappingsDialog.showModal({
dashboard: this.dashboard,
widget: this.widget,
}).result.then(() => {
}).result.then((valuesChanged) => {
this.localParameters = null;

// refresh widget if any parameter value has been updated
if (valuesChanged) {
setTimeout(() => this.refresh(), 0); // must tick for refresh to work
ranbena marked this conversation as resolved.
Show resolved Hide resolved
}
$scope.$applyAsync();
$rootScope.$broadcast('dashboard.update-parameters');
});
Expand Down