GabeLoins commented on a change in pull request #4663: [Request For 
Comments][Explore] Streamlined metric definitions for SQLA and Druid
URL: 
https://github.com/apache/incubator-superset/pull/4663#discussion_r176636322
 
 

 ##########
 File path: superset/assets/javascripts/explore/AdhocMetric.js
 ##########
 @@ -0,0 +1,37 @@
+export default class AdhocMetric {
+  constructor(adhocMetric) {
+    this.column = adhocMetric.column;
+    this.aggregate = adhocMetric.aggregate;
+    this.hasCustomLabel = !!(adhocMetric.hasCustomLabel && adhocMetric.label);
+
+    if (this.hasCustomLabel) {
+      this.label = adhocMetric.label;
+    } else {
+      this.label = this.getDefaultLabel();
+    }
+
+    this.optionName = adhocMetric.optionName ||
+      `metric_${Math.random().toString(36).substring(2, 
15)}_${Math.random().toString(36).substring(2, 15)}`;
+  }
+
+  getDefaultLabel() {
+    return `${this.aggregate || ''}(${(this.column && this.column.column_name) 
|| ''})`;
 
 Review comment:
   It wouldn't be often, but in the case that someone clears the aggregate 
input in the edit popover, and then goes to edit the title, the default title 
they would see without this logic would be like `null(column_name)`, which 
seems like a bad user experience. Adding this logic would make the default 
title appear as `(column_name)`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to