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

likyh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new e3329e981 fix(config-ui): remove redirect offline when api throw a 
error (#5546)
e3329e981 is described below

commit e3329e98158cd8fcdb51c8d949ef189b29e5d767
Author: 青湛 <[email protected]>
AuthorDate: Wed Jun 21 13:57:38 2023 +0800

    fix(config-ui): remove redirect offline when api throw a error (#5546)
---
 config-ui/src/layouts/base/base.tsx | 29 ++++++++++++++++++-----------
 config-ui/src/utils/request.ts      |  4 ----
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/config-ui/src/layouts/base/base.tsx 
b/config-ui/src/layouts/base/base.tsx
index f1cc1ac77..0d7f74ffa 100644
--- a/config-ui/src/layouts/base/base.tsx
+++ b/config-ui/src/layouts/base/base.tsx
@@ -17,14 +17,13 @@
  */
 
 import { useState, useEffect, useRef } from 'react';
-import { useLocation } from 'react-router-dom';
+import { useHistory, useLocation } from 'react-router-dom';
 import { CSSTransition } from 'react-transition-group';
 import { Menu, MenuItem, Navbar, Alignment } from '@blueprintjs/core';
 
 import { PageLoading, Logo, ExternalLink, IconButton } from '@/components';
 import { useTips, useRefreshData } from '@/hooks';
 import { TipsContextProvider, ConnectionContextProvider } from '@/store';
-import { history } from '@/utils/history';
 
 import DashboardIcon from '@/images/icons/dashborad.svg';
 import FileIcon from '@/images/icons/file.svg';
@@ -42,20 +41,32 @@ interface Props {
 }
 
 export const BaseLayout = ({ children }: Props) => {
+  const history = useHistory();
+  const { ready, data, error } = useRefreshData<{ version: string }>(() => 
API.getVersion(), []);
+
+  if (error) {
+    history.push('/offline');
+  }
+
+  if (!ready || !data) {
+    return <PageLoading />;
+  }
+
   return (
     <TipsContextProvider>
       <ConnectionContextProvider>
-        <Layout>{children}</Layout>
+        <Layout version={data.version}>{children}</Layout>
       </ConnectionContextProvider>
     </TipsContextProvider>
   );
 };
 
-export const Layout = ({ children }: Props) => {
-  const menu = useMenu();
+const Layout = ({ version, children }: Props & { version: string }) => {
+  const history = useHistory();
   const { pathname } = useLocation();
+
+  const menu = useMenu();
   const { tips, setTips } = useTips();
-  const { ready, data } = useRefreshData<{ version: string }>(() => 
API.getVersion(), []);
 
   const [userInfo, setUserInfo] = useState<API.UserInfo | null>(null);
 
@@ -80,10 +91,6 @@ export const Layout = ({ children }: Props) => {
     return import.meta.env.DEV ? `${protocol}//${hostname}:3002${suffix}` : 
`/grafana${suffix}`;
   };
 
-  if (!ready || !data) {
-    return <PageLoading />;
-  }
-
   return (
     <S.Wrapper>
       <S.Sider>
@@ -122,7 +129,7 @@ export const Layout = ({ children }: Props) => {
         </Menu>
         <div className="copyright">
           <div>Apache 2.0 License</div>
-          <div className="version">{data.version}</div>
+          <div className="version">{version}</div>
         </div>
       </S.Sider>
       <S.Main>
diff --git a/config-ui/src/utils/request.ts b/config-ui/src/utils/request.ts
index dc76d4495..2098741dc 100644
--- a/config-ui/src/utils/request.ts
+++ b/config-ui/src/utils/request.ts
@@ -35,10 +35,6 @@ instance.interceptors.response.use(
       history.push('/db-migrate');
     }
 
-    if (status === 500) {
-      history.push('/offline');
-    }
-
     return Promise.reject(error);
   },
 );

Reply via email to