Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: config to customize bootstrap data overrides #16386

Merged
merged 2 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,20 @@ 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 `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[
[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 = [
Expand Down
4 changes: 3 additions & 1 deletion superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down