From 339e4736a33b2bf09bf0f68c8d2a0a366107edd5 Mon Sep 17 00:00:00 2001 From: chriddyp Date: Mon, 18 Sep 2017 13:23:56 -0400 Subject: [PATCH 1/5] Add custom tokenizer to support non-ascii character search --- src/components/Dropdown.react.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/components/Dropdown.react.js b/src/components/Dropdown.react.js index 3b19acfe0..de0413a3f 100644 --- a/src/components/Dropdown.react.js +++ b/src/components/Dropdown.react.js @@ -3,6 +3,18 @@ import React, {Component, PropTypes} from 'react'; import ReactDropdown from 'react-virtualized-select'; import createFilterOptions from 'react-select-fast-filter-options'; +// Custom tokenizer, see https://github.com/bvaughn/js-search/issues/43 +const REGEX = /\s+/; // Split on spaces +const TOKENIZER = { + tokenize(text) { + return text + .split(REGEX) + .filter( + (text) => text // Filter empty tokens + ); + } +} + const DELIMETER = ','; /** @@ -28,7 +40,10 @@ export default class Dropdown extends Component { this.setState({value: newProps.value}); if (newProps.options !== this.props.options) { this.setState({ - filterOptions: createFilterOptions({options: newProps.options}) + filterOptions: createFilterOptions({ + options: newProps.options, + tokenizer: TOKENIZER + }) }); } } From 1ee2f90b9ed72b3bb49ec49f0d1ef50de431be66 Mon Sep 17 00:00:00 2001 From: chriddyp Date: Mon, 18 Sep 2017 13:24:24 -0400 Subject: [PATCH 2/5] add chinese characters to tests --- test/test_integration.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/test/test_integration.py b/test/test_integration.py index 8b1e88fd7..ee12fda6a 100644 --- a/test/test_integration.py +++ b/test/test_integration.py @@ -53,9 +53,11 @@ def test_integration(self): options=[ {'label': 'New York City', 'value': 'NYC'}, {'label': u'Montréal', 'value': 'MTL'}, - {'label': 'San Francisco', 'value': 'SF'} + {'label': 'San Francisco', 'value': 'SF'}, + {'label': u'北京', 'value': u'北京'} ], - value='MTL' + value='MTL', + id={'dropdown'} ), html.Label('Multi-Select Dropdown'), @@ -63,7 +65,8 @@ def test_integration(self): options=[ {'label': 'New York City', 'value': 'NYC'}, {'label': u'Montréal', 'value': 'MTL'}, - {'label': 'San Francisco', 'value': 'SF'} + {'label': 'San Francisco', 'value': 'SF'}, + {'label': u'北京', 'value': u'北京'} ], value=['MTL', 'SF'], multi=True @@ -74,7 +77,8 @@ def test_integration(self): options=[ {'label': 'New York City', 'value': 'NYC'}, {'label': u'Montréal', 'value': 'MTL'}, - {'label': 'San Francisco', 'value': 'SF'} + {'label': 'San Francisco', 'value': 'SF'}, + {'label': u'北京', 'value': u'北京'} ], value='MTL' ), @@ -84,7 +88,8 @@ def test_integration(self): options=[ {'label': 'New York City', 'value': 'NYC'}, {'label': u'Montréal', 'value': 'MTL'}, - {'label': 'San Francisco', 'value': 'SF'} + {'label': 'San Francisco', 'value': 'SF'}, + {'label': u'北京', 'value': u'北京'} ], values=['MTL', 'SF'] ), @@ -107,7 +112,10 @@ def test_integration(self): 'data': [{ 'x': [1, 2, 3], 'y': [4, 1, 4] - }] + }], + 'layout': { + 'title': u'北京' + } } ), @@ -126,7 +134,7 @@ def test_integration(self): html.Label('TextArea'), dcc.Textarea( - placeholder='Enter a value...', + placeholder='Enter a value... 北京', style={'width': '100%'} ), @@ -140,6 +148,8 @@ def test_integration(self): It includes a syntax for things like **bold text** and *italics*, [links](http://commonmark.org/help), inline `code` snippets, lists, quotes, and more. + + 北京 '''.replace(' ', '')) ]) self.startServer(app) From f6aca924e64a4ebd5b6eca32c753923a496cb220 Mon Sep 17 00:00:00 2001 From: chriddyp Date: Mon, 18 Sep 2017 13:29:06 -0400 Subject: [PATCH 3/5] snapshot test chinese character search --- test/test_integration.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/test/test_integration.py b/test/test_integration.py index ee12fda6a..d9ca577ad 100644 --- a/test/test_integration.py +++ b/test/test_integration.py @@ -42,6 +42,11 @@ def wait_for_element_by_css_selector(css_selector): return self.driver.find_element_by_css_selector(css_selector) self.wait_for_element_by_css_selector = wait_for_element_by_css_selector + def snapshot(self, name): + if 'PERCY_PROJECT' in os.environ and 'PERCY_TOKEN' in os.environ: + python_version = sys.version.split(' ')[0] + print('Percy Snapshot {}'.format(python_version)) + self.percy_runner.snapshot(name=name) def test_integration(self): app = dash.Dash(__name__) @@ -57,7 +62,7 @@ def test_integration(self): {'label': u'北京', 'value': u'北京'} ], value='MTL', - id={'dropdown'} + id='dropdown' ), html.Label('Multi-Select Dropdown'), @@ -161,7 +166,9 @@ def test_integration(self): '_dash-app-content').get_attribute('innerHTML')) raise e - if 'PERCY_PROJECT' in os.environ and 'PERCY_TOKEN' in os.environ: - python_version = sys.version.split(' ')[0] - print('Percy Snapshot {}'.format(python_version)) - self.percy_runner.snapshot() + self.snapshot('gallery') + + self.driver.find_element_by_css_selector( + '#dropdown .Select-input input' + ).send_keys(u'北') + self.snapshot('gallery - chinese character') From 15b50046eb79e98e71e97db0afb1434291f9bc3f Mon Sep 17 00:00:00 2001 From: chriddyp Date: Mon, 18 Sep 2017 13:31:12 -0400 Subject: [PATCH 4/5] add tokenizer to the constructor --- src/components/Dropdown.react.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/Dropdown.react.js b/src/components/Dropdown.react.js index de0413a3f..4bfbdd3b2 100644 --- a/src/components/Dropdown.react.js +++ b/src/components/Dropdown.react.js @@ -32,7 +32,10 @@ export default class Dropdown extends Component { super(props); this.state = { value: props.value, - filterOptions: createFilterOptions({options: props.options}) + filterOptions: createFilterOptions({ + options: props.options, + tokenizer: TOKENIZER + }) }; } From e69655556fdf439ac870784a5b5c1952c24ce771 Mon Sep 17 00:00:00 2001 From: chriddyp Date: Mon, 18 Sep 2017 13:35:05 -0400 Subject: [PATCH 5/5] v0.12.6 --- CHANGELOG.md | 6 ++++++ dash_core_components/version.py | 2 +- package.json | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a766efec7..82b953bac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [0.12.6] - 2017-09-11 +### :bug: Fixed +- Non-ascii characters, like chinese characters, are now supported as + search strings in the `dcc.Dropdown` component (https://github.com/plotly/dash-core-components/pull/75) + + ## [0.12.5] - 2017-09-11 ### :bug: Fixed - The `Interval` component was constantly resetting its interval on every update. Initially reported in https://community.plot.ly/t/multiple-interval-object-in-a-single-page/5699/3 diff --git a/dash_core_components/version.py b/dash_core_components/version.py index 37f150490..55fe9c406 100644 --- a/dash_core_components/version.py +++ b/dash_core_components/version.py @@ -1 +1 @@ -__version__ = '0.12.5' +__version__ = '0.12.6' diff --git a/package.json b/package.json index 4e804f3a4..b13358717 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dash-core-components", - "version": "0.12.5", + "version": "0.12.6", "description": "Core component suite for Dash", "repository": { "type": "git",