Skip to content

Commit

Permalink
give warning/error msg on inaccurate graph config
Browse files Browse the repository at this point in the history
getredash#57

I tried to make
`JSON.stringify(this.visualization.options.columnMapping)` a variable
to avoid repeating it, but if I make it a `let` the linter throws an
error and if I make it a `const` then it doesn’t change with the UI and
the logic doesn’t work. :(
  • Loading branch information
alison985 authored and Allen Short committed Dec 6, 2017
1 parent b50efbf commit 41d528c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion client/app/visualizations/edit-visualization-dialog.html
Expand Up @@ -33,10 +33,18 @@ <h4 class="modal-title">Visualization Editor</h4>
<div class="col-md-7" style="border: 1px solid #eee;">
<visualization-renderer visualization="$ctrl.visualization" query-result="$ctrl.queryResult"></visualization-renderer>
</div>
<div class="col-md-7">
<div class="bg-warning" ng-if="$ctrl.visualization.options.series.stacking == null && $ctrl.has3plusColumnsFunction()" style="padding:2%;" ng-bind-html="$ctrl.warning_three_column_stacking">
</div>
<div ng-repeat="value in $ctrl.visualization.options.columnMapping">
<div ng-if="value == 'unused' && $ctrl.has3plusColumnsFunction()" ng-bind-html="$ctrl.warning_three_column_groupby" class="bg-danger" style="padding:2%;"></div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="$ctrl.closeDialog()">Close</button>
<button type="button" class="btn btn-primary" ng-click="$ctrl.submit()">Save</button>
<button type="button" class="btn btn-primary" ng-click="$ctrl.submit()" ng-disabled="$ctrl.disableSubmit()">Save</button>
</div>
</div>
18 changes: 18 additions & 0 deletions client/app/visualizations/edit-visualization-dialog.js
Expand Up @@ -19,6 +19,9 @@ const EditVisualizationDialog = {
this.visualization = copy(this.originalVisualization);
this.visTypes = Visualization.visualizationTypes;

this.warning_three_column_groupby = '<b>You have more than 2 columns in your result set.</b> To ensure the chart is accurate, please do one of the following: <ul> <li>Change the SQL query to give 2 result columns. You can CONCAT() columns together if you wish.</li> <LI>Select column(s) to group by.</LI> </ul>';
this.warning_three_column_stacking = '<B>You have more than 2 columns in your result set.</b> You may wish to make the Stacking option equal to `Enabled` or `Percent`.';

this.newVisualization = () =>
({
type: Visualization.defaultVisualization.type,
Expand All @@ -45,6 +48,21 @@ const EditVisualizationDialog = {
}
};

this.has3plusColumnsFunction = () => {
let has3plusColumns = false;
if ((JSON.stringify(this.visualization.options.columnMapping).match(/,/g) || []).length > 1) {
has3plusColumns = true;
}
return has3plusColumns;
};

this.disableSubmit = () => {
if (this.has3plusColumnsFunction() && JSON.stringify(this.visualization.options.columnMapping).includes('unused')) {
return true;
}
return false;
};

this.submit = () => {
if (this.visualization.id) {
Events.record('update', 'visualization', this.visualization.id, { type: this.visualization.type });
Expand Down

0 comments on commit 41d528c

Please sign in to comment.