From 443fc2bef8b858ae82bcfe3284d9bba937f0aef5 Mon Sep 17 00:00:00 2001 From: prabhat Date: Thu, 4 Apr 2024 15:32:21 +0100 Subject: [PATCH] upgraded to latest react and react router dom versions --- package.json | 9 +++-- src/index.tsx | 14 ++++--- src/ui/App.tsx | 49 +++++++++--------------- src/ui/layout/DefaultPageContent.tsx | 38 +++--------------- src/ui/pages/search/SearchResultPage.tsx | 4 +- 5 files changed, 39 insertions(+), 75 deletions(-) diff --git a/package.json b/package.json index 50c005e5..ff7fdf53 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "devDependencies": { "@playwright/test": "1.30.0", "@types/file-saver": "2.0.5", - "@types/react-dom": "17.0.2", + "@types/react": "18.2.74", + "@types/react-dom": "18.2.23", "@types/react-router-dom": "5.3.3", "@types/uuid": "^8.3.1", "axios": "1.3.2", @@ -15,10 +16,10 @@ "cra-template-typescript": "1.1.2", "file-saver": "^2.0.5", "pdbe-molstar": "3.1.2", - "react": "17.0.2", - "react-dom": "17.0.2", + "react": "18.2.0", + "react-dom": "18.2.0", "react-dropdown-now": "^6.0.1", - "react-router-dom": "5.3.3", + "react-router-dom": "6.22.3", "react-scripts": "4.0.3", "simple-react-notifications2": "1.2.17", "typescript": "4.9.5", diff --git a/src/index.tsx b/src/index.tsx index aa320f24..a2a2b7de 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,16 +1,18 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import { BrowserRouter } from 'react-router-dom'; +import * as React from "react"; +import { createRoot } from "react-dom/client"; +import { BrowserRouter } from "react-router-dom"; import './styles/index.scss'; import reportWebVitals from './reportWebVitals'; import App from './ui/App'; -ReactDOM.render( +const container = document.getElementById('root'); +if (!container) throw new Error('Failed to find the root element'); +const root = createRoot(container); +root.render( - , - document.getElementById('root') + ); // If you want to start measuring performance in your app, pass a function diff --git a/src/ui/App.tsx b/src/ui/App.tsx index bfe65c3e..b3fe8fca 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -1,5 +1,5 @@ import {useState} from "react"; -import {Redirect, Route, RouteComponentProps, withRouter} from "react-router-dom"; +import {useNavigate, Route, Routes} from "react-router-dom"; import HomePage from "./pages/home/HomePage"; import SearchResultsPage from "./pages/search/SearchResultPage"; import APIErrorPage from "./pages/APIErrorPage"; @@ -18,13 +18,13 @@ import DownloadPage from "./pages/download/DownloadPage"; import HelpPage from "./pages/help/HelpPage"; import {FormData, initialFormData} from "../types/FormData"; -interface AppProps extends RouteComponentProps {} -function App(props: AppProps) { +export default function App() { const [loading, setLoading] = useState(false); const [formData, setFormData] = useState(initialFormData); const [page, setPage] = useState(firstPage(0)); const [searchResults, setSearchResults] = useState([]); + const navigate = useNavigate(); // MappingRecord 3d array -> [][][] list of mappings/genes/isoforms // mappings : [ // ... @@ -143,56 +143,43 @@ function App(props: AppProps) { Notify.err(message.text) } }); - props.history.push(SEARCH); + navigate(SEARCH); }) .catch((err) => { - props.history.push(API_ERROR); + navigate(API_ERROR); console.log(err); }) .finally(() => setLoading(false)); } return ( - <> + ( - - )} - /> + />} /> ( - - )} - /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - - - - - + />} /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + ); } - -export default withRouter(App); diff --git a/src/ui/layout/DefaultPageContent.tsx b/src/ui/layout/DefaultPageContent.tsx index 46f0b9ef..b9ce84bc 100644 --- a/src/ui/layout/DefaultPageContent.tsx +++ b/src/ui/layout/DefaultPageContent.tsx @@ -1,4 +1,3 @@ -import { useEffect, useState } from 'react' import { NavLink } from 'react-router-dom' import { DOWNLOAD, HOME, SEARCH } from '../../constants/BrowserPaths' import { MappingRecord } from '../../utills/Convertor' @@ -8,48 +7,23 @@ const DefaultPageContent = (props: { downloadCount: number searchResults?: MappingRecord[][][] }) => { - const [enableResults, setEnableResults] = useState(false) const { children, downloadCount, searchResults } = props - useEffect(() => { - if (searchResults?.length) { - setEnableResults(true) - } - }, [searchResults]) - return (
diff --git a/src/ui/pages/search/SearchResultPage.tsx b/src/ui/pages/search/SearchResultPage.tsx index 20a25c2b..6505eac1 100644 --- a/src/ui/pages/search/SearchResultPage.tsx +++ b/src/ui/pages/search/SearchResultPage.tsx @@ -1,7 +1,7 @@ import ResultTable from "../../components/search/ResultTable"; import DefaultPageLayout from "../../layout/DefaultPageLayout"; import PaginationRow from "./PaginationRow"; -import { Redirect } from 'react-router-dom' +import { Navigate } from 'react-router-dom' import { NextPageFun, Page } from "../../../utills/AppHelper"; import { MappingRecord } from "../../../utills/Convertor"; import DownloadModal from "../../modal/DownloadModal"; @@ -27,7 +27,7 @@ function SearchResultsPageContent(props: SearchResultPageProps) { }, [props]); if (!rows || rows.length < 1) - return + return return <>