Skip to content

Commit

Permalink
fix(config-ui): remove redirect offline when api throw a error (apach…
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsweet authored Jun 21, 2023
1 parent aa25007 commit e3329e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
29 changes: 18 additions & 11 deletions config-ui/src/layouts/base/base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);

Expand All @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
4 changes: 0 additions & 4 deletions config-ui/src/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ instance.interceptors.response.use(
history.push('/db-migrate');
}

if (status === 500) {
history.push('/offline');
}

return Promise.reject(error);
},
);
Expand Down

0 comments on commit e3329e9

Please sign in to comment.