code: def convert_filter_scopes(
      json_metadata: dict[Any, Any], filter_boxes: list[Slice]
  ) -> dict[int, dict[str, dict[str, Any]]]:
      filter_scopes = {}
      immuned_by_id: list[int] = (
          json_metadata.get("filter_immune_slices") or []
      )
      immuned_by_column: dict[str, list[int]] = defaultdict(list)
      for slice_id, columns in json_metadata.get(
          "filter_immune_slice_fields", {}
      ).items():
          for column in columns:
              immuned_by_column[column].append(int(slice_id))
  
      def add_filter_scope(
          filter_fields: dict[str, dict[str, Any]],
          filter_field: str,
          filter_id: int,
      ) -> None:
          # in case filter field is invalid
          if isinstance(filter_field, str):
              current_filter_immune = list(
                  set(
                      immuned_by_id
                      + immuned_by_column.get(filter_field, [])
                  )
              )
              filter_fields[filter_field] = {
                  "scope": ["ROOT_ID"],
                  "immune": current_filter_immune,
              }
          else:
              logging.info(
                  "slice [%i] has invalid field: %s",
                  filter_id,
                  filter_field,
              )
  
      for filter_box in filter_boxes:
          filter_fields: dict[str, dict[str, Any]] = {}
          filter_id = filter_box.id
          slice_params = json.loads(filter_box.params or "{}")
          configs = slice_params.get("filter_configs") or []
  
          if slice_params.get("date_filter"):
              add_filter_scope(filter_fields, "__time_range", filter_id)
          if slice_params.get("show_sqla_time_column"):
              add_filter_scope(filter_fields, "__time_col", filter_id)
          if slice_params.get("show_sqla_time_granularity"):
              add_filter_scope(filter_fields, "__time_grain", filter_id)
          for config in configs:
              add_filter_scope(
                  filter_fields, config.get("column"), filter_id
              )
  
          if filter_fields:
              filter_scopes[filter_id] = filter_fields
  
      return filter_scopes
  
file_path: superset/superset/utils/dashboard_filter_scopes_converter.py
imports: import json
  import logging
  from collections import defaultdict
  from typing import Any
  from shortid import ShortId
  from superset.models.slice import Slice
label_desc: Use image node_id 1 for calling a global function with example usage: convert_filter_scopes(json_metadata, filter_boxes) and returns: filter_scopes