Skip to content

Commit

Permalink
[bugfix] Fix color scheme picker (apache#5891)
Browse files Browse the repository at this point in the history
* Fix color scheme picker

* fix .value
  • Loading branch information
kristw authored and betodealmeida committed Oct 12, 2018
1 parent 480667d commit e269288
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
8 changes: 6 additions & 2 deletions superset/assets/src/explore/components/Control.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -26,7 +29,8 @@ const propTypes = {
PropTypes.object,
PropTypes.bool,
PropTypes.array,
PropTypes.func]),
PropTypes.func,
]),
};

const defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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,
};

Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions superset/assets/src/explore/controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit e269288

Please sign in to comment.