From cf83f4b8a162ba70879169364bef38035aaee829 Mon Sep 17 00:00:00 2001 From: David Aaron Suddjian Date: Fri, 20 Aug 2021 16:01:17 -0700 Subject: [PATCH 1/2] feat: config to customize bootstrap data overrides --- superset/config.py | 10 ++++++++++ superset/views/base.py | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/superset/config.py b/superset/config.py index f18fcca8a863a..a286d2b51acea 100644 --- a/superset/config.py +++ b/superset/config.py @@ -435,6 +435,16 @@ def _try_json_readsha( # pylint: disable=unused-argument # return feature_flags_dict GET_FEATURE_FLAGS_FUNC: Optional[Callable[[Dict[str, bool]], Dict[str, bool]]] = None +# A function that expands/overrides the frontend common bootstrap data. +# Can be used to implement custom frontend functionality, +# or dynamically change certain configs. +# +# Takes as a parameter the common bootstrap payload before transformations. +# Returns a dict containing data that should be added or overridden to the payload. +COMMON_BOOTSTRAP_OVERRIDES_FUNC: Callable[ + [Dict[str, Any]], Dict[str, Any] +] = lambda data: {} # default: empty dict + # EXTRA_CATEGORICAL_COLOR_SCHEMES is used for adding custom categorical color schemes # example code for "My custom warm to hot" color scheme # EXTRA_CATEGORICAL_COLOR_SCHEMES = [ diff --git a/superset/views/base.py b/superset/views/base.py index 2de98b5e6b91e..20187299fee85 100644 --- a/superset/views/base.py +++ b/superset/views/base.py @@ -350,7 +350,7 @@ def common_bootstrap_payload() -> Dict[str, Any]: messages = get_flashed_messages(with_categories=True) locale = str(get_locale()) - return { + bootstrap_data = { "flash_messages": messages, "conf": {k: conf.get(k) for k in FRONTEND_CONF_KEYS}, "locale": locale, @@ -361,6 +361,8 @@ def common_bootstrap_payload() -> Dict[str, Any]: "theme_overrides": conf["THEME_OVERRIDES"], "menu_data": menu_data(), } + bootstrap_data.update(conf["COMMON_BOOTSTRAP_OVERRIDES_FUNC"](bootstrap_data)) + return bootstrap_data # pylint: disable=invalid-name From 1ee961d5ce35a13db7b5cac14c850930f62b8c7e Mon Sep 17 00:00:00 2001 From: David Aaron Suddjian Date: Fri, 20 Aug 2021 16:27:41 -0700 Subject: [PATCH 2/2] comments --- superset/config.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/superset/config.py b/superset/config.py index a286d2b51acea..501d30397b6cb 100644 --- a/superset/config.py +++ b/superset/config.py @@ -435,10 +435,14 @@ def _try_json_readsha( # pylint: disable=unused-argument # return feature_flags_dict GET_FEATURE_FLAGS_FUNC: Optional[Callable[[Dict[str, bool]], Dict[str, bool]]] = None -# A function that expands/overrides the frontend common bootstrap data. +# A function that expands/overrides the frontend `bootstrap_data.common` object. # Can be used to implement custom frontend functionality, # or dynamically change certain configs. # +# Values in `bootstrap_data.common` should have these characteristics: +# - They are not specific to a page the user is visiting +# - They do not contain secrets +# # Takes as a parameter the common bootstrap payload before transformations. # Returns a dict containing data that should be added or overridden to the payload. COMMON_BOOTSTRAP_OVERRIDES_FUNC: Callable[