Skip to content

Commit

Permalink
Merge pull request #200 from MetaCell/develop
Browse files Browse the repository at this point in the history
Add legacy routes redirects
  • Loading branch information
filippomc authored Oct 8, 2023
2 parents 2074de4 + e8cf175 commit c6d57d0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 14 deletions.
29 changes: 29 additions & 0 deletions applications/portal/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,33 @@ import SearchState from "./context/search/SearchState";
import * as UserService from "./services/UserService";
import UpdateForm from "./components/Update/UpdateForm";

function SearchRedirect() {
const searchParams = new URLSearchParams(window.location.search);
const query = searchParams.get('q');

if(query) {
if(query.startsWith('RRID:') || query.startsWith('AB_')) {
const id = query?.replace('RRID:', '');
if (id) {
const newUrl = `/${id}`;
return <Redirect to={newUrl} />;
} else {
return <Redirect to={"/"} />;
}
} else {
return <>
<Navbar />
<Home activeTab={ALLRESULTS} />
</>
}

}


return <Redirect to={"/"} />;
}


const App = () => {
const [user, setUser] = useState(undefined);

Expand Down Expand Up @@ -66,6 +93,8 @@ const App = () => {
<Navbar />
<AntibodyDetail />
</Route>
<Route path="/search" render={SearchRedirect} />
<Route path="/search.php" render={SearchRedirect} />
<Route path="/user">
<Navbar />
<AccountDetails />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useContext, useRef, useCallback, useEffect } from "react";
import { useTheme } from "@mui/material/styles";
import InputBase from "@mui/material/InputBase";
import { SearchIcon, SlashIcon } from "../icons";
import { Box, Autocomplete, InputAdornment, Stack, Tooltip, Typography, Paper } from "@mui/material";
Expand Down Expand Up @@ -93,17 +92,19 @@ export default function Searchbar() {
freeSolo
options={autocompleteOps.map(option => option)}
fullWidth

clearOnEscape
disabled={loader}
className="search-autocomplete"

value={activeSearch}
renderInput={(params) => {
const { InputProps, ...rest } = params;

return(
<InputBase
id="search-main"
inputRef={ref}

{...InputProps}

{...rest}
Expand Down
30 changes: 20 additions & 10 deletions applications/portal/frontend/src/context/search/SearchState.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useCallback, useEffect } from 'react'
import React, { useState, useEffect } from 'react'
import { getSearchAntibodies, getAntibodies } from '../../services/AntibodiesService'
import SearchContext from './SearchContext'
import { getDataInfo } from "../../services/InfoService";
Expand All @@ -9,6 +9,12 @@ const SearchState = (props) => {
lastupdate: new Date()
});

const searchParams = new URLSearchParams(window.location.search);
const query = searchParams.get('q');




const [searchState, setSearch] = useState({
loader:true,
activeSearch:'',
Expand All @@ -22,16 +28,20 @@ const SearchState = (props) => {
).catch((err) => {
console.log("Error: ", err)
})
getAntibodies()
.then((res) => {
setSearch({
loader:false,
activeSearch: "",
totalElements: res.totalElements,
searchedAntibodies: res.items
if(query) {
getFilteredAntibodies(query)
} else {
getAntibodies()
.then((res) => {
setSearch({
loader:false,
activeSearch: "",
totalElements: res.totalElements,
searchedAntibodies: res.items
})
})
})
.catch((err) => console.error(err))
.catch((err) => console.error(err))
}

},[]);

Expand Down
6 changes: 5 additions & 1 deletion applications/portal/frontend/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ module.exports = env => {
https: env.DOMAIN.includes("https"),
port: Number(env.devPort),
allowedHosts: "all",
historyApiFallback: true,
historyApiFallback: {
rewrites: [
{ from: /^\/search\.php$/, to: '/' }
]
},
proxy: {
'/api/': {
target: replaceHost( proxyTarget, 'portal'),
Expand Down
2 changes: 1 addition & 1 deletion port-forward.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
killall -9 kubectl
kubectl port-forward --namespace areg $(kubectl get po -n areg --field-selector=status.phase==Running | grep portal-db | \awk '{print $1;}') 5432:5432 &
kubectl port-forward --namespace areg deployment/portal-db 5432:5432 &
kubectl port-forward --namespace areg deployment/accounts 8080:8080 &
kubectl port-forward --namespace areg $(kubectl get po -n areg | grep kafka | \awk '{print $1;}') 9092:9092 &

0 comments on commit c6d57d0

Please sign in to comment.