This is an automated email from the ASF dual-hosted git repository.
ccwilliams pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push:
new 14de28a [bugfix] Fix color scheme picker (#5891)
14de28a is described below
commit 14de28a4f20cc47832c40112f3bda4fca7f1fd3d
Author: Krist Wongsuphasawat <[email protected]>
AuthorDate: Tue Sep 18 09:50:14 2018 -0700
[bugfix] Fix color scheme picker (#5891)
* Fix color scheme picker
* fix .value
---
superset/assets/src/explore/components/Control.jsx | 8 +++++--
.../components/controls/ColorSchemeControl.jsx | 26 +++++++++++++++-------
superset/assets/src/explore/controls.jsx | 6 ++---
3 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/superset/assets/src/explore/components/Control.jsx
b/superset/assets/src/explore/components/Control.jsx
index bc58ec2..1891a8c 100644
--- a/superset/assets/src/explore/components/Control.jsx
+++ b/superset/assets/src/explore/components/Control.jsx
@@ -11,7 +11,10 @@ const propTypes = {
type: PropTypes.oneOf(controlTypes).isRequired,
hidden: PropTypes.bool,
label: PropTypes.string.isRequired,
- choices: PropTypes.arrayOf(PropTypes.array),
+ choices: PropTypes.oneOfType([
+ PropTypes.arrayOf(PropTypes.array),
+ PropTypes.func,
+ ]),
description: PropTypes.string,
tooltipOnClick: PropTypes.func,
places: PropTypes.number,
@@ -26,7 +29,8 @@ const propTypes = {
PropTypes.object,
PropTypes.bool,
PropTypes.array,
- PropTypes.func]),
+ PropTypes.func,
+ ]),
};
const defaultProps = {
diff --git
a/superset/assets/src/explore/components/controls/ColorSchemeControl.jsx
b/superset/assets/src/explore/components/controls/ColorSchemeControl.jsx
index 14702d8..9463150 100644
--- a/superset/assets/src/explore/components/controls/ColorSchemeControl.jsx
+++ b/superset/assets/src/explore/components/controls/ColorSchemeControl.jsx
@@ -1,8 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
+import _ from 'underscore';
import { Creatable } from 'react-select';
import ControlHeader from '../ControlHeader';
-
import { colorScalerFactory } from '../../../modules/colors';
const propTypes = {
@@ -12,8 +12,14 @@ const propTypes = {
onChange: PropTypes.func,
value: PropTypes.string,
default: PropTypes.string,
- choices: PropTypes.arrayOf(PropTypes.array).isRequired,
- schemes: PropTypes.object.isRequired,
+ choices: PropTypes.oneOfType([
+ PropTypes.arrayOf(PropTypes.array),
+ PropTypes.func,
+ ]).isRequired,
+ schemes: PropTypes.oneOfType([
+ PropTypes.object,
+ PropTypes.func,
+ ]).isRequired,
isLinear: PropTypes.bool,
};
@@ -41,9 +47,9 @@ export default class ColorSchemeControl extends
React.PureComponent {
}
renderOption(key) {
- const currentScheme = key.value ?
- this.props.schemes[key.value] :
- this.props.schemes[defaultProps.value];
+ const { schemes } = this.props;
+ const schemeLookup = _.isFunction(schemes) ? schemes() : schemes;
+ const currentScheme = schemeLookup[key.value || defaultProps.value];
let colors = currentScheme;
if (this.props.isLinear) {
@@ -61,12 +67,16 @@ export default class ColorSchemeControl extends
React.PureComponent {
}
render() {
+ const { choices } = this.props;
+ const options = (_.isFunction(choices) ? choices() : choices)
+ .map(choice => ({ value: choice[0], label: choice[1] }));
+
const selectProps = {
multi: false,
name: `select-${this.props.name}`,
- placeholder: `Select (${this.props.choices.length})`,
+ placeholder: `Select (${options.length})`,
default: this.props.default,
- options: this.props.choices.map(choice => ({ value: choice[0], label:
choice[1] })),
+ options,
value: this.props.value,
autosize: false,
clearable: false,
diff --git a/superset/assets/src/explore/controls.jsx
b/superset/assets/src/explore/controls.jsx
index 9700454..f170ec4 100644
--- a/superset/assets/src/explore/controls.jsx
+++ b/superset/assets/src/explore/controls.jsx
@@ -53,8 +53,6 @@ import { t } from '../locales';
import { getAllSchemes } from '../modules/ColorSchemeManager';
import sequentialSchemes from '../modules/colorSchemes/sequential';
-const ALL_COLOR_SCHEMES = getAllSchemes();
-
const D3_FORMAT_DOCS = 'D3 format syntax: https://github.com/d3/d3-format';
// input choices & options
@@ -1977,9 +1975,9 @@ export const controls = {
label: t('Color Scheme'),
default: 'bnbColors',
renderTrigger: true,
- choices: Object.keys(ALL_COLOR_SCHEMES).map(s => ([s, s])),
+ choices: () => Object.keys(getAllSchemes()).map(s => ([s, s])),
description: t('The color scheme for rendering chart'),
- schemes: ALL_COLOR_SCHEMES,
+ schemes: () => getAllSchemes(),
},
significance_level: {