You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/11/12 12:07:51 UTC

[GitHub] [superset] kgabryje commented on a change in pull request #17422: chore: Notify user of custom label colors and related Dashboard color scheme

kgabryje commented on a change in pull request #17422:
URL: https://github.com/apache/superset/pull/17422#discussion_r748223348



##########
File path: superset-frontend/src/explore/components/controls/ColorSchemeControl/index.jsx
##########
@@ -101,43 +115,93 @@ export default class ColorSchemeControl extends React.PureComponent {
             </li>
           ))}
         </ul>
-      </Tooltip>
+      </span>
     );
   }
 
+  renderLabel() {
+    const { dashboardId, hasCustomLabelColors, label } = this.props;
+
+    if (hasCustomLabelColors || dashboardId) {
+      const alertTitle = hasCustomLabelColors
+        ? t(
+            `This color scheme is being overriden by custom label colors.
+              Check the JSON metadata in the Advanced settings`,
+          )
+        : this.dashboardColorSchemeAlert;
+      return (
+        <>
+          {label}{' '}
+          <Tooltip title={alertTitle}>
+            <StyledAlert iconSize="s" />
+          </Tooltip>
+        </>
+      );
+    }
+    return label;
+  }
+
   render() {
-    const { schemes, choices } = this.props;
-    // save parsed schemes for later
-    this.schemes = isFunction(schemes) ? schemes() : schemes;
+    const { choices, dashboardId, schemes } = this.props;
+    let options = dashboardId
+      ? [
+          {
+            value: 'dashboard',
+            label: 'dashboard',
+            customLabel: (
+              <Tooltip title={this.dashboardColorSchemeAlert}>
+                {t('Dashboard scheme')}
+              </Tooltip>
+            ),
+          },
+        ]
+      : [];
+    let currentScheme = dashboardId ? 'dashboard' : undefined;
 
-    const allColorOptions = (isFunction(choices) ? choices() : choices).filter(
-      o => o[0] !== 'SUPERSET_DEFAULT',
-    );
-    const options = allColorOptions.map(([value]) => ({
-      value,
-      label: this.schemes?.[value]?.label || value,
-      customLabel: this.renderOption(value),
-    }));
-
-    let currentScheme =
-      this.props.value ||
-      (this.props.default !== undefined ? this.props.default : undefined);
-
-    if (currentScheme === 'SUPERSET_DEFAULT') {
-      currentScheme = this.schemes?.SUPERSET_DEFAULT?.id;
+    // if related to a dashboard the scheme is dictated by the dashboard
+    if (!dashboardId) {
+      this.schemes = isFunction(schemes) ? schemes() : schemes;
+      const controlChoices = isFunction(choices) ? choices() : choices;
+      const allColorOptions = [];
+      const filteredColorOptions = controlChoices.filter(o => {
+        const option = o[0];
+        const isValidColorOption =
+          option !== 'SUPERSET_DEFAULT' && !allColorOptions.includes(option);
+        allColorOptions.push(option);
+        return isValidColorOption;
+      });
+
+      options = filteredColorOptions.map(([value]) => ({
+        customLabel: this.renderOption(value),
+        label: this.schemes?.[value]?.label || value,
+        value,
+      }));
+
+      currentScheme =
+        this.props.value ||
+        (this.props.default !== undefined ? this.props.default : undefined);

Review comment:
       Can we simplify that to `this.props.value || this.props.default`?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org