This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new ead10401e7 fix: A newly connected database doesn't appear in the 
databases list if user connected database using the 'plus' button (#20363)
ead10401e7 is described below

commit ead10401e7f5344d821ee3086c191fedb5d6ee4b
Author: Diego Medina <[email protected]>
AuthorDate: Tue Jun 14 20:47:37 2022 -0300

    fix: A newly connected database doesn't appear in the databases list if 
user connected database using the 'plus' button (#20363)
    
    * fix: A newly connected database doesn't appear in the databases list if 
user connected database using the 'plus' button
    
    * PR comments
---
 .../src/views/components/Menu.test.tsx             |  6 +++
 .../src/views/components/MenuRight.tsx             | 50 +++++++++++++++++++---
 2 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/superset-frontend/src/views/components/Menu.test.tsx 
b/superset-frontend/src/views/components/Menu.test.tsx
index 0d84d2c663..31aad0be8a 100644
--- a/superset-frontend/src/views/components/Menu.test.tsx
+++ b/superset-frontend/src/views/components/Menu.test.tsx
@@ -476,3 +476,9 @@ test('should hide create button without proper roles', () 
=> {
   render(<Menu {...mockedProps} />, { useRedux: true, useQueryParams: true });
   expect(screen.queryByTestId('new-dropdown')).not.toBeInTheDocument();
 });
+
+test('should render without QueryParamProvider', () => {
+  useSelectorMock.mockReturnValue({ roles: [] });
+  render(<Menu {...mockedProps} />, { useRedux: true });
+  expect(screen.queryByTestId('new-dropdown')).not.toBeInTheDocument();
+});
diff --git a/superset-frontend/src/views/components/MenuRight.tsx 
b/superset-frontend/src/views/components/MenuRight.tsx
index 61bc6de0d6..36c5dd37fd 100644
--- a/superset-frontend/src/views/components/MenuRight.tsx
+++ b/superset-frontend/src/views/components/MenuRight.tsx
@@ -88,7 +88,10 @@ const RightMenu = ({
   settings,
   navbarRight,
   isFrontendRoute,
-}: RightMenuProps) => {
+  setQuery,
+}: RightMenuProps & {
+  setQuery: ({ databaseAdded }: { databaseAdded: boolean }) => void;
+}) => {
   const user = useSelector<any, UserWithPermissionsAndRoles>(
     state => state.user,
   );
@@ -96,10 +99,6 @@ const RightMenu = ({
     state => state.dashboardInfo?.id,
   );
 
-  const [, setQuery] = useQueryParams({
-    databaseAdded: BooleanParam,
-  });
-
   const { roles } = user;
   const {
     CSV_EXTENSIONS,
@@ -439,4 +438,43 @@ const RightMenu = ({
   );
 };
 
-export default RightMenu;
+const RightMenuWithQueryWrapper: React.FC<RightMenuProps> = props => {
+  const [, setQuery] = useQueryParams({
+    databaseAdded: BooleanParam,
+  });
+
+  return <RightMenu setQuery={setQuery} {...props} />;
+};
+
+// Query param manipulation requires that, during the setup, the
+// QueryParamProvider is present and configured.
+// Superset still has multiple entry points, and not all of them have
+// the same setup, and critically, not all of them have the QueryParamProvider.
+// This wrapper ensures the RightMenu renders regardless of the provider being 
present.
+class RightMenuErrorWrapper extends React.PureComponent<RightMenuProps> {
+  state = {
+    hasError: false,
+  };
+
+  static getDerivedStateFromError() {
+    return { hasError: true };
+  }
+
+  noop = () => {};
+
+  render() {
+    if (this.state.hasError) {
+      return <RightMenu setQuery={this.noop} {...this.props} />;
+    }
+
+    return this.props.children;
+  }
+}
+
+const RightMenuWrapper: React.FC<RightMenuProps> = props => (
+  <RightMenuErrorWrapper {...props}>
+    <RightMenuWithQueryWrapper {...props} />
+  </RightMenuErrorWrapper>
+);
+
+export default RightMenuWrapper;

Reply via email to