Skip to content

Commit

Permalink
fix(explore comma): make that the comma can be added by removing it f…
Browse files Browse the repository at this point in the history
…rom token separators… (#18926)

* make that the comma can be added by removing it from token separators in select component.

* fix(explore comma): add the allowTokenSeperators props into Select

* fix(explore comma): make to allow to customize the token separators in Select.

* fix(explore comma): make to add the unit test and story book.

* fix(explore comma): make to fix the lint

* fix(explore comma): make to fix the spell  & add tokenSeparatprs props to PickedSelectProps

* Update Select.tsx

* fix(explore comma): make to run lint fix
  • Loading branch information
prosdev0107 committed Mar 18, 2022
1 parent 2a89da2 commit e7355b9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ const y_axis_format: SharedControlConfig<'SelectControl', SelectDefaultOption> =
default: DEFAULT_NUMBER_FORMAT,
choices: D3_FORMAT_OPTIONS,
description: D3_FORMAT_DOCS,
tokenSeparators: ['\n', '\t', ';'],
filterOption: ({ data: option }, search) =>
option.label.includes(search) || option.value.includes(search),
mapStateToProps: state => {
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/components/Select/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ AsyncSelect.args = {
pageSize: 10,
withError: false,
withInitialValue: false,
tokenSeparators: ['\n', '\t', ';'],
};

AsyncSelect.argTypes = {
Expand Down
4 changes: 3 additions & 1 deletion superset-frontend/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type PickedSelectProps = Pick<
| 'onDropdownVisibleChange'
| 'placeholder'
| 'showSearch'
| 'tokenSeparators'
| 'value'
>;

Expand Down Expand Up @@ -310,6 +311,7 @@ const Select = (
placeholder = t('Select ...'),
showSearch = true,
sortComparator = DEFAULT_SORT_COMPARATOR,
tokenSeparators,
value,
...props
}: SelectProps,
Expand Down Expand Up @@ -706,7 +708,7 @@ const Select = (
placeholder={placeholder}
showSearch={shouldShowSearch}
showArrow
tokenSeparators={TOKEN_SEPARATORS}
tokenSeparators={tokenSeparators || TOKEN_SEPARATORS}
value={selectValue}
suffixIcon={getSuffixIcon()}
menuItemSelectedIcon={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const propTypes = {
options: PropTypes.array,
placeholder: PropTypes.string,
filterOption: PropTypes.func,
tokenSeparators: PropTypes.arrayOf(PropTypes.string),

// ControlHeader props
label: PropTypes.string,
Expand Down Expand Up @@ -177,6 +178,7 @@ export default class SelectControl extends React.PureComponent {
optionRenderer,
showHeader,
value,
tokenSeparators,
// ControlHeader props
description,
renderTrigger,
Expand Down Expand Up @@ -242,6 +244,7 @@ export default class SelectControl extends React.PureComponent {
placeholder,
sortComparator: this.props.sortComparator,
value: getValue(),
tokenSeparators,
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ describe('SelectControl', () => {
expect(wrapper.find(SelectComponent).prop('allowNewOptions')).toBe(false);
});

it('renders with tokenSeparators', () => {
wrapper.setProps({ tokenSeparators: ['\n', '\t', ';'] });
expect(wrapper.find(SelectComponent)).toExist();
expect(wrapper.find(SelectComponent).prop('tokenSeparators')).toEqual(
expect.arrayContaining([expect.any(String)]),
);
});

describe('empty placeholder', () => {
describe('withMulti', () => {
it('does not show a placeholder if there are no choices', () => {
Expand Down

0 comments on commit e7355b9

Please sign in to comment.