You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by li...@apache.org on 2022/12/15 07:17:55 UTC

[incubator-devlake] branch main updated: refactor(config-ui): adjust the entrance for app (#3937)

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 c0ad781d0 refactor(config-ui): adjust the entrance for app (#3937)
c0ad781d0 is described below

commit c0ad781d0cbd0cabd16c5cae47d030c6d590a943
Author: 青湛 <0x...@gmail.com>
AuthorDate: Thu Dec 15 15:17:50 2022 +0800

    refactor(config-ui): adjust the entrance for app (#3937)
    
    * feat(config-ui): add parameter formatMessage for operator
    
    * refactor(config-ui): move the offline page to error
    
    * refactor(config-ui): move the error-handler to error as default
    
    * feat(config-ui): add error db-migrate in error
    
    * feat(config-ui): add endpoint in config
    
    * refactor(config-ui): the error boundary
    
    * feat(config-ui): add global version store
    
    * refactor(config-ui): adjust the entrance for app
---
 config-ui/src/App.js                               | 152 +++++++--------------
 config-ui/src/components/index.ts                  |   1 -
 config-ui/src/components/utils/request.ts          |   2 +-
 config-ui/src/config/{index.ts => endpoint.ts}     |   2 +-
 config-ui/src/config/index.ts                      |   1 +
 .../components/db-migrate}/api.ts                  |   2 +-
 .../src/error/components/db-migrate/index.tsx      |  56 ++++++++
 .../components/db-migrate/use-db-migrate.ts}       |  63 ++++-----
 config-ui/src/error/components/default/index.tsx   |  68 +++++++++
 .../src/{config => error/components}/index.ts      |   5 +-
 .../src/{pages => error/components}/offline/api.ts |   0
 config-ui/src/error/components/offline/index.tsx   | 104 ++++++++++++++
 .../components}/offline/use-offline.ts             |  43 ++++--
 .../index.tsx => error/error-boundary.tsx}         |  31 ++++-
 config-ui/src/{config => error}/index.ts           |   4 +-
 config-ui/src/{pages/offline => error}/styled.ts   |  43 +++---
 config-ui/src/{config/index.ts => error/types.ts}  |   5 +-
 .../src/{pages/offline/api.ts => error/utils.ts}   |  13 +-
 config-ui/src/index.js                             |  17 ++-
 config-ui/src/pages/error-handler/index.tsx        |  68 ---------
 config-ui/src/pages/index.ts                       |   2 -
 config-ui/src/pages/offline/index.tsx              | 110 ---------------
 config-ui/src/store/index.ts                       |   1 +
 .../{hooks/use-version => store/version}/api.ts    |   0
 .../index.tsx => store/version/context.tsx}        |  49 ++++---
 config-ui/src/{config => store/version}/index.ts   |   3 +-
 .../src/{hooks/index.ts => store/version/types.ts} |   2 +-
 .../version/use-context-value.ts}                  |  22 ++-
 config-ui/src/utils/operator.ts                    |  21 +--
 29 files changed, 473 insertions(+), 417 deletions(-)

diff --git a/config-ui/src/App.js b/config-ui/src/App.js
index 3357f47d9..2cf626341 100644
--- a/config-ui/src/App.js
+++ b/config-ui/src/App.js
@@ -17,28 +17,15 @@
  */
 
 import React from 'react'
-import {
-  BrowserRouter as Router,
-  Route,
-  Switch,
-  Redirect
-} from 'react-router-dom'
+import { Switch, Route, Redirect } from 'react-router-dom'
 
-import 'normalize.css'
 import '@/styles/app.scss'
-// import 'typeface-montserrat'
-// import 'jetbrains-mono'
 import '@fontsource/inter/400.css'
 import '@fontsource/inter/600.css'
 import '@fontsource/inter/variable-full.css'
-// Theme variables (@styles/theme.scss) injected via Webpack w/ @sass-loader additionalData option!
-// import '@/styles/theme.scss'
-import useDatabaseMigrations from '@/hooks/useDatabaseMigrations'
 
