From 5978be1d4cd49c176c928e2bf5a851107ea32d02 Mon Sep 17 00:00:00 2001
From: reesercollins <10563996+reesercollins@users.noreply.github.com>
Date: Tue, 7 Jun 2022 13:40:02 -0400
Subject: [PATCH 1/9] Added environment tag and relevant tests
---
.../src/views/components/Menu.test.tsx | 13 +++++++++++++
superset-frontend/src/views/components/Menu.tsx | 13 ++++++++++++-
.../src/views/components/MenuRight.tsx | 7 +++++++
superset-frontend/src/views/components/types.ts | 4 ++++
superset/config.py | 14 ++++++++++++++
superset/views/base.py | 8 ++++++++
6 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/superset-frontend/src/views/components/Menu.test.tsx b/superset-frontend/src/views/components/Menu.test.tsx
index a80a43a22f02c..33044c1b3e3a4 100644
--- a/superset-frontend/src/views/components/Menu.test.tsx
+++ b/superset-frontend/src/views/components/Menu.test.tsx
@@ -176,6 +176,10 @@ const mockedProps = {
tooltip: '',
text: '',
},
+ environment_tag: {
+ text: 'Production',
+ color: '#000',
+ },
navbar_right: {
show_watermark: false,
bug_report_url: '/report/',
@@ -270,6 +274,15 @@ test('should render the brand', () => {
expect(image).toHaveAttribute('src', icon);
});
+test('should render the environment tag', () => {
+ useSelectorMock.mockReturnValue({ roles: user.roles });
+ const {
+ data: { environment_tag },
+ } = mockedProps;
+ render(
, { useRedux: true });
+ expect(screen.getByText(environment_tag.text)).toBeInTheDocument();
+});
+
test('should render all the top navbar menu items', () => {
useSelectorMock.mockReturnValue({ roles: user.roles });
const {
diff --git a/superset-frontend/src/views/components/Menu.tsx b/superset-frontend/src/views/components/Menu.tsx
index 3cc61f5243057..86502c5276e59 100644
--- a/superset-frontend/src/views/components/Menu.tsx
+++ b/superset-frontend/src/views/components/Menu.tsx
@@ -62,6 +62,10 @@ export interface MenuProps {
brand: BrandProps;
navbar_right: NavBarProps;
settings: MenuObjectProps[];
+ environment_tag: {
+ text: string;
+ color: string;
+ };
};
isFrontendRoute?: (path?: string) => boolean;
}
@@ -199,7 +203,13 @@ const { SubMenu } = DropdownMenu;
const { useBreakpoint } = Grid;
export function Menu({
- data: { menu, brand, navbar_right: navbarRight, settings },
+ data: {
+ menu,
+ brand,
+ navbar_right: navbarRight,
+ settings,
+ environment_tag: environmentTag,
+ },
isFrontendRoute = () => false,
}: MenuProps) {
const [showMenu, setMenu] = useState('horizontal');
@@ -323,6 +333,7 @@ export function Menu({
settings={settings}
navbarRight={navbarRight}
isFrontendRoute={isFrontendRoute}
+ environmentTag={environmentTag}
/>
diff --git a/superset-frontend/src/views/components/MenuRight.tsx b/superset-frontend/src/views/components/MenuRight.tsx
index 4c34b883491c4..8d7fd2ceaeeec 100644
--- a/superset-frontend/src/views/components/MenuRight.tsx
+++ b/superset-frontend/src/views/components/MenuRight.tsx
@@ -42,6 +42,7 @@ import {
RightMenuProps,
} from './types';
import { MenuObjectProps } from './Menu';
+import { Tag } from 'antd';
const versionInfoStyles = (theme: SupersetTheme) => css`
padding: ${theme.gridUnit * 1.5}px ${theme.gridUnit * 4}px
@@ -86,6 +87,7 @@ const RightMenu = ({
settings,
navbarRight,
isFrontendRoute,
+ environmentTag,
}: RightMenuProps) => {
const user = useSelector(
state => state.user,
@@ -259,6 +261,11 @@ const RightMenu = ({
dbEngine={engine}
/>
)}
+ {environmentTag.text && (
+
+ {environmentTag.text}
+
+ )}