MDeadman commented on code in PR #38638: URL: https://github.com/apache/superset/pull/38638#discussion_r2942998708
########## superset/charts/data/dashboard_filter_context.py: ########## @@ -0,0 +1,288 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +import logging +from dataclasses import dataclass, field +from enum import Enum +from typing import Any + +from flask_babel import gettext as _ + +from superset import db, security_manager +from superset.models.dashboard import Dashboard +from superset.utils import json + +logger = logging.getLogger(__name__) + +CHART_TYPE = "CHART" + + +class DashboardFilterStatus(str, Enum): + APPLIED = "applied" + NOT_APPLIED = "not_applied" + NOT_APPLIED_USES_DEFAULT_TO_FIRST_ITEM_PREQUERY = ( + "not_applied_uses_default_to_first_item_prequery" + ) + + +@dataclass +class DashboardFilterInfo: + id: str + name: str + status: DashboardFilterStatus + column: str | None = None + + +@dataclass +class DashboardFilterContext: + extra_form_data: dict[str, Any] = field(default_factory=dict) + filters: list[DashboardFilterInfo] = field(default_factory=list) + + def to_dict(self) -> dict[str, Any]: + return { + "filters": [ + { + "id": f.id, + "name": f.name, + "status": f.status.value, + **({"column": f.column} if f.column else {}), + } + for f in self.filters + ], + } + + +def _is_filter_in_scope_for_chart( + filter_config: dict[str, Any], + chart_id: int, + position_json: dict[str, Any], +) -> bool: + """ + Determines whether a native filter applies to a given chart. When + chartsInScope is present on the filter config, uses that directly. + Otherwise falls back to scope.rootPath and scope.excluded with + the dashboard layout. + """ + if charts_in_scope := filter_config.get("chartsInScope"): + return chart_id in charts_in_scope Review Comment: Resolved and added a test to test_dashboard_filter_context.py to capture this. -- 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]
