From 0ba6d52e0ad925172b2f70cb5b66702441e41ead Mon Sep 17 00:00:00 2001 From: cccs-joel Date: Tue, 1 Jun 2021 21:35:57 +0000 Subject: [PATCH 1/3] Added code to get the build number from the config and show the value in the About area, if present. --- superset-frontend/src/components/Menu/Menu.test.tsx | 7 +++++-- superset-frontend/src/components/Menu/Menu.tsx | 1 + superset-frontend/src/components/Menu/MenuRight.tsx | 7 ++++++- superset/views/base.py | 8 ++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/superset-frontend/src/components/Menu/Menu.test.tsx b/superset-frontend/src/components/Menu/Menu.test.tsx index daeb5262f726b..2aa6544620b04 100644 --- a/superset-frontend/src/components/Menu/Menu.test.tsx +++ b/superset-frontend/src/components/Menu/Menu.test.tsx @@ -100,6 +100,7 @@ const mockedProps = { locale: 'en', version_string: '1.0.0', version_sha: 'randomSHA', + build_number: 'randomBuildNumber', }, settings: [ { @@ -277,10 +278,10 @@ test('should render the Profile link when available', async () => { expect(profile).toHaveAttribute('href', user_profile_url); }); -test('should render the About section and version_string or sha when available', async () => { +test('should render the About section and version_string, sha or build_number when available', async () => { const { data: { - navbar_right: { version_sha, version_string }, + navbar_right: { version_sha, version_string, build_number }, }, } = mockedProps; @@ -289,9 +290,11 @@ test('should render the About section and version_string or sha when available', const about = await screen.findByText('About'); const version = await screen.findByText(`Version: ${version_string}`); const sha = await screen.findByText(`SHA: ${version_sha}`); + const build = await screen.findByText(`Build: ${build_number}`); expect(about).toBeInTheDocument(); expect(version).toBeInTheDocument(); expect(sha).toBeInTheDocument(); + expect(build).toBeInTheDocument(); }); test('should render the Documentation link when available', async () => { diff --git a/superset-frontend/src/components/Menu/Menu.tsx b/superset-frontend/src/components/Menu/Menu.tsx index 0875b85f8a661..62e5d02c1581d 100644 --- a/superset-frontend/src/components/Menu/Menu.tsx +++ b/superset-frontend/src/components/Menu/Menu.tsx @@ -40,6 +40,7 @@ export interface NavBarProps { bug_report_url?: string; version_string?: string; version_sha?: string; + build_number?: string; documentation_url?: string; languages: Languages; show_language_picker: boolean; diff --git a/superset-frontend/src/components/Menu/MenuRight.tsx b/superset-frontend/src/components/Menu/MenuRight.tsx index a722834bdf442..a6ad597e94e03 100644 --- a/superset-frontend/src/components/Menu/MenuRight.tsx +++ b/superset-frontend/src/components/Menu/MenuRight.tsx @@ -141,7 +141,7 @@ const RightMenu = ({ , ]} - {(navbarRight.version_string || navbarRight.version_sha) && [ + {(navbarRight.version_string || navbarRight.version_sha || navbarRight.build_number) && [ ,
@@ -155,6 +155,11 @@ const RightMenu = ({ SHA: {navbarRight.version_sha}
)} + {navbarRight.build_number && ( +
+ Build: {navbarRight.build_number} +
+ )}
, ]} diff --git a/superset/views/base.py b/superset/views/base.py index 74e05db5402aa..89328c6f495c6 100644 --- a/superset/views/base.py +++ b/superset/views/base.py @@ -305,6 +305,13 @@ def menu_data() -> Dict[str, Any]: **appbuilder.languages[lang], "url": appbuilder.get_url_for_locale(lang), } + + build_number = "" + try: + build_number = appbuilder.app.config["BUILD_NUMBER"] + except Exception as ex: + logger.debug("BUILD_NUMBER is missing from the config", ex) + return { "menu": menu, "brand": { @@ -318,6 +325,7 @@ def menu_data() -> Dict[str, Any]: "documentation_url": appbuilder.app.config["DOCUMENTATION_URL"], "version_string": appbuilder.app.config["VERSION_STRING"], "version_sha": appbuilder.app.config["VERSION_SHA"], + "build_number": build_number, "languages": languages, "show_language_picker": len(languages.keys()) > 1, "user_is_anonymous": g.user.is_anonymous, From 5e071b4f13a5dcb31510bc9a3021ea6426c6e30b Mon Sep 17 00:00:00 2001 From: cccs-joel Date: Thu, 19 Aug 2021 17:42:49 +0000 Subject: [PATCH 2/3] As per feedback, added a variable in the config with a default value of None, removed try catch block as config values are always defined. --- superset/config.py | 4 ++++ superset/views/base.py | 6 +----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/superset/config.py b/superset/config.py index f18fcca8a863a..65227b0dcb9e0 100644 --- a/superset/config.py +++ b/superset/config.py @@ -119,6 +119,10 @@ def _try_json_readsha( # pylint: disable=unused-argument VERSION_SHA_LENGTH = 8 VERSION_SHA = _try_json_readsha(VERSION_INFO_FILE, VERSION_SHA_LENGTH) +# Build number is shown in the About section if available. This +# can be replaced at build time to expose build information. +BUILD_NUMBER = None + # default viz used in chart explorer DEFAULT_VIZ_TYPE = "table" diff --git a/superset/views/base.py b/superset/views/base.py index ef327a1ddf19f..4e8a1cf94cd77 100644 --- a/superset/views/base.py +++ b/superset/views/base.py @@ -312,11 +312,7 @@ def menu_data() -> Dict[str, Any]: brand_text = appbuilder.app.config["LOGO_RIGHT_TEXT"] if callable(brand_text): brand_text = brand_text() - build_number = "" - try: - build_number = appbuilder.app.config["BUILD_NUMBER"] - except Exception as ex: - logger.debug("BUILD_NUMBER is missing from the config", ex) + build_number = appbuilder.app.config["BUILD_NUMBER"] return { "menu": menu, "brand": { From 1010abe95b7f5e67a0a5d2a415af921098a74957 Mon Sep 17 00:00:00 2001 From: Joel Gregoire Date: Tue, 31 Aug 2021 15:46:18 -0400 Subject: [PATCH 3/3] Removed trailing space, splited long line as requested --- superset-frontend/src/components/Menu/MenuRight.tsx | 4 +++- superset/config.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/components/Menu/MenuRight.tsx b/superset-frontend/src/components/Menu/MenuRight.tsx index a4fe6306f12df..1626713f54283 100644 --- a/superset-frontend/src/components/Menu/MenuRight.tsx +++ b/superset-frontend/src/components/Menu/MenuRight.tsx @@ -146,7 +146,9 @@ const RightMenu = ({ , ]} - {(navbarRight.version_string || navbarRight.version_sha || navbarRight.build_number) && [ + {(navbarRight.version_string || + navbarRight.version_sha || + navbarRight.build_number) && [ ,
diff --git a/superset/config.py b/superset/config.py index 65227b0dcb9e0..a957e57c585c0 100644 --- a/superset/config.py +++ b/superset/config.py @@ -119,7 +119,7 @@ def _try_json_readsha( # pylint: disable=unused-argument VERSION_SHA_LENGTH = 8 VERSION_SHA = _try_json_readsha(VERSION_INFO_FILE, VERSION_SHA_LENGTH) -# Build number is shown in the About section if available. This +# Build number is shown in the About section if available. This # can be replaced at build time to expose build information. BUILD_NUMBER = None