-import { useVersion } from '@/hooks'
 import { BaseLayout } from '@/layouts'
 import {
-  Offline,
   ProjectHomePage,
   ProjectDetailPage,
   CreateBlueprintPage,
@@ -50,99 +37,54 @@ import ManageIntegration from '@/pages/configure/integration/manage'
 import AddConnection from '@/pages/configure/connections/AddConnection'
 import ConfigureConnection from '@/pages/configure/connections/ConfigureConnection'
 import Blueprints from '@/pages/blueprints/index'
-import CreateBlueprint from '@/pages/blueprints/create-blueprint'
-import BlueprintDetail from '@/pages/blueprints/blueprint-detail'
-import BlueprintSettings from '@/pages/blueprints/blueprint-settings'
-import { IncomingWebhook as IncomingWebhookConnection } from '@/pages/connections/incoming-webhook'
-import MigrationAlertDialog from '@/components/MigrationAlertDialog'
-
-function App(props) {
-  const {
-    isProcessing,
-    migrationWarning,
-    migrationAlertOpened,
-    wasMigrationSuccessful,
-    hasMigrationFailed,
-    handleConfirmMigration,
-    handleCancelMigration,
-    handleMigrationDialogClose
-  } = useDatabaseMigrations()
-
-  useVersion()
 
+function App() {
   return (
-    <Switch>
-      <Route exact path='/offline' component={() => <Offline />} />
-
-      <Route>
-        <BaseLayout>
-          <Switch>
-            <Route
-              path='/'
-              exact
-              component={() => <Redirect to='/projects' />}
-            />
-            <Route
-              exact
-              path='/projects'
-              component={() => <ProjectHomePage />}
-            />
-            <Route
-              exact
-              path='/projects/:pname'
-              component={() => <ProjectDetailPage />}
-            />
-            <Route
-              exact
-              path='/projects/:pname/create-blueprint'
-              component={() => <CreateBlueprintPage from='project' />}
-            />
-            <Route
-              exact
-              path='/integrations'
-              component={() => <Integration />}
-            />
-            <Route
-              path='/integrations/:providerId'
-              component={() => <ManageIntegration />}
-            />
-            <Route
-              path='/connections/add/:providerId'
-              component={() => <AddConnection />}
-            />
-            <Route
-              path='/connections/configure/:providerId/:connectionId'
-              component={() => <ConfigureConnection />}
-            />
-            <Route
-              exact
-              path='/connections/incoming-webhook'
-              component={() => <WebHookConnectionPage />}
-            />
-            <Route exact path='/blueprints' component={() => <Blueprints />} />
-            <Route
-              exact
-              path='/blueprints/create'
-              component={() => <CreateBlueprintPage from='blueprint' />}
-            />
-            <Route
-              exact
-              path='/blueprints/:id'
-              component={() => <BlueprintDetailPage />}
-            />
-          </Switch>
-          <MigrationAlertDialog
-            isOpen={migrationAlertOpened}
-            onClose={handleMigrationDialogClose}
-            onCancel={handleCancelMigration}
-            onConfirm={handleConfirmMigration}
-            isMigrating={isProcessing}
-            wasSuccessful={wasMigrationSuccessful}
-            hasFailed={hasMigrationFailed}
-          />
-        </BaseLayout>
-      </Route>
-    </Switch>
+    <BaseLayout>
+      <Switch>
+        <Route path='/' exact component={() => <Redirect to='/projects' />} />
+        <Route exact path='/projects' component={() => <ProjectHomePage />} />
+        <Route
+          exact
+          path='/projects/:pname'
+          component={() => <ProjectDetailPage />}
+        />
+        <Route
+          exact
+          path='/projects/:pname/create-blueprint'
+          component={() => <CreateBlueprintPage from='project' />}
+        />
+        <Route exact path='/integrations' component={() => <Integration />} />
+        <Route
+          path='/integrations/:providerId'
+          component={() => <ManageIntegration />}
+        />
+        <Route
+          path='/connections/add/:providerId'
+          component={() => <AddConnection />}
+        />
+        <Route
+          path='/connections/configure/:providerId/:connectionId'
+          component={() => <ConfigureConnection />}
+        />
+        <Route
+          exact
+          path='/connections/incoming-webhook'
+          component={() => <WebHookConnectionPage />}
+        />
+        <Route exact path='/blueprints' component={() => <Blueprints />} />
+        <Route
+          exact
+          path='/blueprints/create'
+          component={() => <CreateBlueprintPage from='blueprint' />}
+        />
+        <Route
+          exact
+          path='/blueprints/:id'
+          component={() => <BlueprintDetailPage />}
+        />
+      </Switch>
+    </BaseLayout>
   )
 }
 
diff --git a/config-ui/src/components/index.ts b/config-ui/src/components/index.ts
index 9744a3aee..90cf931d2 100644
--- a/config-ui/src/components/index.ts
+++ b/config-ui/src/components/index.ts
@@ -25,4 +25,3 @@ export * from './table'
 export * from './toast2'
 export * from './logo'
 export * from './card'
-export * from './error-boundary'
diff --git a/config-ui/src/components/utils/request.ts b/config-ui/src/components/utils/request.ts
index 51e17db17..814ad216c 100644
--- a/config-ui/src/components/utils/request.ts
+++ b/config-ui/src/components/utils/request.ts
@@ -19,7 +19,7 @@
 import type { AxiosRequestConfig } from 'axios'
 import axios from 'axios'
 
-import { DEVLAKE_ENDPOINT } from '@/utils/config'
+import { DEVLAKE_ENDPOINT } from '@/config'
 
 const instance = axios.create({
   baseURL: DEVLAKE_ENDPOINT
diff --git a/config-ui/src/config/index.ts b/config-ui/src/config/endpoint.ts
similarity index 95%
copy from config-ui/src/config/index.ts
copy to config-ui/src/config/endpoint.ts
index 87a9b1d49..dda29950e 100644
--- a/config-ui/src/config/index.ts
+++ b/config-ui/src/config/endpoint.ts
@@ -16,4 +16,4 @@
  *
  */
 
-export * from './cron'
+export const DEVLAKE_ENDPOINT = '/api'
diff --git a/config-ui/src/config/index.ts b/config-ui/src/config/index.ts
index 87a9b1d49..d57ff0a42 100644
--- a/config-ui/src/config/index.ts
+++ b/config-ui/src/config/index.ts
@@ -17,3 +17,4 @@
  */
 
 export * from './cron'
+export * from './endpoint'
diff --git a/config-ui/src/hooks/use-version/api.ts b/config-ui/src/error/components/db-migrate/api.ts
similarity index 93%
copy from config-ui/src/hooks/use-version/api.ts
copy to config-ui/src/error/components/db-migrate/api.ts
index 2ba560578..9938ede4b 100644
--- a/config-ui/src/hooks/use-version/api.ts
+++ b/config-ui/src/error/components/db-migrate/api.ts
@@ -18,4 +18,4 @@
 
 import request from '@/components/utils/request'
 
-export const getVersion = () => request('/version')
+export const migrate = () => request('/proceed-db-migration')
diff --git a/config-ui/src/error/components/db-migrate/index.tsx b/config-ui/src/error/components/db-migrate/index.tsx
new file mode 100644
index 000000000..e6eecf4e8
--- /dev/null
+++ b/config-ui/src/error/components/db-migrate/index.tsx
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+import React from 'react'
+import { Icon, ButtonGroup, Button, Colors, Intent } from '@blueprintjs/core'
+
+import { Card } from '@/components'
+
+import type { UseDBMigrateProps } from './use-db-migrate'
+import { useDBMigrate } from './use-db-migrate'
+
+interface Props extends UseDBMigrateProps {}
+
+export const DBMigrate = ({ ...props }: Props) => {
+  const { processing, onSubmit } = useDBMigrate({ ...props })
+
+  return (
+    <Card>
+      <h2>
+        <Icon icon='outdated' color={Colors.ORANGE5} size={20} />
+        <span>New Migration Scripts Detected</span>
+      </h2>
+      <p>
+        If you have already started, please wait for database migrations to
+        complete, do <strong>NOT</strong> close your browser at this time.
+      </p>
+      <p className='warning'>
+        Warning: Performing migration may wipe collected data for consistency
+        and re-collecting data may be required.
+      </p>
+      <ButtonGroup>
+        <Button
+          loading={processing}
+          text='Proceed to Database Migration'
+          intent={Intent.PRIMARY}
+          onClick={onSubmit}
+        />
+      </ButtonGroup>
+    </Card>
+  )
+}
diff --git a/config-ui/src/pages/error-handler/styled.ts b/config-ui/src/error/components/db-migrate/use-db-migrate.ts
similarity index 54%
rename from config-ui/src/pages/error-handler/styled.ts
rename to config-ui/src/error/components/db-migrate/use-db-migrate.ts
index 94bbaa5aa..6485c04eb 100644
--- a/config-ui/src/pages/error-handler/styled.ts
+++ b/config-ui/src/error/components/db-migrate/use-db-migrate.ts
@@ -13,40 +13,41 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
+ *
  */
 
-import styled from 'styled-components'
-
-export const Wrapper = styled.div`
-  display: flex;
-  flex-direction: column;
-  align-items: center;
-  padding-top: 100px;
-  height: 100vh;
-  background-color: #f9f9fa;
-  box-sizing: border-box;
-
-  .inner {
-    margin: 32px auto 0;
-    width: 640px;
-
-    h2 {
-      display: flex;
-      align-items: center;
-      margin: 0;
-
-      .bp4-icon {
-        margin-right: 4px;
-      }
-    }
+import { useState, useMemo } from 'react'
+import { useHistory } from 'react-router-dom'
 
-    p {
-      margin: 16px 0;
-    }
+import { operator } from '@/utils'
+
+import * as API from './api'
+
+export interface UseDBMigrateProps {
+  onResetError: () => void
+}
 
-    .bp4-button-group {
-      display: flex;
-      justify-content: center;
+export const useDBMigrate = ({ onResetError }: UseDBMigrateProps) => {
+  const [processing, setProcessing] = useState(false)
+
+  const history = useHistory()
+
+  const handleSubmit = async () => {
+    const [success] = await operator(() => API.migrate(), {
+      setOperating: setProcessing
+    })
+
+    if (success) {
+      onResetError()
+      history.push('/')
     }
   }
-`
+
+  return useMemo(
+    () => ({
+      processing,
+      onSubmit: handleSubmit
+    }),
+    [processing]
+  )
+}
diff --git a/config-ui/src/error/components/default/index.tsx b/config-ui/src/error/components/default/index.tsx
new file mode 100644
index 000000000..4b4d73cb3
--- /dev/null
+++ b/config-ui/src/error/components/default/index.tsx
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import React from 'react'
+import { useHistory } from 'react-router-dom'
+import { Icon, ButtonGroup, Button, Intent, Colors } from '@blueprintjs/core'
+
+import { Card } from '@/components'
+
+interface Props {
+  error: any
+  onResetError: () => void
+}
+
+export const Default = ({ error, onResetError }: Props) => {
+  const history = useHistory()
+
+  const handleContinue = () => {
+    onResetError()
+    history.push('/')
+  }
+
+  return (
+    <Card>
+      <h2>
+        <Icon icon='error' color={Colors.RED5} size={20} />
+        <span>{error?.toString() || 'Unknown Error'}</span>
+      </h2>
+      <p>
+        Please try again, if the problem persists include the above error
+        message when filing a bug report on <strong>GitHub</strong>. You can
+        also message us on <strong>Slack</strong> to engage with community
+        members for solutions to common issues.
+      </p>
+      <ButtonGroup>
+        <Button
+          text='Continue'
+          intent={Intent.PRIMARY}
+          onClick={handleContinue}
+        />
+        <Button
+          text='Visit GitHub'
+          onClick={() =>
+            window.open(
+              'https://github.com/apache/incubator-devlake',
+              '_blank',
+              'noopener,noreferrer'
+            )
+          }
+        />
+      </ButtonGroup>
+    </Card>
+  )
+}
diff --git a/config-ui/src/config/index.ts b/config-ui/src/error/components/index.ts
similarity index 90%
copy from config-ui/src/config/index.ts
copy to config-ui/src/error/components/index.ts
index 87a9b1d49..6fd9487cb 100644
--- a/config-ui/src/config/index.ts
+++ b/config-ui/src/error/components/index.ts
@@ -13,7 +13,8 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- *
  */
 
-export * from './cron'
+export * from './db-migrate'
+export * from './offline'
+export * from './default'
diff --git a/config-ui/src/pages/offline/api.ts b/config-ui/src/error/components/offline/api.ts
similarity index 100%
copy from config-ui/src/pages/offline/api.ts
copy to config-ui/src/error/components/offline/api.ts
diff --git a/config-ui/src/error/components/offline/index.tsx b/config-ui/src/error/components/offline/index.tsx
new file mode 100644
index 000000000..f3e6aa1ee
--- /dev/null
+++ b/config-ui/src/error/components/offline/index.tsx
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+import React, { useMemo } from 'react'
+import {
+  Icon,
+  Tag,
+  ButtonGroup,
+  Button,
+  Intent,
+  Colors,
+  IconName
+} from '@blueprintjs/core'
+
+import { Card } from '@/components'
+import { DEVLAKE_ENDPOINT } from '@/config'
+
+import type { UseOfflineProps } from './use-offline'
+import { useOffline } from './use-offline'
+
+interface Props extends UseOfflineProps {}
+
+export const Offline = ({ ...props }: Props) => {
+  const { processing, offline, onRefresh, onContinue } = useOffline({
+    ...props
+  })
+
+  const [icon, color, text] = useMemo(
+    () => [
+      offline ? 'offline' : 'endorsed',
+      offline ? Colors.RED3 : Colors.GREEN3,
+      offline ? 'Offline' : 'Online'
+    ],
+    [offline]
+  )
+
+  return (
+    <Card>
+      <h2>
+        <Icon icon={icon as IconName} color={color} size={30} />
+        <span>DevLake API</span>
+        <strong style={{ marginLeft: 4, color }}>{text}</strong>
+      </h2>
+      <p>
+        <Tag>DEVLAKE_ENDPOINT: {DEVLAKE_ENDPOINT}</Tag>
+      </p>
+      {offline ? (
+        <>
+          <p>
+            Please wait for the&nbsp;
+            <strong>Lake API</strong> to start before accessing the{' '}
+            <strong>Configuration Interface</strong>.
+          </p>
+          <ButtonGroup>
+            <Button
+              loading={processing}
+              icon='refresh'
+              intent={Intent.PRIMARY}
+              text='Refresh'
+              onClick={onRefresh}
+            />
+          </ButtonGroup>
+        </>
+      ) : (
+        <>
+          <p>Connectivity to the Lake API service was successful.</p>
+          <ButtonGroup>
+            <Button
+              intent={Intent.PRIMARY}
+              text='Continue'
+              onClick={onContinue}
+            />
+            <Button
+              icon='help'
+              text='Read Documentation'
+              onClick={() =>
+                window.open(
+                  'https://github.com/apache/incubator-devlake/blob/main/README.md',
+                  '_blank',
+                  'noopener,noreferrer'
+                )
+              }
+            />
+          </ButtonGroup>
+        </>
+      )}
+    </Card>
+  )
+}
diff --git a/config-ui/src/pages/offline/use-offline.ts b/config-ui/src/error/components/offline/use-offline.ts
similarity index 68%
rename from config-ui/src/pages/offline/use-offline.ts
rename to config-ui/src/error/components/offline/use-offline.ts
index 56f86ed79..2c660109c 100644
--- a/config-ui/src/pages/offline/use-offline.ts
+++ b/config-ui/src/error/components/offline/use-offline.ts
@@ -17,31 +17,40 @@
  */
 
 import { useState, useEffect, useMemo, useRef } from 'react'
+import { useHistory } from 'react-router-dom'
+
+import { operator } from '@/utils'
 
 import * as API from './api'
 
 const pollTimer = 10000
 const retryLimit = 10
 
-export const useOffline = () => {
-  const [loading, setLoading] = useState(false)
+export interface UseOfflineProps {
+  onResetError: () => void
+}
+
+export const useOffline = ({ onResetError }: UseOfflineProps) => {
+  const [processing, setProcessing] = useState(false)
   const [offline, setOffline] = useState(true)
 
+  const history = useHistory()
+
   const timer = useRef<any>()
   const retryCount = useRef<number>(0)
 
   const ping = async (auto = true) => {
-    setLoading(true)
-    try {
-      await API.ping()
+    const [success] = await operator(() => API.ping(), {
+      setOperating: setProcessing,
+      formatReason: () => 'Attempt to connect to the API failed'
+    })
+
+    if (success) {
       setOffline(false)
-    } catch {
-      setOffline(true)
-    } finally {
-      if (auto) {
-        retryCount.current += 1
-      }
-      setLoading(false)
+    }
+
+    if (auto) {
+      retryCount.current += 1
     }
   }
 
@@ -60,10 +69,14 @@ export const useOffline = () => {
 
   return useMemo(
     () => ({
-      loading,
+      processing,
       offline,
-      onRefresh: () => ping(false)
+      onRefresh: () => ping(false),
+      onContinue: () => {
+        onResetError()
+        history.push('/')
+      }
     }),
-    [loading, offline]
+    [processing, offline]
   )
 }
diff --git a/config-ui/src/components/error-boundary/index.tsx b/config-ui/src/error/error-boundary.tsx
similarity index 63%
copy from config-ui/src/components/error-boundary/index.tsx
copy to config-ui/src/error/error-boundary.tsx
index eccc25e1f..27afe1a08 100644
--- a/config-ui/src/components/error-boundary/index.tsx
+++ b/config-ui/src/error/error-boundary.tsx
@@ -17,7 +17,12 @@
 
 import React from 'react'
 
-import { ErrorHandler } from '@/pages'
+import { Logo } from '@/components'
+
+import { Error } from './types'
+import { DBMigrate, Offline, Default } from './components'
+
+import * as S from './styled'
 
 type Props = {
   children: React.ReactNode
@@ -41,6 +46,13 @@ export class ErrorBoundary extends React.Component<Props, State> {
     }
   }
 
+  handleResetError = () => {
+    this.setState({
+      hasError: false,
+      error: undefined
+    })
+  }
+
   render() {
     const { hasError, error } = this.state
 
@@ -48,6 +60,21 @@ export class ErrorBoundary extends React.Component<Props, State> {
       return this.props.children
     }
 
-    return <ErrorHandler error={error} />
+    return (
+      <S.Wrapper>
+        <Logo />
+        <S.Inner>
+          {error === Error.DB_NEED_MIGRATE && (
+            <DBMigrate onResetError={this.handleResetError} />
+          )}
+          {error === Error.API_OFFLINE && (
+            <Offline onResetError={this.handleResetError} />
+          )}
+          {!Object.keys(Error).includes(error) && (
+            <Default error={error} onResetError={this.handleResetError} />
+          )}
+        </S.Inner>
+      </S.Wrapper>
+    )
   }
 }
diff --git a/config-ui/src/config/index.ts b/config-ui/src/error/index.ts
similarity index 90%
copy from config-ui/src/config/index.ts
copy to config-ui/src/error/index.ts
index 87a9b1d49..038fd12db 100644
--- a/config-ui/src/config/index.ts
+++ b/config-ui/src/error/index.ts
@@ -16,4 +16,6 @@
  *
  */
 
-export * from './cron'
+export * from './types'
+export * from './utils'
+export * from './error-boundary'
diff --git a/config-ui/src/pages/offline/styled.ts b/config-ui/src/error/styled.ts
similarity index 73%
rename from config-ui/src/pages/offline/styled.ts
rename to config-ui/src/error/styled.ts
index b6d2724db..e415c2893 100644
--- a/config-ui/src/pages/offline/styled.ts
+++ b/config-ui/src/error/styled.ts
@@ -13,10 +13,10 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- *
  */
 
 import styled from 'styled-components'
+import { Colors } from '@blueprintjs/core'
 
 export const Wrapper = styled.div`
   display: flex;
@@ -26,33 +26,32 @@ export const Wrapper = styled.div`
   height: 100vh;
   background-color: #f9f9fa;
   box-sizing: border-box;
+`
 
-  .inner {
-    margin: 32px auto 0;
-    width: 640px;
-    text-align: center;
-
-    h2 {
-      display: flex;
-      align-items: center;
-      justify-content: center;
-      margin: 0;
+export const Inner = styled.div`
+  margin: 32px auto 0;
+  width: 640px;
 
-      .bp4-icon {
-        margin-right: 4px;
-      }
+  h2 {
+    display: flex;
+    align-items: center;
+    margin: 0;
 
-      strong {
-        margin-left: 4px;
-      }
+    .bp4-icon {
+      margin-right: 4px;
     }
+  }
 
-    .path {
-      margin: 8px 0;
-    }
+  p {
+    margin: 16px 0;
 
-    p {
-      margin: 0 0 16px 0;
+    &.warning {
+      color: ${Colors.ORANGE5};
     }
   }
+
+  .bp4-button-group {
+    display: flex;
+    justify-content: center;
+  }
 `
diff --git a/config-ui/src/config/index.ts b/config-ui/src/error/types.ts
similarity index 89%
copy from config-ui/src/config/index.ts
copy to config-ui/src/error/types.ts
index 87a9b1d49..66a83f2c4 100644
--- a/config-ui/src/config/index.ts
+++ b/config-ui/src/error/types.ts
@@ -16,4 +16,7 @@
  *
  */
 
-export * from './cron'
+export enum Error {
+  API_OFFLINE = 'API_OFFLINE',
+  DB_NEED_MIGRATE = 'DB_NEED_MIGRATE'
+}
diff --git a/config-ui/src/pages/offline/api.ts b/config-ui/src/error/utils.ts
similarity index 76%
rename from config-ui/src/pages/offline/api.ts
rename to config-ui/src/error/utils.ts
index c18ed2044..ead78df09 100644
--- a/config-ui/src/pages/offline/api.ts
+++ b/config-ui/src/error/utils.ts
@@ -16,6 +16,15 @@
  *
  */
 
-import request from '@/components/utils/request'
+import { Error } from './types'
 
-export const ping = () => request('/ping')
+export const transformError = (error: any) => {
+  switch (error?.response?.status) {
+    case 428:
+      return Error.DB_NEED_MIGRATE
+    case 504:
+      return Error.API_OFFLINE
+    default:
+      return error
+  }
+}
diff --git a/config-ui/src/index.js b/config-ui/src/index.js
index 93b76d0be..958ba44f9 100644
--- a/config-ui/src/index.js
+++ b/config-ui/src/index.js
@@ -18,9 +18,10 @@
 
 import React from 'react'
 import ReactDOM from 'react-dom'
-import { BrowserRouter as Router } from 'react-router-dom'
+import { BrowserRouter } from 'react-router-dom'
 
-import { ErrorBoundary } from '@/components'
+import { ErrorBoundary } from '@/error'
+import { VersionContextProvider } from '@/store'
 
 import App from './App'
 import { UIContextProvider } from '@/store/UIContext'
@@ -31,11 +32,13 @@ import './index.css'
 ReactDOM.render(
   <UIContextProvider>
     <IntegrationsContextProvider>
-      <ErrorBoundary>
-        <Router>
-          <App />
-        </Router>
-      </ErrorBoundary>
+      <BrowserRouter>
+        <ErrorBoundary>
+          <VersionContextProvider>
+            <App />
+          </VersionContextProvider>
+        </ErrorBoundary>
+      </BrowserRouter>
     </IntegrationsContextProvider>
   </UIContextProvider>,
   document.getElementById('app')
diff --git a/config-ui/src/pages/error-handler/index.tsx b/config-ui/src/pages/error-handler/index.tsx
deleted file mode 100644
index e1d95e0cb..000000000
--- a/config-ui/src/pages/error-handler/index.tsx
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import React from 'react'
-import type { RouteComponentProps } from 'react-router-dom'
-import { useHistory } from 'react-router-dom'
-import { Icon, ButtonGroup, Button, Intent, Colors } from '@blueprintjs/core'
-
-import { Logo, Card } from '@/components'
-
-import * as S from './styled'
-
-interface Props {
-  error: any
-}
-
-export const ErrorHandler = ({ error }: Props) => {
-  const history = useHistory()
-
-  return (
-    <S.Wrapper>
-      <Logo />
-      <Card className='inner'>
-        <h2>
-          <Icon icon='error' color={Colors.RED5} size={20} />
-          <span>{error?.toString() || 'Unknown Error'}</span>
-        </h2>
-        <p>
-          Please try again, if the problem persists include the above error
-          message when filing a bug report on <strong>GitHub</strong>. You can
-          also message us on <strong>Slack</strong> to engage with community
-          members for solutions to common issues.
-        </p>
-        <ButtonGroup>
-          <Button
-            text='Continue'
-            intent={Intent.PRIMARY}
-            onClick={() => history.push('/')}
-          />
-          <Button
-            text='Visit GitHub'
-            onClick={() =>
-              window.open(
-                'https://github.com/apache/incubator-devlake',
-                '_blank',
-                'noopener,noreferrer'
-              )
-            }
-          />
-        </ButtonGroup>
-      </Card>
-    </S.Wrapper>
-  )
-}
diff --git a/config-ui/src/pages/index.ts b/config-ui/src/pages/index.ts
index 8cb2e4380..89e794d51 100644
--- a/config-ui/src/pages/index.ts
+++ b/config-ui/src/pages/index.ts
@@ -16,8 +16,6 @@
  *
  */
 
-export * from './error-handler'
-export * from './offline'
 export * from './project'
 export * from './blueprint'
 export * from './connections'
diff --git a/config-ui/src/pages/offline/index.tsx b/config-ui/src/pages/offline/index.tsx
deleted file mode 100644
index 221618f6a..000000000
--- a/config-ui/src/pages/offline/index.tsx
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-import React, { useMemo } from 'react'
-import { useHistory } from 'react-router-dom'
-import {
-  Icon,
-  Tag,
-  ButtonGroup,
-  Button,
-  Intent,
-  Colors,
-  IconName
-} from '@blueprintjs/core'
-
-import { Logo, Card, Loading } from '@/components'
-import { DEVLAKE_ENDPOINT } from '@/utils/config'
-
-import { useOffline } from './use-offline'
-import * as S from './styled'
-
-export const Offline = () => {
-  const history = useHistory()
-  const { loading, offline, onRefresh } = useOffline()
-
-  const [icon, color, text] = useMemo(
-    () => [
-      offline ? 'offline' : 'endorsed',
-      offline ? Colors.RED3 : Colors.GREEN3,
-      offline ? 'Offline' : 'Online'
-    ],
-    [offline]
-  )
-
-  return (
-    <S.Wrapper>
-      <Logo />
-      <Card className='inner'>
-        {loading ? (
-          <Loading />
-        ) : (
-          <>
-            <h2>
-              <Icon icon={icon as IconName} color={color} size={30} />
-              <span>DevLake API</span>
-              <strong style={{ color }}>{text}</strong>
-            </h2>
-            <div className='path'>
-              <Tag>DEVLAKE_ENDPOINT: {DEVLAKE_ENDPOINT}</Tag>
-            </div>
-            {offline ? (
-              <>
-                <p>
-                  Please wait for the&nbsp;
-                  <strong>Lake API</strong> to start before accessing the{' '}
-                  <strong>Configuration Interface</strong>.
-                </p>
-                <ButtonGroup>
-                  <Button
-                    icon='refresh'
-                    intent={Intent.PRIMARY}
-                    text='Refresh'
-                    onClick={onRefresh}
-                  />
-                </ButtonGroup>
-              </>
-            ) : (
-              <>
-                <p>Connectivity to the Lake API service was successful.</p>
-                <ButtonGroup>
-                  <Button
-                    intent={Intent.PRIMARY}
-                    text='Continue'
-                    onClick={() => history.push('/')}
-                  />
-                  <Button
-                    icon='help'
-                    text='Read Documentation'
-                    onClick={() =>
-                      window.open(
-                        'https://github.com/apache/incubator-devlake/blob/main/README.md',
-                        '_blank',
-                        'noopener,noreferrer'
-                      )
-                    }
-                  />
-                </ButtonGroup>
-              </>
-            )}
-          </>
-        )}
-      </Card>
-    </S.Wrapper>
-  )
-}
diff --git a/config-ui/src/store/index.ts b/config-ui/src/store/index.ts
index 839be970a..6199fc0b7 100644
--- a/config-ui/src/store/index.ts
+++ b/config-ui/src/store/index.ts
@@ -17,3 +17,4 @@
  */
 
 export * from './connections'
+export * from './version'
diff --git a/config-ui/src/hooks/use-version/api.ts b/config-ui/src/store/version/api.ts
similarity index 100%
rename from config-ui/src/hooks/use-version/api.ts
rename to config-ui/src/store/version/api.ts
diff --git a/config-ui/src/components/error-boundary/index.tsx b/config-ui/src/store/version/context.tsx
similarity index 53%
rename from config-ui/src/components/error-boundary/index.tsx
rename to config-ui/src/store/version/context.tsx
index eccc25e1f..4bdafce4c 100644
--- a/config-ui/src/components/error-boundary/index.tsx
+++ b/config-ui/src/store/version/context.tsx
@@ -13,41 +13,38 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
+ *
  */
 
-import React from 'react'
+import React, { useContext } from 'react'
 
-import { ErrorHandler } from '@/pages'
+import { PageLoading } from '@/components'
 
-type Props = {
-  children: React.ReactNode
-}
+import type { VersionType } from './types'
+import { useContextValue } from './use-context-value'
 
-type State = {
-  hasError: boolean
-  error?: any
+const VersionContext = React.createContext<{
+  version?: VersionType
+}>({})
+
+interface Props {
+  children?: React.ReactNode
 }
 
-export class ErrorBoundary extends React.Component<Props, State> {
-  constructor(props: Props) {
-    super(props)
-    this.state = { hasError: false }
-  }
+export const VersionContextProvider = ({ children }: Props) => {
+  const { loading, version } = useContextValue()
 
-  static getDerivedStateFromError(error: any) {
-    return {
-      hasError: true,
-      error
-    }
+  if (loading) {
+    return <PageLoading />
   }
 
-  render() {
-    const { hasError, error } = this.state
+  return (
+    <VersionContext.Provider value={{ version }}>
+      {children}
+    </VersionContext.Provider>
+  )
+}
 
-    if (!hasError) {
-      return this.props.children
-    }
+export const VersionContextConsumer = VersionContext.Consumer
 
-    return <ErrorHandler error={error} />
-  }
-}
+export const useVersion = () => useContext(VersionContext)
diff --git a/config-ui/src/config/index.ts b/config-ui/src/store/version/index.ts
similarity index 94%
copy from config-ui/src/config/index.ts
copy to config-ui/src/store/version/index.ts
index 87a9b1d49..5f25db57c 100644
--- a/config-ui/src/config/index.ts
+++ b/config-ui/src/store/version/index.ts
@@ -16,4 +16,5 @@
  *
  */
 
-export * from './cron'
+export * from './types'
+export * from './context'
diff --git a/config-ui/src/hooks/index.ts b/config-ui/src/store/version/types.ts
similarity index 96%
rename from config-ui/src/hooks/index.ts
rename to config-ui/src/store/version/types.ts
index c22852abd..de8c5a47c 100644
--- a/config-ui/src/hooks/index.ts
+++ b/config-ui/src/store/version/types.ts
@@ -16,4 +16,4 @@
  *
  */
 
-export * from './use-version'
+export type VersionType = string
diff --git a/config-ui/src/hooks/use-version/index.ts b/config-ui/src/store/version/use-context-value.ts
similarity index 68%
rename from config-ui/src/hooks/use-version/index.ts
rename to config-ui/src/store/version/use-context-value.ts
index 2b35a1b35..69af79a9b 100644
--- a/config-ui/src/hooks/use-version/index.ts
+++ b/config-ui/src/store/version/use-context-value.ts
@@ -17,20 +17,28 @@
  */
 
 import { useState, useEffect, useMemo } from 'react'
-import { useHistory } from 'react-router-dom'
 
+import { transformError } from '@/error'
+
+import type { VersionType } from './types'
 import * as API from './api'
 
-export const useVersion = () => {
-  const [version, setVersion] = useState()
-  const history = useHistory()
+export const useContextValue = () => {
+  const [loading, setLoading] = useState(true)
+  const [version, setVersion] = useState<VersionType>()
+  const [, setError] = useState<any>()
 
   const getVersion = async () => {
+    setLoading(true)
     try {
       const res = await API.getVersion()
       setVersion(res.version)
-    } catch {
-      history.push('/offline')
+    } catch (err) {
+      setError(() => {
+        throw transformError(err)
+      })
+    } finally {
+      setLoading(false)
     }
   }
 
@@ -38,5 +46,5 @@ export const useVersion = () => {
     getVersion()
   }, [])
 
-  return useMemo(() => version, [version])
+  return useMemo(() => ({ loading, version }), [loading, version])
 }
diff --git a/config-ui/src/utils/operator.ts b/config-ui/src/utils/operator.ts
index 611052190..040e8d78f 100644
--- a/config-ui/src/utils/operator.ts
+++ b/config-ui/src/utils/operator.ts
@@ -22,39 +22,40 @@ import { Toast } from '@/components'
 
 export type OperateConfig = {
   setOperating?: (success: boolean) => void
+  formatMessage?: () => string
   formatReason?: (err: unknown) => string
 }
 
 /**
- * 
+ *
  * @param request -> a request
- * @param config 
+ * @param config
  * @param config.setOperating -> Control the status of the request
- * @parma config.formatReason -> Show the reason for the failure
- * @returns 
+ * @param config.formatMessage -> Show the message for the success
+ * @param config.formatReason -> Show the reason for the failure
+ * @returns
  */
 export const operator = async <T>(
   request: () => Promise<T>,
   config?: OperateConfig
 ) => {
-  const { setOperating, formatReason } = config || {}
+  const { setOperating, formatMessage, formatReason } = config || {}
 
   try {
     setOperating?.(true)
     const res = await request()
+    const message = formatMessage?.() ?? 'Operation successfully completed'
     Toast.show({
       intent: Intent.SUCCESS,
-      message: 'Operation successfully completed',
+      message,
       icon: 'endorsed'
     })
     return [true, res]
   } catch (err) {
-    const reason = formatReason?.(err)
+    const reason = formatReason?.(err) ?? 'Operation failed.'
     Toast.show({
       intent: Intent.DANGER,
-      message: reason
-        ? `Operation failed. Reason: ${reason}`
-        : 'Operation failed.',
+      message: reason,
       icon: 'error'
     })