From 14b7f6cdbaad3a97aa24d234768a47752b700a11 Mon Sep 17 00:00:00 2001 From: Geido <60598000+geido@users.noreply.github.com> Date: Mon, 11 Oct 2021 16:16:06 +0300 Subject: [PATCH] fix: Exclude SUPERSET_DEFAULT from the list of available color schemes (#17018) * Handle SUPERSET_DEFAULT theme * Update superset-frontend/src/explore/components/controls/ColorSchemeControl.jsx Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com> * Update superset-frontend/src/explore/components/controls/ColorSchemeControl.jsx Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com> Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com> --- .../controls/ColorSchemeControl.jsx | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/superset-frontend/src/explore/components/controls/ColorSchemeControl.jsx b/superset-frontend/src/explore/components/controls/ColorSchemeControl.jsx index da363aa34f17..20be45db038b 100644 --- a/superset-frontend/src/explore/components/controls/ColorSchemeControl.jsx +++ b/superset-frontend/src/explore/components/controls/ColorSchemeControl.jsx @@ -110,23 +110,31 @@ export default class ColorSchemeControl extends React.PureComponent { // save parsed schemes for later this.schemes = isFunction(schemes) ? schemes() : schemes; - const options = (isFunction(choices) ? choices() : choices).map( - ([value]) => ({ - value, - label: this.schemes?.[value]?.label || value, - customLabel: this.renderOption(value), - }), + 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; + } + const selectProps = { ariaLabel: t('Select color scheme'), allowClear: this.props.clearable, - defaultValue: this.props.default, name: `select-${this.props.name}`, onChange: this.onChange, options, placeholder: `Select (${options.length})`, - showSearch: true, - value: this.props.value, + value: currentScheme, }; return (