aminghadersohi commented on code in PR #44985:
URL: https://github.com/apache/superset/pull/44985#discussion_r4186825696
##########
superset/mcp_service/dashboard/tool/manage_native_filters.py:
##########
@@ -240,6 +328,15 @@ def _merge_filter_update(
control_values[control_key] = value
merged["controlValues"] = control_values
+ if spec.default_value is not None:
Review Comment:
Fixed in e7c59d756482aa09a3498de6368f441ddc81986c. P2 update path:
retargeting the filter (column/dataset_id), switching to single-select while
the stored default has several values, or enabling default_to_first_item
without a new default_value now resets the stored default (single-value
defaults are kept when switching to single-select). Passing default_value
together with default_to_first_item is still rejected. Covered by new tests in
test_manage_native_filters.py.
##########
superset/mcp_service/dashboard/tool/manage_native_filters.py:
##########
@@ -64,6 +72,83 @@ def _empty_data_mask() -> dict[str, Any]:
return {"filterState": {"value": None}, "extraFormData": {}}
+def _value_label(value: FilterSelectValue) -> str:
+ """Format one selected value the way the dashboard UI labels it."""
+ if value is None:
+ return _NULL_LABEL
+ if isinstance(value, bool):
+ return _TRUE_LABEL if value else _FALSE_LABEL
+ return str(value)
+
+
+def _select_data_mask(
+ conf: dict[str, Any], values: list[FilterSelectValue]
+) -> dict[str, Any]:
+ """Build the data mask a filter_select filter produces for ``values``.
+
+ Mirrors the frontend's ``getSelectExtraFormData``: a non-empty selection
+ becomes an ``IN`` predicate on the filter's target column, and an empty
+ selection on a filter marked ``enableEmptyFilter`` becomes an impossible
+ predicate (the "required filter, nothing chosen" state) rather than no
+ filtering at all. Shared by ``apply_dashboard_filters`` (applied values)
+ and this module (default values on create/update) so both paths agree.
+ """
+ targets = [target for target in (conf.get("targets") or []) if target]
+ column = (targets[0].get("column") or {}).get("name") if targets else None
+ if not column:
+ raise _FilterValidationError(
+ f"Filter '{conf.get('name') or conf.get('id')}' has no target "
+ "column, so a value cannot be applied to it."
+ )
+
+ control_values = conf.get("controlValues") or {}
+ if control_values.get("inverseSelection"):
Review Comment:
Fixed in e7c59d756482aa09a3498de6368f441ddc81986c. P3 default_value=[] now
stores the plain empty mask for filters with inverseSelection or a non-exact
operator, so the default can be cleared; non-empty defaults and
apply_dashboard_filters keep the guards. Covered by new tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]