geido commented on a change in pull request #17422:
URL: https://github.com/apache/superset/pull/17422#discussion_r748250047
##########
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:
`default` could also be `null` and `null` it's an acceptable value for
the Select. That's the reason of the strict check here
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]