Skip to content

Commit

Permalink
last touches
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Apr 18, 2018
1 parent 01aa3a2 commit 741832e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,7 @@ describe('FilterControl', () => {
// Sets active to null after success
$.ajax.getCall(0).args[0].success(['opt1', 'opt2', null, '']);
expect(wrapper.state().filters[0].valuesLoading).to.equal(false);
expect(wrapper.state().filters[0].valueChoices).to.deep.equal([
{ value: 'opt1', label: 'opt1' },
{ value: 'opt2', label: 'opt2' },
{ value: '<NULL>', label: '<NULL>' },
{ value: '', label: '<empty string>' },
]);
expect(wrapper.state().filters[0].valueChoices).to.deep.equal(['opt1', 'opt2', null, '']);
expect(wrapper.state().activeRequest).to.equal(null);
});

Expand Down
12 changes: 11 additions & 1 deletion superset/assets/spec/javascripts/utils/common_spec.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { it, describe } from 'mocha';
import { expect } from 'chai';
import { isTruthy } from '../../../src/utils/common';
import { isTruthy, optionFromValue } from '../../../src/utils/common';

describe('utils/common', () => {
describe('isTruthy', () => {
Expand Down Expand Up @@ -40,4 +40,14 @@ describe('utils/common', () => {
expect(isTruthy('false')).to.equal(false);
});
});
describe('optionFromValue', () => {
it('converts values as expected', () => {
expect(optionFromValue(false)).to.deep.equal({ value: false, label: '<false>' });
expect(optionFromValue(true)).to.deep.equal({ value: true, label: '<true>' });
expect(optionFromValue(null)).to.deep.equal({ value: '<NULL>', label: '<NULL>' });
expect(optionFromValue('')).to.deep.equal({ value: '', label: '<empty string>' });
expect(optionFromValue('foo')).to.deep.equal({ value: 'foo', label: 'foo' });
expect(optionFromValue(5)).to.deep.equal({ value: 5, label: '5' });
});
});
});
26 changes: 0 additions & 26 deletions superset/assets/src/components/OnPasteSelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,6 @@ import React from 'react';
import PropTypes from 'prop-types';
import Select from 'react-select';


function optionLabel(opt) {
if (opt === null) {
return '<NULL>';
} else if (opt === '') {
return '<empty string>';
} else if (opt === true) {
return '<true>';
} else if (opt === '') {
return '<false>';
}
return opt;
}
function optionValue(opt) {
if (opt === null) {
return '<NULL>';
}
return opt;
}
function optionFromValue(opt) {
// From a list of options, handles special values & labels
return { value: optionValue(opt), label: optionLabel(opt) };
}


export default class OnPasteSelect extends React.Component {
onPaste(evt) {
if (!this.props.multi) {
Expand Down Expand Up @@ -80,7 +55,6 @@ export default class OnPasteSelect extends React.Component {
this.pasteInput = ref;
};
const inputProps = { onPaste: this.onPaste.bind(this) };
console.log(this.props);
return (
<SelectComponent
{...this.props}
Expand Down
1 change: 0 additions & 1 deletion superset/assets/src/explore/components/controls/Filter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
import Select from 'react-select';
import { Button, Row, Col } from 'react-bootstrap';
import { t } from '../../../locales';
import OnPasteSelect from '../../../components/OnPasteSelect';
import SelectControl from './SelectControl';

const operatorsArr = [
Expand Down
2 changes: 2 additions & 0 deletions superset/assets/src/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export function optionLabel(opt) {
return '<true>';
} else if (opt === false) {
return '<false>';
} else if (typeof opt !== 'string' && opt.toString) {
return opt.toString();
}
return opt;
}
Expand Down

0 comments on commit 741832e

Please sign in to comment.