This is an automated email from the ASF dual-hosted git repository.
klesh 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 136a191ae refactor(config-ui): use router configuration to replace
App.tsx (#5668)
136a191ae is described below
commit 136a191aef0517c2c7d6f664b2336e1b8126b11e
Author: 青湛 <[email protected]>
AuthorDate: Mon Jul 17 20:56:48 2023 +1200
refactor(config-ui): use router configuration to replace App.tsx (#5668)
---
config-ui/src/App.tsx | 58 ------------------------------
config-ui/src/main.tsx | 12 ++++---
config-ui/src/router.tsx | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 99 insertions(+), 62 deletions(-)
diff --git a/config-ui/src/App.tsx b/config-ui/src/App.tsx
deleted file mode 100644
index e40cc73d1..000000000
--- a/config-ui/src/App.tsx
+++ /dev/null
@@ -1,58 +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 { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
-import { ErrorLayout, BaseLayout } from '@/layouts';
-import {
- OfflinePage,
- DBMigratePage,
- ConnectionHomePage,
- ConnectionDetailPage,
- ProjectHomePage,
- ProjectDetailPage,
- BlueprintHomePage,
- BlueprintDetailPage,
- BlueprintConnectionDetailPage,
-} from '@/pages';
-
-function App() {
- return (
- <BrowserRouter>
- <Routes>
- <Route element={<ErrorLayout />}>
- <Route path="offline" element={<OfflinePage />} />
- <Route path="db-migrate" element={<DBMigratePage />} />
- </Route>
-
- <Route path="/" element={<BaseLayout />}>
- <Route index element={<Navigate to="connections" />} />
- <Route path="connections" element={<ConnectionHomePage />} />
- <Route path="connections/:plugin/:id" element={<ConnectionDetailPage
/>} />
- <Route path="projects" element={<ProjectHomePage />} />
- <Route path="projects/:pname" element={<ProjectDetailPage />} />
- <Route path="projects/:pname/:unique"
element={<BlueprintConnectionDetailPage />} />
- <Route path="blueprints" element={<BlueprintHomePage />} />
- <Route path="blueprints/:id" element={<BlueprintDetailPage />} />
- <Route path="blueprints/:bid/:unique"
element={<BlueprintConnectionDetailPage />} />
- </Route>
- </Routes>
- </BrowserRouter>
- );
-}
-
-export default App;
diff --git a/config-ui/src/main.tsx b/config-ui/src/main.tsx
index 817fa363c..056e37e5b 100644
--- a/config-ui/src/main.tsx
+++ b/config-ui/src/main.tsx
@@ -16,17 +16,21 @@
*
*/
+import React from 'react';
import ReactDOM from 'react-dom';
+import { RouterProvider } from 'react-router-dom';
import { ErrorBoundary } from '@/components';
-import App from './App';
+import { router } from './router';
import './index.css';
ReactDOM.render(
- <ErrorBoundary>
- <App />
- </ErrorBoundary>,
+ <React.StrictMode>
+ <ErrorBoundary>
+ <RouterProvider router={router} />
+ </ErrorBoundary>
+ </React.StrictMode>,
document.getElementById('root'),
);
diff --git a/config-ui/src/router.tsx b/config-ui/src/router.tsx
new file mode 100644
index 000000000..a163d118e
--- /dev/null
+++ b/config-ui/src/router.tsx
@@ -0,0 +1,91 @@
+/*
+ * 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 { createBrowserRouter, Navigate } from 'react-router-dom';
+
+import { ErrorLayout, BaseLayout } from '@/layouts';
+import {
+ OfflinePage,
+ DBMigratePage,
+ ConnectionHomePage,
+ ConnectionDetailPage,
+ ProjectHomePage,
+ ProjectDetailPage,
+ BlueprintHomePage,
+ BlueprintDetailPage,
+ BlueprintConnectionDetailPage,
+} from '@/pages';
+
+export const router = createBrowserRouter([
+ {
+ path: '',
+ element: <ErrorLayout />,
+ children: [
+ {
+ path: 'offline',
+ element: <OfflinePage />,
+ },
+ {
+ path: 'db-migrate',
+ element: <DBMigratePage />,
+ },
+ ],
+ },
+ {
+ path: '/',
+ element: <BaseLayout />,
+ children: [
+ {
+ index: true,
+ element: <Navigate to="connections" />,
+ },
+ {
+ path: 'connections',
+ element: <ConnectionHomePage />,
+ },
+ {
+ path: 'connections/:plugin/:id',
+ element: <ConnectionDetailPage />,
+ },
+ {
+ path: 'projects',
+ element: <ProjectHomePage />,
+ },
+ {
+ path: 'projects/:pname',
+ element: <ProjectDetailPage />,
+ },
+ {
+ path: 'projects/:pname/:unique',
+ element: <BlueprintConnectionDetailPage />,
+ },
+ {
+ path: 'blueprints',
+ element: <BlueprintHomePage />,
+ },
+ {
+ path: 'blueprints/:id',
+ element: <BlueprintDetailPage />,
+ },
+ {
+ path: 'blueprints/:bid/:unique',
+ element: <BlueprintConnectionDetailPage />,
+ },
+ ],
+ },
+]);