This is an automated email from the ASF dual-hosted git repository. michaelsmolina pushed a commit to branch 3.0 in repository https://gitbox.apache.org/repos/asf/superset.git
commit 6201a297b4ad24eebb15e52cef8970a97573be3c Author: Jack Fragassi <[email protected]> AuthorDate: Thu Nov 16 12:06:05 2023 -0800 fix: Make Select component fire onChange listener when a selection is pasted in (#25993) (cherry picked from commit 5fccf67cdc4a84edb067a3cde48efacc76dbe33a) --- .../src/components/Select/AsyncSelect.test.tsx | 14 ++++++++++++++ superset-frontend/src/components/Select/AsyncSelect.tsx | 1 + superset-frontend/src/components/Select/Select.test.tsx | 14 ++++++++++++++ superset-frontend/src/components/Select/Select.tsx | 1 + superset/models/helpers.py | 2 +- 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/components/Select/AsyncSelect.test.tsx b/superset-frontend/src/components/Select/AsyncSelect.test.tsx index c1442a6b70..0bb24b474a 100644 --- a/superset-frontend/src/components/Select/AsyncSelect.test.tsx +++ b/superset-frontend/src/components/Select/AsyncSelect.test.tsx @@ -868,6 +868,20 @@ test('fires onChange when clearing the selection in multiple mode', async () => expect(onChange).toHaveBeenCalledTimes(1); }); +test('fires onChange when pasting a selection', async () => { + const onChange = jest.fn(); + render(<AsyncSelect {...defaultProps} onChange={onChange} />); + await open(); + const input = getElementByClassName('.ant-select-selection-search-input'); + const paste = createEvent.paste(input, { + clipboardData: { + getData: () => OPTIONS[0].label, + }, + }); + fireEvent(input, paste); + expect(onChange).toHaveBeenCalledTimes(1); +}); + test('does not duplicate options when using numeric values', async () => { render( <AsyncSelect diff --git a/superset-frontend/src/components/Select/AsyncSelect.tsx b/superset-frontend/src/components/Select/AsyncSelect.tsx index 20de7bb591..d102af7483 100644 --- a/superset-frontend/src/components/Select/AsyncSelect.tsx +++ b/superset-frontend/src/components/Select/AsyncSelect.tsx @@ -554,6 +554,7 @@ const AsyncSelect = forwardRef( ...values, ]); } + fireOnChange(); }; const shouldRenderChildrenOptions = useMemo( diff --git a/superset-frontend/src/components/Select/Select.test.tsx b/superset-frontend/src/components/Select/Select.test.tsx index a6b8307582..2910353295 100644 --- a/superset-frontend/src/components/Select/Select.test.tsx +++ b/superset-frontend/src/components/Select/Select.test.tsx @@ -985,6 +985,20 @@ test('fires onChange when clearing the selection in multiple mode', async () => expect(onChange).toHaveBeenCalledTimes(1); }); +test('fires onChange when pasting a selection', async () => { + const onChange = jest.fn(); + render(<Select {...defaultProps} onChange={onChange} />); + await open(); + const input = getElementByClassName('.ant-select-selection-search-input'); + const paste = createEvent.paste(input, { + clipboardData: { + getData: () => OPTIONS[0].label, + }, + }); + fireEvent(input, paste); + expect(onChange).toHaveBeenCalledTimes(1); +}); + test('does not duplicate options when using numeric values', async () => { render( <Select diff --git a/superset-frontend/src/components/Select/Select.tsx b/superset-frontend/src/components/Select/Select.tsx index 6ccc1e1715..1e3bc73758 100644 --- a/superset-frontend/src/components/Select/Select.tsx +++ b/superset-frontend/src/components/Select/Select.tsx @@ -571,6 +571,7 @@ const Select = forwardRef( ]); } } + fireOnChange(); }; return ( diff --git a/superset/models/helpers.py b/superset/models/helpers.py index 037e4d8c6e..3dff86ecee 100644 --- a/superset/models/helpers.py +++ b/superset/models/helpers.py @@ -783,7 +783,7 @@ class ExploreMixin: # pylint: disable=too-many-public-methods self, template_processor: Optional[ # pylint: disable=unused-argument BaseTemplateProcessor - ] = None, # pylint: disable=unused-argument + ] = None, ) -> TextClause: return self.fetch_values_predicate
