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

fix(nav): make doc and bug buttons customizable #22682

Merged
merged 2 commits into from
Jan 11, 2023
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
4 changes: 4 additions & 0 deletions superset-frontend/src/types/bootstrapTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@ export interface BrandProps {
export interface NavBarProps {
show_watermark: boolean;
bug_report_url?: string;
bug_report_text?: string;
bug_report_icon?: string;
version_string?: string;
version_sha?: string;
build_number?: string;
documentation_url?: string;
documentation_text?: string;
documentation_icon?: string;
languages: Languages;
show_language_picker: boolean;
user_is_anonymous: boolean;
Expand Down
47 changes: 30 additions & 17 deletions superset-frontend/src/views/components/RightMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -539,25 +539,38 @@ const RightMenu = ({
)}
</Menu>
{navbarRight.documentation_url && (
<StyledAnchor
href={navbarRight.documentation_url}
target="_blank"
rel="noreferrer"
title={t('Documentation')}
>
<i className="fa fa-question" />
&nbsp;
</StyledAnchor>
<>
<StyledAnchor
href={navbarRight.documentation_url}
target="_blank"
rel="noreferrer"
title={navbarRight.documentation_text || t('Documentation')}
Copy link
Member

@kgabryje kgabryje Jan 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Should we translate documentation_text? If not, we probably don't want to translate bug_report_text in line 564?
  2. Are you sure that t() will work correctly with dynamic expression like here (text depends on the result of || operator). Shouldn't we use t('%s', navbarRight.documentation_text || 'Documentation') instead? That's actually more of a question than suggestion, I'm not sure which style is preferred here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, the bug_report_text translation was a complete mistake from me! Will fix

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding question 2, I think the pattern in documentation_text is correct, i.e. we want to use the string from the config as-is, and only fall back to the translated text if it's undefined.

>
{navbarRight.documentation_icon ? (
<i className={navbarRight.documentation_icon} />
) : (
<i className="fa fa-question" />
)}
</StyledAnchor>
<span>&nbsp;</span>
</>
)}
{navbarRight.bug_report_url && (
<StyledAnchor
href={navbarRight.bug_report_url}
target="_blank"
rel="noreferrer"
title={t('Report a bug')}
>
<i className="fa fa-bug" />
</StyledAnchor>
<>
<StyledAnchor
href={navbarRight.bug_report_url}
target="_blank"
rel="noreferrer"
title={navbarRight.bug_report_text || t('Report a bug')}
>
{navbarRight.bug_report_icon ? (
<i className={navbarRight.bug_report_icon} />
) : (
<i className="fa fa-bug" />
)}
</StyledAnchor>
<span>&nbsp;</span>
</>
)}
{navbarRight.user_is_anonymous && (
<StyledAnchor href={navbarRight.user_login_url}>
Expand Down
2 changes: 2 additions & 0 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,8 @@ def EMAIL_HEADER_MUTATOR( # pylint: disable=invalid-name,unused-argument

# Send user to a link where they can report bugs
BUG_REPORT_URL = None
BUG_REPORT_TEXT = "Report a bug"
BUG_REPORT_ICON = None # Recommended size: 16x16

# Send user to a link where they can read more about Superset
DOCUMENTATION_URL = None
Expand Down
127 changes: 0 additions & 127 deletions superset/templates/appbuilder/navbar_right.html

This file was deleted.

4 changes: 4 additions & 0 deletions superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,11 @@ def menu_data(user: User) -> Dict[str, Any]:
# show the watermark if the default app icon has been overriden
"show_watermark": ("superset-logo-horiz" not in appbuilder.app_icon),
"bug_report_url": appbuilder.app.config["BUG_REPORT_URL"],
"bug_report_icon": appbuilder.app.config["BUG_REPORT_ICON"],
"bug_report_text": appbuilder.app.config["BUG_REPORT_TEXT"],
"documentation_url": appbuilder.app.config["DOCUMENTATION_URL"],
"documentation_icon": appbuilder.app.config["DOCUMENTATION_ICON"],
"documentation_text": appbuilder.app.config["DOCUMENTATION_TEXT"],
"version_string": appbuilder.app.config["VERSION_STRING"],
"version_sha": appbuilder.app.config["VERSION_SHA"],
"build_number": build_number,
Expand Down