Skip to content

Commit

Permalink
fix: Make Select component fire onChange listener when a selection is…
Browse files Browse the repository at this point in the history
… pasted in (#25993)

(cherry picked from commit 5fccf67)
  • Loading branch information
jfrag1 authored and michael-s-molina committed Nov 16, 2023
1 parent 8d873e6 commit ee1ba7e
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 246 deletions.
474 changes: 237 additions & 237 deletions helm/superset/README.md

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions superset-frontend/src/components/Select/AsyncSelect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/components/Select/AsyncSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ const AsyncSelect = forwardRef(
...values,
]);
}
fireOnChange();
};

const shouldRenderChildrenOptions = useMemo(
Expand Down
14 changes: 14 additions & 0 deletions superset-frontend/src/components/Select/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ const Select = forwardRef(
]);
}
}
fireOnChange();
};

return (
Expand Down
16 changes: 7 additions & 9 deletions superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ def db_engine_spec(self) -> builtins.type["BaseEngineSpec"]:
raise NotImplementedError()

@property
def database(self) -> builtins.type["Database"]:
def database(self) -> "Database":
raise NotImplementedError()

@property
Expand All @@ -783,7 +783,7 @@ def get_fetch_values_predicate(
self,
template_processor: Optional[ # pylint: disable=unused-argument
BaseTemplateProcessor
] = None, # pylint: disable=unused-argument
] = None,
) -> TextClause:
return self.fetch_values_predicate

Expand All @@ -792,7 +792,7 @@ def get_sqla_row_level_filters(
template_processor: BaseTemplateProcessor,
) -> list[TextClause]:
"""
Return the appropriate row level security filters for this table and the
Returns the appropriate row level security filters for this table and the
current user. A custom username can be passed when the user is not present in the
Flask global namespace.
Expand Down Expand Up @@ -896,7 +896,7 @@ def get_query_str_extended(
self, query_obj: QueryObjectDict, mutate: bool = True
) -> QueryStringExtended:
sqlaq = self.get_sqla_query(**query_obj)
sql = self.database.compile_sqla_query(sqlaq.sqla_query) # type: ignore
sql = self.database.compile_sqla_query(sqlaq.sqla_query)
sql = self._apply_cte(sql, sqlaq.cte)
sql = sqlparse.format(sql, reindent=True)
if mutate:
Expand Down Expand Up @@ -935,7 +935,7 @@ def _normalize_prequery_result_type(
value = value.item()

column_ = columns_by_name[dimension]
db_extra: dict[str, Any] = self.database.get_extra() # type: ignore
db_extra: dict[str, Any] = self.database.get_extra()

if isinstance(column_, dict):
if (
Expand Down Expand Up @@ -1020,9 +1020,7 @@ def assign_column_label(df: pd.DataFrame) -> Optional[pd.DataFrame]:
return df

try:
df = self.database.get_df(
sql, self.schema, mutator=assign_column_label # type: ignore
)
df = self.database.get_df(sql, self.schema, mutator=assign_column_label)
except Exception as ex: # pylint: disable=broad-except
df = pd.DataFrame()
status = QueryStatus.FAILED
Expand Down Expand Up @@ -1355,7 +1353,7 @@ def values_for_column(self, column_name: str, limit: int = 10000) -> list[Any]:
if self.fetch_values_predicate:
qry = qry.where(self.get_fetch_values_predicate(template_processor=tp))

with self.database.get_sqla_engine_with_context() as engine: # type: ignore
with self.database.get_sqla_engine_with_context() as engine:
sql = qry.compile(engine, compile_kwargs={"literal_binds": True})
sql = self._apply_cte(sql, cte)
sql = self.mutate_query_from_config(sql)
Expand Down

0 comments on commit ee1ba7e

Please sign in to comment.