Fix model name and set parameter watcher only for react component (#33399)

This commit is contained in:
Maryia Lapata 2019-03-18 16:21:45 +03:00 committed by GitHub
parent 76eff0afab
commit 364325b1be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View file

@ -76,11 +76,13 @@ uiModules
return true;
};
$scope.$watch('agg.params[aggParam.name]', (value) => {
// Whenever the value of the parameter changed (e.g. by a reset or actually by calling)
// we store the new value in $scope.paramValue, which will be passed as a new value to the react component.
$scope.paramValue = value;
}, true);
if (attr.editorComponent) {
$scope.$watch('agg.params[aggParam.name]', (value) => {
// Whenever the value of the parameter changed (e.g. by a reset or actually by calling)
// we store the new value in $scope.paramValue, which will be passed as a new value to the react component.
$scope.paramValue = value;
}, true);
}
$scope.onChange = (value) => {
// This is obviously not a good code quality, but without using scope binding (which we can't see above)

View file

@ -209,7 +209,7 @@ uiModules
// The form should interact with reactified components as well.
// So we set the ng-model (using a random ng-model variable) to have the method to set dirty
// inside the agg_param.js directive, which can get access to the ngModelController to manipulate it.
attrs['ng-model'] = `_internalNgModelState${$scope.agg.id}${param.name}`;
attrs['ng-model'] = normalizeModelName(`_internalNgModelState${$scope.agg.id}${param.name}`);
}
return $('<vis-agg-param-editor>')
@ -217,6 +217,10 @@ uiModules
.append(param.editor)
.get(0);
}
function normalizeModelName(modelName = '') {
return modelName.replace('-', '_');
}
}
};
});