Skip to content

Commit

Permalink
Add routing support for ebi-lookup service (#631)
Browse files Browse the repository at this point in the history
* - Add routing for ebi lookup service

* - Fix URL routing with env variable

* - Add console log
- Try diff caddy config

* - REVERT - Add console log
- REVERT - Try diff caddy config
  • Loading branch information
haideriqbal authored Mar 12, 2024
1 parent c2b3560 commit b36c2ae
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion frontend/src/pages/home/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,57 @@
import moment from "moment";
import { useEffect } from "react";
import {useEffect, useState} from "react";
import { Link } from "react-router-dom";
import { useAppDispatch, useAppSelector } from "../../app/hooks";
import { Banner } from "../../components/Banner";
import Header from "../../components/Header";
import SearchBox from "../../components/SearchBox";
import { getBannerText, getStats } from "./homeSlice";
import { useNavigate, useSearchParams } from "react-router-dom";

export default function Home() {
const dispatch = useAppDispatch();
const stats = useAppSelector((state) => state.home.stats);
const banner = useAppSelector((state) => state.home.bannerText);

/*
The following code handles a special case where the user is redirected to the class page of a term.
The service which initiates this workflow is the ebi lookup service. http://www.ebi.ac.uk/ontology-lookup/?termId=ECO:0000353
this url redirects to the OLS class page. It used to work in OLS3 but not in OLS 4. The following code is a workaround to make it work in OLS 4.
Refer to this RT ticket for further details: https://helpdesk.ebi.ac.uk/Ticket/Display.html?id=714111
*/


const navigate = useNavigate();
const [searchParams] = useSearchParams();
const termId = searchParams.get("termId");
const [iri, setIri] = useState('');

useEffect(() => {
const fetchEntity = async () => {
try {
const response = await fetch(`${process.env.REACT_APP_APIURL}api/v2/entities?search=${termId}`);
const data = await response.json();
const entity = data.elements[0];
setIri(entity.iri);
} catch (error) {
console.error('Failed to fetch entity:', error);
}
};

if (termId) {
fetchEntity();
}
}, [termId]);

useEffect(() => {
if (iri && termId) {
navigate(`/ontologies/${termId.split(':')[0].toLowerCase()}/classes?iri=${encodeURIComponent(iri)}`);
}
}, [iri, navigate]);

useEffect(() => {
dispatch(getStats());
}, [dispatch]);
Expand Down

0 comments on commit b36c2ae

Please sign in to comment.