From 50a20b819e4c72bdd028c9a5245593194c12a8e8 Mon Sep 17 00:00:00 2001 From: Graham McNeill Date: Thu, 18 Apr 2024 09:30:57 +0100 Subject: [PATCH 01/10] duplicate literature section --- .../src/pages/DiseasePage/Profile.jsx | 45 +-- apps/platform/src/pages/DrugPage/Profile.jsx | 47 +-- .../platform/src/pages/TargetPage/Profile.jsx | 122 ++++--- .../src/common/LiteratureOld/Body.jsx | 97 +++++ .../src/common/LiteratureOld/Category.jsx | 100 ++++++ .../src/common/LiteratureOld/CountInfo.jsx | 31 ++ .../src/common/LiteratureOld/DateFilter.tsx | 223 ++++++++++++ .../src/common/LiteratureOld/Description.jsx | 18 + .../src/common/LiteratureOld/Entities.jsx | 199 ++++++++++ .../src/common/LiteratureOld/Loader.jsx | 38 ++ .../common/LiteratureOld/PublicationsList.jsx | 242 +++++++++++++ .../src/common/LiteratureOld/Summary.jsx | 31 ++ .../LiteratureOld/TimeTravelObserver.jsx | 52 +++ .../src/common/LiteratureOld/atoms.ts | 339 ++++++++++++++++++ .../src/common/LiteratureOld/index.js | 9 + .../BibliographyOld/BibliographyQuery.gql | 58 +++ .../BibliographySummaryFragment.gql | 6 + .../src/disease/BibliographyOld/Body.jsx | 18 + .../disease/BibliographyOld/Description.jsx | 18 + .../src/disease/BibliographyOld/Summary.jsx | 31 ++ .../src/disease/BibliographyOld/index.js | 9 + .../BibliographyOld/BibliographyQuery.gql | 58 +++ .../BibliographySummaryFragment.gql | 6 + .../src/drug/BibliographyOld/Body.jsx | 22 ++ .../src/drug/BibliographyOld/Description.jsx | 18 + .../src/drug/BibliographyOld/Summary.jsx | 31 ++ .../src/drug/BibliographyOld/index.js | 6 + .../src/target/BibliographyOld/Body.jsx | 17 + .../target/BibliographyOld/Description.jsx | 18 + .../BibliographyOld/SimilarEntities.gql | 58 +++ .../SimilarEntitiesSummary.gql | 6 + .../src/target/BibliographyOld/Summary.jsx | 31 ++ .../src/target/BibliographyOld/index.js | 6 + 33 files changed, 1909 insertions(+), 101 deletions(-) create mode 100644 packages/sections/src/common/LiteratureOld/Body.jsx create mode 100644 packages/sections/src/common/LiteratureOld/Category.jsx create mode 100644 packages/sections/src/common/LiteratureOld/CountInfo.jsx create mode 100644 packages/sections/src/common/LiteratureOld/DateFilter.tsx create mode 100644 packages/sections/src/common/LiteratureOld/Description.jsx create mode 100644 packages/sections/src/common/LiteratureOld/Entities.jsx create mode 100644 packages/sections/src/common/LiteratureOld/Loader.jsx create mode 100644 packages/sections/src/common/LiteratureOld/PublicationsList.jsx create mode 100644 packages/sections/src/common/LiteratureOld/Summary.jsx create mode 100644 packages/sections/src/common/LiteratureOld/TimeTravelObserver.jsx create mode 100644 packages/sections/src/common/LiteratureOld/atoms.ts create mode 100644 packages/sections/src/common/LiteratureOld/index.js create mode 100644 packages/sections/src/disease/BibliographyOld/BibliographyQuery.gql create mode 100644 packages/sections/src/disease/BibliographyOld/BibliographySummaryFragment.gql create mode 100644 packages/sections/src/disease/BibliographyOld/Body.jsx create mode 100644 packages/sections/src/disease/BibliographyOld/Description.jsx create mode 100644 packages/sections/src/disease/BibliographyOld/Summary.jsx create mode 100644 packages/sections/src/disease/BibliographyOld/index.js create mode 100644 packages/sections/src/drug/BibliographyOld/BibliographyQuery.gql create mode 100644 packages/sections/src/drug/BibliographyOld/BibliographySummaryFragment.gql create mode 100644 packages/sections/src/drug/BibliographyOld/Body.jsx create mode 100644 packages/sections/src/drug/BibliographyOld/Description.jsx create mode 100644 packages/sections/src/drug/BibliographyOld/Summary.jsx create mode 100644 packages/sections/src/drug/BibliographyOld/index.js create mode 100644 packages/sections/src/target/BibliographyOld/Body.jsx create mode 100644 packages/sections/src/target/BibliographyOld/Description.jsx create mode 100644 packages/sections/src/target/BibliographyOld/SimilarEntities.gql create mode 100644 packages/sections/src/target/BibliographyOld/SimilarEntitiesSummary.gql create mode 100644 packages/sections/src/target/BibliographyOld/Summary.jsx create mode 100644 packages/sections/src/target/BibliographyOld/index.js diff --git a/apps/platform/src/pages/DiseasePage/Profile.jsx b/apps/platform/src/pages/DiseasePage/Profile.jsx index 9992506cf..77c1a1b8a 100644 --- a/apps/platform/src/pages/DiseasePage/Profile.jsx +++ b/apps/platform/src/pages/DiseasePage/Profile.jsx @@ -10,27 +10,29 @@ import { SectionLoader, } from "ui"; -import OntologySummary from "sections/src/disease/Ontology/Summary"; -import KnownDrugsSummary from "sections/src/disease/KnownDrugs/Summary"; +// import OntologySummary from "sections/src/disease/Ontology/Summary"; +// import KnownDrugsSummary from "sections/src/disease/KnownDrugs/Summary"; + import BibliographySummary from "sections/src/disease/Bibliography/Summary"; -import PhenotypesSummary from "sections/src/disease/Phenotypes/Summary"; -import OTProjectsSummary from "sections/src/disease/OTProjects/Summary"; +// import PhenotypesSummary from "sections/src/disease/Phenotypes/Summary"; +// import OTProjectsSummary from "sections/src/disease/OTProjects/Summary"; import client from "../../client"; import ProfileHeader from "./ProfileHeader"; -const OntologySection = lazy(() => import("sections/src/disease/Ontology/Body")); -const KnownDrugsSection = lazy(() => import("sections/src/disease/KnownDrugs/Body")); +// const OntologySection = lazy(() => import("sections/src/disease/Ontology/Body")); +// const KnownDrugsSection = lazy(() => import("sections/src/disease/KnownDrugs/Body")); const BibliographySection = lazy(() => import("sections/src/disease/Bibliography/Body")); -const PhenotypesSection = lazy(() => import("sections/src/disease/Phenotypes/Body")); -const OTProjectsSection = lazy(() => import("sections/src/disease/OTProjects/Body")); +const BibliographySectionOld = lazy(() => import("sections/src/disease/BibliographyOld/Body")); +// const PhenotypesSection = lazy(() => import("sections/src/disease/Phenotypes/Body")); +// const OTProjectsSection = lazy(() => import("sections/src/disease/OTProjects/Body")); const summaries = [ - OntologySummary, - KnownDrugsSummary, + // OntologySummary, + // KnownDrugsSummary, BibliographySummary, - PhenotypesSummary, - OTProjectsSummary, + // PhenotypesSummary, + // OTProjectsSummary, ]; const DISEASE = "disease"; @@ -57,17 +59,17 @@ function Profile({ efoId, name }) { > - + {/* - + */} - + {/* - + */} - }> + {/* }> }> @@ -75,15 +77,18 @@ function Profile({ efoId, name }) { }> - + */} }> - + }> + + + {/* }> - + */} ); diff --git a/apps/platform/src/pages/DrugPage/Profile.jsx b/apps/platform/src/pages/DrugPage/Profile.jsx index aeca1b853..04e75d3ca 100644 --- a/apps/platform/src/pages/DrugPage/Profile.jsx +++ b/apps/platform/src/pages/DrugPage/Profile.jsx @@ -1,31 +1,32 @@ import { gql } from "@apollo/client"; import { PlatformApiProvider, SectionContainer, SummaryContainer, summaryUtils } from "ui"; -import MechanismsOfActionSummary from "sections/src/drug/MechanismsOfAction/Summary"; -import IndicationsSummary from "sections/src/drug/Indications/Summary"; -import KnownDrugsSummary from "sections/src/drug/KnownDrugs/Summary"; -import DrugWarningsSummary from "sections/src/drug/DrugWarnings/Summary"; -import PharmacogenomicsSummary from "sections/src/drug/Pharmacogenomics/Summary"; -import AdverseEventsSummary from "sections/src/drug/AdverseEvents/Summary"; +// import MechanismsOfActionSummary from "sections/src/drug/MechanismsOfAction/Summary"; +// import IndicationsSummary from "sections/src/drug/Indications/Summary"; +// import KnownDrugsSummary from "sections/src/drug/KnownDrugs/Summary"; +// import DrugWarningsSummary from "sections/src/drug/DrugWarnings/Summary"; +// import PharmacogenomicsSummary from "sections/src/drug/Pharmacogenomics/Summary"; +// import AdverseEventsSummary from "sections/src/drug/AdverseEvents/Summary"; import BibliographySummary from "sections/src/drug/Bibliography/Summary"; -import MechanismsOfActionSection from "sections/src/drug/MechanismsOfAction/Body"; -import IndicationsSection from "sections/src/drug/Indications/Body"; -import KnownDrugsSection from "sections/src/drug/KnownDrugs/Body"; -import DrugWarningsSection from "sections/src/drug/DrugWarnings/Body"; -import PharmacogenomicsSection from "sections/src/drug/Pharmacogenomics/Body"; -import AdverseEventsSection from "sections/src/drug/AdverseEvents/Body"; +// import MechanismsOfActionSection from "sections/src/drug/MechanismsOfAction/Body"; +// import IndicationsSection from "sections/src/drug/Indications/Body"; +// import KnownDrugsSection from "sections/src/drug/KnownDrugs/Body"; +// import DrugWarningsSection from "sections/src/drug/DrugWarnings/Body"; +// import PharmacogenomicsSection from "sections/src/drug/Pharmacogenomics/Body"; +// import AdverseEventsSection from "sections/src/drug/AdverseEvents/Body"; import BibliographySection from "sections/src/drug/Bibliography/Body"; +import BibliographySectionOld from "sections/src/drug/BibliographyOld/Body"; import client from "../../client"; import ProfileHeader from "./ProfileHeader"; const summaries = [ - MechanismsOfActionSummary, - IndicationsSummary, - KnownDrugsSummary, - DrugWarningsSummary, - PharmacogenomicsSummary, - AdverseEventsSummary, + // MechanismsOfActionSummary, + // IndicationsSummary, + // KnownDrugsSummary, + // DrugWarningsSummary, + // PharmacogenomicsSummary, + // AdverseEventsSummary, BibliographySummary, ]; @@ -44,6 +45,7 @@ const DRUG_PROFILE_QUERY = gql` `; function Profile({ chemblId, name }) { + return ( - + {/* - + */} - + {/* - + */} + ); diff --git a/apps/platform/src/pages/TargetPage/Profile.jsx b/apps/platform/src/pages/TargetPage/Profile.jsx index 177da54a8..178086e84 100644 --- a/apps/platform/src/pages/TargetPage/Profile.jsx +++ b/apps/platform/src/pages/TargetPage/Profile.jsx @@ -8,68 +8,69 @@ import { SectionLoader, } from "ui"; -import KnownDrugsSummary from "sections/src/target/KnownDrugs/Summary"; -import TractabilitySummary from "sections/src/target/Tractability/Summary"; -import SafetySummary from "sections/src/target/Safety/Summary"; -import PharmacogenomicsSummary from "sections/src/target/Pharmacogenomics/Summary"; -import ChemicalProbesSummary from "sections/src/target/ChemicalProbes/Summary"; -import BaselineExpressionSummary from "sections/src/target/Expression/Summary"; -import DepMapSummary from "sections/src/target/DepMap/Summary"; -import GeneOntologySummary from "sections/src/target/GeneOntology/Summary"; -import GeneticConstraintSummary from "sections/src/target/GeneticConstraint/Summary"; -import ProtVistaSummary from "sections/src/target/ProtVista/Summary"; -import MolecularInteractionsSummary from "sections/src/target/MolecularInteractions/Summary"; -import PathwaysSummary from "sections/src/target/Pathways/Summary"; -import CancerHallmarksSummary from "sections/src/target/CancerHallmarks/Summary"; -import MousePhenotypesSummary from "sections/src/target/MousePhenotypes/Summary"; -import ComparativeGenomicsSummary from "sections/src/target/ComparativeGenomics/Summary"; -import SubcellularLocationSummary from "sections/src/target/SubcellularLocation/Summary"; +// import KnownDrugsSummary from "sections/src/target/KnownDrugs/Summary"; +// import TractabilitySummary from "sections/src/target/Tractability/Summary"; +// import SafetySummary from "sections/src/target/Safety/Summary"; +// import PharmacogenomicsSummary from "sections/src/target/Pharmacogenomics/Summary"; +// import ChemicalProbesSummary from "sections/src/target/ChemicalProbes/Summary"; +// import BaselineExpressionSummary from "sections/src/target/Expression/Summary"; +// import DepMapSummary from "sections/src/target/DepMap/Summary"; +// import GeneOntologySummary from "sections/src/target/GeneOntology/Summary"; +// import GeneticConstraintSummary from "sections/src/target/GeneticConstraint/Summary"; +// import ProtVistaSummary from "sections/src/target/ProtVista/Summary"; +// import MolecularInteractionsSummary from "sections/src/target/MolecularInteractions/Summary"; +// import PathwaysSummary from "sections/src/target/Pathways/Summary"; +// import CancerHallmarksSummary from "sections/src/target/CancerHallmarks/Summary"; +// import MousePhenotypesSummary from "sections/src/target/MousePhenotypes/Summary"; +// import ComparativeGenomicsSummary from "sections/src/target/ComparativeGenomics/Summary"; +// import SubcellularLocationSummary from "sections/src/target/SubcellularLocation/Summary"; import BibliographySummary from "sections/src/target/Bibliography/Summary"; import ProfileHeader from "./ProfileHeader"; import client from "../../client"; -const KnownDrugsSection = lazy(() => import("sections/src/target/KnownDrugs/Body")); -const TractabilitySection = lazy(() => import("sections/src/target/Tractability/Body")); -const SafetySection = lazy(() => import("sections/src/target/Safety/Body")); -const PharmacogenomicsSection = lazy(() => import("sections/src/target/Pharmacogenomics/Body")); -const ChemicalProbesSection = lazy(() => import("sections/src/target/ChemicalProbes/Body")); -const BaselineExpressionSection = lazy(() => import("sections/src/target/Expression/Body")); -const DepMapSection = lazy(() => import("sections/src/target/DepMap/Body")); -const GeneOntologySection = lazy(() => import("sections/src/target/GeneOntology/Body")); -const GeneticConstraintSection = lazy(() => import("sections/src/target/GeneticConstraint/Body")); -const ProtVistaSection = lazy(() => import("sections/src/target/ProtVista/Body")); -const MolecularInteractionsSection = lazy(() => - import("sections/src/target/MolecularInteractions/Body") -); -const PathwaysSection = lazy(() => import("sections/src/target/Pathways/Body")); -const CancerHallmarksSection = lazy(() => import("sections/src/target/CancerHallmarks/Body")); -const MousePhenotypesSection = lazy(() => import("sections/src/target/MousePhenotypes/Body")); -const ComparativeGenomicsSection = lazy(() => - import("sections/src/target/ComparativeGenomics/Body") -); -const SubcellularLocationSection = lazy(() => - import("sections/src/target/SubcellularLocation/Body") -); +// const KnownDrugsSection = lazy(() => import("sections/src/target/KnownDrugs/Body")); +// const TractabilitySection = lazy(() => import("sections/src/target/Tractability/Body")); +// const SafetySection = lazy(() => import("sections/src/target/Safety/Body")); +// const PharmacogenomicsSection = lazy(() => import("sections/src/target/Pharmacogenomics/Body")); +// const ChemicalProbesSection = lazy(() => import("sections/src/target/ChemicalProbes/Body")); +// const BaselineExpressionSection = lazy(() => import("sections/src/target/Expression/Body")); +// const DepMapSection = lazy(() => import("sections/src/target/DepMap/Body")); +// const GeneOntologySection = lazy(() => import("sections/src/target/GeneOntology/Body")); +// const GeneticConstraintSection = lazy(() => import("sections/src/target/GeneticConstraint/Body")); +// const ProtVistaSection = lazy(() => import("sections/src/target/ProtVista/Body")); +// const MolecularInteractionsSection = lazy(() => +// import("sections/src/target/MolecularInteractions/Body") +// ); +// const PathwaysSection = lazy(() => import("sections/src/target/Pathways/Body")); +// const CancerHallmarksSection = lazy(() => import("sections/src/target/CancerHallmarks/Body")); +// const MousePhenotypesSection = lazy(() => import("sections/src/target/MousePhenotypes/Body")); +// const ComparativeGenomicsSection = lazy(() => +// import("sections/src/target/ComparativeGenomics/Body") +// ); +// const SubcellularLocationSection = lazy(() => +// import("sections/src/target/SubcellularLocation/Body") +// ); const BibliographySection = lazy(() => import("sections/src/target/Bibliography/Body")); +const BibliographySectionOld = lazy(() => import("sections/src/target/BibliographyOld/Body")); const summaries = [ - KnownDrugsSummary, - TractabilitySummary, - SafetySummary, - PharmacogenomicsSummary, - ChemicalProbesSummary, - BaselineExpressionSummary, - DepMapSummary, - GeneOntologySummary, - GeneticConstraintSummary, - ProtVistaSummary, - MolecularInteractionsSummary, - PathwaysSummary, - CancerHallmarksSummary, - MousePhenotypesSummary, - ComparativeGenomicsSummary, - SubcellularLocationSummary, + // KnownDrugsSummary, + // TractabilitySummary, + // SafetySummary, + // PharmacogenomicsSummary, + // ChemicalProbesSummary, + // BaselineExpressionSummary, + // DepMapSummary, + // GeneOntologySummary, + // GeneticConstraintSummary, + // ProtVistaSummary, + // MolecularInteractionsSummary, + // PathwaysSummary, + // CancerHallmarksSummary, + // MousePhenotypesSummary, + // ComparativeGenomicsSummary, + // SubcellularLocationSummary, BibliographySummary, ]; @@ -97,7 +98,7 @@ function Profile({ ensgId, symbol }) { > - + {/* @@ -112,12 +113,12 @@ function Profile({ ensgId, symbol }) { - + */} - }> + {/* }> }> @@ -164,13 +165,16 @@ function Profile({ ensgId, symbol }) { }> - + */} }> + }> + + ); } -export default Profile; +export default Profile; \ No newline at end of file diff --git a/packages/sections/src/common/LiteratureOld/Body.jsx b/packages/sections/src/common/LiteratureOld/Body.jsx new file mode 100644 index 000000000..feb5c8889 --- /dev/null +++ b/packages/sections/src/common/LiteratureOld/Body.jsx @@ -0,0 +1,97 @@ +import { useEffect, useState } from "react"; +import { Box } from "@mui/material"; +import { useSetRecoilState, useRecoilValue, useResetRecoilState, RecoilRoot } from "recoil"; +import { SectionItem } from "ui"; +import PublicationsList from "./PublicationsList"; +import Description from "./Description"; +import { literatureState, updateLiteratureState, fetchSimilarEntities } from "./atoms"; +import Entities from "./Entities"; +import Category from "./Category"; +import CountInfo from "./CountInfo"; +import { DateFilter } from "./DateFilter"; + +function LiteratureList({ id, name, entity, BODY_QUERY, definition }) { + const [requestObj, setRequestObj] = useState({}); + + const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); + const resetLiteratureState = useResetRecoilState(literatureState); + + const bibliographyState = useRecoilValue(literatureState); + const { category, startYear, startMonth, endYear, endMonth } = bibliographyState; + + useEffect( + () => { + async function startRequest() { + const inintRequest = await fetchSimilarEntities({ + id, + query: BODY_QUERY, + category, + startYear, + startMonth, + endYear, + endMonth, + }); + setRequestObj(inintRequest); + const data = inintRequest.data[entity]; + const update = { + entities: data.similarEntities, + litsIds: data.literatureOcurrences?.rows?.map(({ pmid }) => ({ + id: pmid, + status: "ready", + publication: null, + })), + litsCount: data.literatureOcurrences?.filteredCount, + earliestPubYear: data.literatureOcurrences?.earliestPubYear, + cursor: data.literatureOcurrences?.cursor, + id, + query: BODY_QUERY, + globalEntity: entity, + }; + setLiteratureUpdate(update); + } + startRequest(); + return function cleanUp() { + resetLiteratureState(); + }; + }, + // eslint-disable-next-line react-hooks/exhaustive-deps + [] + ); + return ( + } + renderBody={() => ( + <> + + + + + + + + + + + )} + /> + ); +} + +function Body({ definition, name, id, entity, BODY_QUERY }) { + return ( + + + + ); +} + +export default Body; diff --git a/packages/sections/src/common/LiteratureOld/Category.jsx b/packages/sections/src/common/LiteratureOld/Category.jsx new file mode 100644 index 000000000..8dd350c99 --- /dev/null +++ b/packages/sections/src/common/LiteratureOld/Category.jsx @@ -0,0 +1,100 @@ +import { InputLabel, FormGroup, Checkbox, FormControlLabel } from "@mui/material"; +import { useRecoilState, useRecoilValue, useSetRecoilState } from "recoil"; +import { + selectedCategoriesState, + loadingEntitiesState, + literatureState, + fetchSimilarEntities, + updateLiteratureState, +} from "./atoms"; + +const toggleValue = (selected, categories) => { + const isChecked = categories.indexOf(selected) !== -1; + if (!isChecked) return [...categories, selected]; + return [...categories.filter(value => value !== selected).sort()]; +}; + +const categories = [ + { name: "target", label: "Target" }, + { name: "disease", label: "Disease" }, + { name: "drug", label: "Drug" }, +]; + +export default function Category() { + const category = useRecoilValue(selectedCategoriesState); + const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); + const [loadingEntities, setLoadingEntities] = useRecoilState(loadingEntitiesState); + + const bibliographyState = useRecoilValue(literatureState); + + const handleChange = async event => { + const { + query, + id, + category: bibliographyCategory, + selectedEntities, + globalEntity, + cursor, + endYear, + endMonth, + startYear, + startMonth, + } = bibliographyState; + const { + target: { name: clicked }, + } = event; + const newCategories = toggleValue(clicked, bibliographyCategory); + setLoadingEntities(true); + const request = await fetchSimilarEntities({ + query, + id, + category: newCategories, + entities: selectedEntities, + cursor, + endYear, + endMonth, + startYear, + startMonth, + }); + const data = request.data[globalEntity]; + + const update = { + entities: data.similarEntities, + earliestPubYear: data.literatureOcurrences?.earliestPubYear, + litsCount: data.literatureOcurrences?.filteredCount, + loadingEntities: false, + category: newCategories, + }; + setLiteratureUpdate(update); + }; + + return ( +
+ + Tag category: + + + {categories.map(({ name, label }) => ( + + } + label={label} + /> + ))} + +
+ ); +} diff --git a/packages/sections/src/common/LiteratureOld/CountInfo.jsx b/packages/sections/src/common/LiteratureOld/CountInfo.jsx new file mode 100644 index 000000000..241aae271 --- /dev/null +++ b/packages/sections/src/common/LiteratureOld/CountInfo.jsx @@ -0,0 +1,31 @@ +import { InputLabel, Box } from "@mui/material"; +import { makeStyles } from "@mui/styles"; +import { useRecoilValue } from "recoil"; +import { litsCountState, loadingEntitiesState, tablePageSizeState } from "./atoms"; + +const useStyles = makeStyles(() => ({ + resultCount: { + // marginLeft: "2rem", + // marginRight: "6rem", + }, +})); + +function CountInfo() { + const classes = useStyles(); + const pageSize = useRecoilValue(tablePageSizeState); + const count = useRecoilValue(litsCountState); + const loadingEntities = useRecoilValue(loadingEntitiesState); + + const getLabelText = () => { + if (loadingEntities) return "Loading count..."; + return `Showing ${count > pageSize ? pageSize : count} of ${count} results`; + }; + + return ( + + {getLabelText()} + + ); +} + +export default CountInfo; diff --git a/packages/sections/src/common/LiteratureOld/DateFilter.tsx b/packages/sections/src/common/LiteratureOld/DateFilter.tsx new file mode 100644 index 000000000..3e9e7a595 --- /dev/null +++ b/packages/sections/src/common/LiteratureOld/DateFilter.tsx @@ -0,0 +1,223 @@ +import { useEffect, useState } from "react"; +import { FormControl, FormGroup, InputLabel, Slider } from "@mui/material"; +import { useRecoilState, useRecoilValue, useSetRecoilState } from "recoil"; +import { + fetchSimilarEntities, + literatureState, + loadingEntitiesState, + updateLiteratureState, +} from "./atoms"; +import { styled } from "@mui/material/styles"; + +const OTSlider = styled(Slider)({ + root: { + padding: "0 10px !important", + }, + mark: { + backgroundColor: "#b8b8b8", + width: 10, + height: 1, + marginLeft: -4, + }, + valueLabel: { + zIndex: "9999", + }, +}); + +const DateIndicator = styled("span")({ + minWidth: 65, + maxWidth: 80, +}); + +const monthsBtwnDates = (startDate: Date, endDate: Date) => + Math.max( + (endDate.getFullYear() - startDate.getFullYear()) * 12 + + (endDate.getMonth() - startDate.getMonth()), + 0 + ); + +export function DateFilter() { + const [filterDate, setFilterDate] = useState([0, 0]); + const [numberOfMonths, setNumberOfMonths] = useState(0); + const [pubYear, setPubYear] = useState(0); + const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); + const [_, setLoadingEntities] = useRecoilState(loadingEntitiesState); + const { + query, + id, + category, + earliestPubYear, + selectedEntities, + cursor, + globalEntity, + litsIds, + pageSize, + litsCount, + loadingEntities, + } = useRecoilValue(literatureState); + + function getDateFromYear(year: number) { + return new Date(year, 0, 1, 1, 1, 1, 1); + } + + const sumMonthsSinceYear = (year: number) => (value: number) => { + const from = getDateFromYear(year); + const date = new Date(from.setMonth(from.getMonth() + value)); + return date; + }; + + const selectedDate = sumMonthsSinceYear(earliestPubYear); + const oldSelectedDate = sumMonthsSinceYear(pubYear); + + useEffect(() => { + // the publication year has changed + if (earliestPubYear && earliestPubYear !== pubYear) { + const earliestDate = getDateFromYear(earliestPubYear); + const limit = monthsBtwnDates(earliestDate, new Date()); + + const lowerLimit = getLowerLimit(earliestDate); + + const higherLimit = getHigherLimit(earliestDate, limit); + + setFilterDate([lowerLimit, higherLimit]); + setNumberOfMonths(limit); + setPubYear(earliestPubYear); + } else { + setPubYear(0); + setNumberOfMonths(0); + setFilterDate([0, 0]); + } + }, [earliestPubYear]); + + function getHigherLimit(earliestDate: Date, limit: number) { + const oldHigherDate = oldSelectedDate(filterDate[1]); + const newHighFilter = monthsBtwnDates(earliestDate, oldHigherDate); + const higherLimit = + filterDate[1] > 0 && newHighFilter > 0 && newHighFilter < limit ? newHighFilter : limit; + return higherLimit; + } + + function getLowerLimit(earliestDate: Date) { + if (filterDate[0] == 0) return 0; + const oldLowerDate = oldSelectedDate(filterDate[0]); + const newLowerFilter = monthsBtwnDates(earliestDate, oldLowerDate); + const lowerLimit = newLowerFilter > 0 ? newLowerFilter : 0; + return lowerLimit; + } + + const handleChange = async (values: { + startYear: number; + startMonth: number; + endYear: number; + endMonth: number; + }) => { + setLoadingEntities(true); + const entities = selectedEntities as any[]; + const request = await fetchSimilarEntities({ + query, + id, + category, + entities, + cursor: null, + earliestPubYear, + globalEntity, + selectedEntities, + litsIds, + page: 0, + pageSize, + litsCount, + loadingEntities, + ...values, + }); + const data = request.data[globalEntity]; + const update = { + id, + cursor: data.literatureOcurrences?.cursor, + query, + entities: data.similarEntities, + loadingEntities: false, + category, + litsIds: data.literatureOcurrences?.rows?.map(({ pmid }: { pmid: any }) => ({ + id: pmid, + status: "ready", + publication: null, + })), + litsCount: data.literatureOcurrences?.filteredCount, + earliestPubYear: data.literatureOcurrences?.earliestPubYear, + globalEntity, + selectedEntities, + page: 0, + pageSize, + ...values, + }; + setLiteratureUpdate(update); + }; + + const valueLabelFormat = (value: number | number[]) => { + if (earliestPubYear) { + const labelDate = selectedDate(value as number); + return `${labelDate.getFullYear()}-${labelDate.getMonth() + 1}`; + } + return "YYYY-MM"; + }; + + const handleDateRangeChange = (_event: Event, value: number[] | number, _activeThumb: number) => { + setFilterDate(value as number[]); + }; + + const handleDateRangeChangeCommitted = ( + _event: Event | React.SyntheticEvent, + value: number | number[] + ) => { + if (Array.isArray(value)) { + const startDate = selectedDate(value[0]); + const endDate = selectedDate(value[1]); + handleChange({ + startYear: startDate.getFullYear(), + startMonth: startDate.getMonth() + 1, + endYear: endDate.getFullYear(), + endMonth: endDate.getMonth() + 1, + }); + } + }; + + return ( +
+ Date Filter: + + + {valueLabelFormat(filterDate[0])} + "date-range-slider"} + max={numberOfMonths} + valueLabelFormat={valueLabelFormat} + /> + {valueLabelFormat(filterDate[1])} + + +
+ ); +} diff --git a/packages/sections/src/common/LiteratureOld/Description.jsx b/packages/sections/src/common/LiteratureOld/Description.jsx new file mode 100644 index 000000000..afd67b955 --- /dev/null +++ b/packages/sections/src/common/LiteratureOld/Description.jsx @@ -0,0 +1,18 @@ +import { Link } from "ui"; + +const url = "http://platform-docs.opentargets.org/bibliography"; + +function Description({ name }) { + return ( + <> + Scientific literature mentioning NLP-recognised entity {name} and other + selected co-occurring entities. Source:{" "} + + Open Targets + + . + + ); +} + +export default Description; diff --git a/packages/sections/src/common/LiteratureOld/Entities.jsx b/packages/sections/src/common/LiteratureOld/Entities.jsx new file mode 100644 index 000000000..3d7a119f2 --- /dev/null +++ b/packages/sections/src/common/LiteratureOld/Entities.jsx @@ -0,0 +1,199 @@ +import { Chip, Grow } from "@mui/material"; +import { makeStyles } from "@mui/styles"; +import { useRecoilState, useSetRecoilState, useRecoilValue } from "recoil"; +import { + entitiesState, + selectedEntitiesState, + fetchSimilarEntities, + literatureState, + loadingEntitiesState, + updateLiteratureState, +} from "./atoms"; + +const useStyles = makeStyles(theme => ({ + root: { + display: "flex", + flexWrap: "wrap", + "& > *": { + margin: `${theme.spacing(0.5)} !important`, + }, + }, + loadingContainer: { + display: "flex", + margin: "10px", + }, +})); + +function EntitiesToSelect({ id }) { + const entities = useRecoilValue(entitiesState); + const bibliographyState = useRecoilValue(literatureState); + const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); + const [selectedChips, setSelectedChips] = useRecoilState(selectedEntitiesState); + const [loadingEntities, setLoadingEntities] = useRecoilState(loadingEntitiesState); + + const handleSelectChip = async e => { + const { + query, + id: bibliographyId, + category, + globalEntity, + endYear, + endMonth, + startYear, + startMonth, + } = bibliographyState; + const newChips = [ + ...selectedChips, + { + score: e.score, + object: { + name: e.object.name || e.object.approvedSymbol, + id: e.object.id, + }, + }, + ]; + setSelectedChips(newChips); + setLoadingEntities(true); + const request = await fetchSimilarEntities({ + query, + id: bibliographyId, + category, + entities: newChips, + endYear, + endMonth, + startYear, + startMonth, + }); + const data = request.data[globalEntity]; + const update = { + entities: data.similarEntities, + litsIds: data.literatureOcurrences?.rows?.map(({ pmid }) => ({ + id: pmid, + status: "ready", + publication: null, + })), + litsCount: data.literatureOcurrences?.filteredCount, + earliestPubYear: data.literatureOcurrences?.earliestPubYear, + cursor: data.literatureOcurrences?.cursor, + loadingEntities: false, + page: 0, + }; + setLiteratureUpdate(update); + }; + + const validateEntity = entity => { + if (id === entity.object?.id) return null; + if (selectedChips.find(s => s.object.id === entity.object.id)) return null; + return entity; + }; + + return entities.map(e => { + if (!e.object) + return ( + + + + ); + return validateEntity(e) ? ( + + { + handleSelectChip(e); + }} + title={`Score: ${e.score} ID: ${e.object.id}`} + color="primary" + variant="outlined" + /> + + ) : null; + }); +} + +export default function Entities({ name, id }) { + const classes = useStyles(); + + const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); + const bibliographyState = useRecoilValue(literatureState); + const [loadingEntities, setLoadingEntities] = useRecoilState(loadingEntitiesState); + const [selectedChips, setSelectedChips] = useRecoilState(selectedEntitiesState); + + const handleDeleteChip = async index => { + const { + query, + id: bibliographyId, + category, + globalEntity, + endYear, + endMonth, + startYear, + startMonth, + } = bibliographyState; + const newChips = [...selectedChips.slice(0, index), ...selectedChips.slice(index + 1)]; + setSelectedChips(newChips); + setLoadingEntities(true); + const request = await fetchSimilarEntities({ + query, + id: bibliographyId, + category, + entities: newChips, + endYear, + endMonth, + startYear, + startMonth, + }); + const data = request.data[globalEntity]; + const update = { + entities: data.similarEntities, + litsIds: data.literatureOcurrences?.rows?.map(({ pmid }) => ({ + id: pmid, + status: "ready", + publication: null, + })), + litsCount: data.literatureOcurrences?.filteredCount, + earliestPubYear: data.literatureOcurrences?.earliestPubYear, + cursor: data.literatureOcurrences?.cursor, + loadingEntities: false, + page: 0, + }; + setLiteratureUpdate(update); + }; + + return ( +
+
+ + {selectedChips.map((e, i) => ( + + { + handleDeleteChip(i); + }} + onDelete={() => { + handleDeleteChip(i); + }} + /> + + ))} +
+
+ +
+
+ ); +} diff --git a/packages/sections/src/common/LiteratureOld/Loader.jsx b/packages/sections/src/common/LiteratureOld/Loader.jsx new file mode 100644 index 000000000..435a04263 --- /dev/null +++ b/packages/sections/src/common/LiteratureOld/Loader.jsx @@ -0,0 +1,38 @@ +import { Box, Typography, CircularProgress } from "@mui/material"; +import { makeStyles } from "@mui/styles"; +import { useEffect, useState } from "react"; + +const listComponentStyles = makeStyles(() => ({ + loader: { + display: "flex", + justifyContent: "center", + alignItems: "center", + }, +})); + +function Loader({ message = "", pageSize = 5 }) { + const [height, setHeight] = useState("4040px"); + + useEffect(() => { + if (pageSize === 5) setHeight("850px"); + else if (pageSize === 10) setHeight("1640px"); + else setHeight("4040px"); + }, [pageSize]); + + return ( + + + + {message} + + + ); +} + +export default Loader; diff --git a/packages/sections/src/common/LiteratureOld/PublicationsList.jsx b/packages/sections/src/common/LiteratureOld/PublicationsList.jsx new file mode 100644 index 000000000..eec522374 --- /dev/null +++ b/packages/sections/src/common/LiteratureOld/PublicationsList.jsx @@ -0,0 +1,242 @@ +import { useEffect } from "react"; +import { useRecoilState, useRecoilValue, useSetRecoilState, useRecoilCallback } from "recoil"; +import { Box, Grid, Fade, Skeleton } from "@mui/material"; +import { makeStyles } from "@mui/styles"; +import { PublicationWrapper, Table } from "ui"; +import Loader from "./Loader"; + +import { + litsIdsState, + loadingEntitiesState, + displayedPublications, + literaturesEuropePMCQuery, + parsePublications, + tablePageState, + litsCountState, + litsCursorState, + literatureState, + fetchSimilarEntities, + updateLiteratureState, + tablePageSizeState, +} from "./atoms"; + +const useStyles = makeStyles(() => ({ + root: { + marginTop: 0, + }, +})); + +function SkeletonRow() { + return ( + + + + {/* */} + + {/* */} + + + + + + + + + + + ); +} + +function PublicationsList({ hideSearch = false }) { + const classes = useStyles(); + const lits = useRecoilValue(litsIdsState); + const [loadingEntities, setLoadingEntities] = useRecoilState(loadingEntitiesState); + const count = useRecoilValue(litsCountState); + const cursor = useRecoilValue(litsCursorState); + const displayedPubs = useRecoilValue(displayedPublications); + const bibliographyState = useRecoilValue(literatureState); + const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); + const page = useRecoilValue(tablePageState); + const pageSize = useRecoilValue(tablePageSizeState); + + // function to request 'ready' literatures ids + const syncLiteraturesState = useRecoilCallback(({ snapshot, set }) => async () => { + const AllLits = await snapshot.getPromise(litsIdsState); + const readyForRequest = AllLits.filter(x => x.status === "ready").map(x => x.id); + + if (readyForRequest.length === 0) return; + const queryResult = await snapshot.getPromise( + literaturesEuropePMCQuery({ + literaturesIds: readyForRequest, + }) + ); + + const parsedPublications = parsePublications(queryResult); + + const mapedResults = new Map(parsedPublications.map(key => [key.europePmcId, key])); + + const updatedPublications = AllLits.map(x => { + const publication = mapedResults.get(x.id); + if (x.status === "loaded") return x; + const status = publication ? "loaded" : "missing"; + return { ...x, status, publication }; + }); + set(litsIdsState, updatedPublications); + }); + + useEffect( + () => { + if (lits.length !== 0) syncLiteraturesState(); + }, + // eslint-disable-next-line react-hooks/exhaustive-deps + [lits] + ); + + const handleRowsPerPageChange = useRecoilCallback(({ snapshot }) => async newPageSize => { + const pageSizeInt = Number(newPageSize); + const expected = pageSizeInt * page + pageSizeInt; + if (expected > lits.length && cursor !== null) { + const { + query, + id, + category, + selectedEntities, + cursor: newCursor, + globalEntity, + endYear, + endMonth, + startYear, + startMonth, + } = bibliographyState; + setLoadingEntities(true); + const request = await fetchSimilarEntities({ + query, + id, + category, + entities: selectedEntities, + cursor: newCursor, + page: 0, + endYear, + endMonth, + startYear, + startMonth, + }); + setLoadingEntities(false); + const data = request.data[globalEntity]; + const loadedPublications = await snapshot.getPromise(litsIdsState); + const newLits = data.literatureOcurrences?.rows?.map(({ pmid }) => ({ + id: pmid, + status: "ready", + publication: null, + })); + const update = { + litsIds: [...loadedPublications, ...newLits], + cursor: data.literatureOcurrences?.cursor, + page: 0, + pageSize: pageSizeInt, + }; + setLiteratureUpdate(update); + } else { + setLiteratureUpdate({ page: 0, pageSize: pageSizeInt }); + } + }); + + const handlePageChange = useRecoilCallback(({ snapshot }) => async newPage => { + const newPageInt = Number(newPage); + if (pageSize * newPageInt + pageSize > lits.length && cursor !== null) { + const { + query, + id, + category, + selectedEntities, + cursor: newCursor, + globalEntity, + endYear, + endMonth, + startYear, + startMonth, + } = bibliographyState; + setLoadingEntities(true); + const request = await fetchSimilarEntities({ + query, + id, + category, + entities: selectedEntities, + cursor: newCursor, + endYear, + endMonth, + startYear, + startMonth, + }); + setLoadingEntities(false); + const data = request.data[globalEntity]; + const loadedPublications = await snapshot.getPromise(litsIdsState); + const newLits = data.literatureOcurrences?.rows?.map(({ pmid }) => ({ + id: pmid, + status: "ready", + publication: null, + })); + const update = { + litsIds: [...loadedPublications, ...newLits], + cursor: data.literatureOcurrences?.cursor, + page: newPageInt, + }; + setLiteratureUpdate(update); + } else { + setLiteratureUpdate({ page: newPageInt }); + } + }); + + const columns = [ + { + id: "publications", + label: " ", + renderCell: ({ publication, status }) => { + if (status === "ready") return ; + if (status === "missing") return null; + return ( + + ); + }, + filterValue: ({ row: publication }) => + `${publication.journal.journal?.title} ${publication?.title} ${publication?.year} + ${publication.authors + .reduce((acc, author) => { + if (author.fullName) acc.push(author.fullName); + return acc; + }, []) + .join(" ")}`, + }, + ]; + + if (loadingEntities) + return ; + + return ( + + ); +} + +export default PublicationsList; diff --git a/packages/sections/src/common/LiteratureOld/Summary.jsx b/packages/sections/src/common/LiteratureOld/Summary.jsx new file mode 100644 index 000000000..155251c7a --- /dev/null +++ b/packages/sections/src/common/LiteratureOld/Summary.jsx @@ -0,0 +1,31 @@ +import { gql } from "@apollo/client"; + +import { SummaryItem, usePlatformApi } from "ui"; + +const SIMILARENTTIES_SUMMARY_FRAGMENT = gql` + fragment SimilarEntitiesDisease on Disease { + similarEntities(threshold: 0.5, size: 20) { + score + } + } +`; + +function Summary({ definition }) { + const request = usePlatformApi(SIMILARENTTIES_SUMMARY_FRAGMENT); + + return ( + + data.similarEntities?.length > 0 ? <>Data available : <>no data + } + /> + ); +} + +Summary.fragments = { + SimilarEntitiesDisease: SIMILARENTTIES_SUMMARY_FRAGMENT, +}; + +export default Summary; diff --git a/packages/sections/src/common/LiteratureOld/TimeTravelObserver.jsx b/packages/sections/src/common/LiteratureOld/TimeTravelObserver.jsx new file mode 100644 index 000000000..00843e92e --- /dev/null +++ b/packages/sections/src/common/LiteratureOld/TimeTravelObserver.jsx @@ -0,0 +1,52 @@ +import { useState, useEffect } from "react"; +import { List, ListItem, Drawer, Box, Link as MUILink, Button } from "@mui/material"; +import { useRecoilSnapshot, useGotoRecoilSnapshot } from "recoil"; + +export default function TimeTravelObserver() { + const [snapshots, setSnapshots] = useState([]); + const [open, setOpen] = useState(false); + + const snapshot = useRecoilSnapshot(); + + const toggleDrawer = event => { + if (event.type === "keydown" && (event.key === "Tab" || event.key === "Shift")) { + return; + } + + setOpen(true); + }; + + const closeDrawer = () => { + setOpen(false); + }; + + useEffect( + () => { + if (snapshots.every(s => s.getID() !== snapshot.getID())) { + setSnapshots([...snapshots, snapshot]); + } + }, + // eslint-disable-next-line react-hooks/exhaustive-deps + [snapshot] + ); + + const gotoSnapshot = useGotoRecoilSnapshot(); + + return ( + <> + Time Travel Observer + + + + {snapshots.map((snapshotItem, i) => ( + + Snapshot {i} + + + ))} + + + + + ); +} diff --git a/packages/sections/src/common/LiteratureOld/atoms.ts b/packages/sections/src/common/LiteratureOld/atoms.ts new file mode 100644 index 000000000..aeea0a4e5 --- /dev/null +++ b/packages/sections/src/common/LiteratureOld/atoms.ts @@ -0,0 +1,339 @@ +import isEmpty from "lodash/isEmpty"; +import { atom, selectorFamily, selector, DefaultValue } from "recoil"; +import { getPage } from "ui"; +import client from "../../client"; +import { europePmcBiblioSearchPOSTQuery } from "../../utils/urls"; + +// ------------------------------------------ +// Helpers +// ------------------------------------------ + +type AuthorListType = { + fullName: string; + firstName: string; + lastName: string; + initials: string; + authorId: { + type: string; + value: string; + }; + authorAffiliationDetailsList: { + authorAffiliation: { + affiliation: string; + }[]; + }; +}; + +type JournalInfoType = { + issue: string; + volume: string; + journalIssueId: number; + dateOfPublication: string; + monthOfPublication: number; + yearOfPublication: number; + printPublicationDate: string; + journal: { + title: string; + medlineAbbreviation: string; + isoabbreviation: string; + nlmid: string; + issn: string; + essn: string; + }; +}; + +type PublicationType = { + source: string; + patentDetails: any; + id: string; + inEPMC: string; + inPMC: string; + title: string; + pubYear: string; + abstractText: string; + isOpenAccess: string; + authorList: { + author: AuthorListType; + }; + journalInfo: JournalInfoType; + pageInfo: string; +}; + +type RowType = { + source: string; + patentDetails: any; + europePmcId: string; + fullTextOpen: boolean; + title: string; + year: string; + abstract: string; + openAccess: boolean; + authors: AuthorListType; + journal: JournalInfoType & { page: string }; +}; + +export const parsePublications = (publications: PublicationType[]) => + publications.map(pub => { + const row: RowType = { + source: pub.source, + patentDetails: pub.patentDetails, + europePmcId: pub.id, + fullTextOpen: !!(pub.inEPMC === "Y" || pub.inPMC === "Y"), + title: pub.title, + year: pub.pubYear, + abstract: pub.abstractText, + openAccess: pub.isOpenAccess !== "N", + authors: pub.authorList?.author || [], + journal: { + ...pub.journalInfo, + page: pub.pageInfo, + }, + }; + return row; + }); + +type LiteratureStateType = { + id: string; + cursor: string | null; + threshold?: number; + size?: number; + category: string[]; + query: any | null; + globalEntity: any | null; + entities: any[]; + selectedEntities: any[] | DefaultValue; + startYear: number | null; + startMonth: number | null; + endYear: number | null; + endMonth: number | null; + earliestPubYear: number; + litsIds: + | { + id: string; + status: string; + publication: null; + }[] + | DefaultValue; + page: number; + pageSize: number | DefaultValue; + litsCount: number; + loadingEntities: boolean | DefaultValue; +}; + +// ------------------------------------------ +// ATOMS +// ------------------------------------------ + +const defaultState: LiteratureStateType = { + id: "", + cursor: "", + category: ["disease", "drug", "target"], + query: null, + globalEntity: null, + entities: [], + selectedEntities: [], + startYear: null, + startMonth: null, + endYear: null, + endMonth: null, + earliestPubYear: 0, + litsIds: [], + page: 0, + pageSize: 5, + litsCount: 0, + loadingEntities: false, +}; + +export const literatureState = atom({ + key: "literatureState", + default: defaultState, +}); + +// ------------------------------------------ +// SELECTORS +// ------------------------------------------ +export const loadingEntitiesState = selector({ + key: "loadingEntitiesState", + get: ({ get }) => { + const { loadingEntities } = get(literatureState); + return loadingEntities; + }, + set: ({ set, get }, newStatus) => { + const currentState = get(literatureState); + const newState: LiteratureStateType = { + ...currentState, + loadingEntities: newStatus, + }; + return set(literatureState, newState); + }, +}); + +export const selectedCategoriesState = selector({ + key: "selectedCategoriesState", + get: ({ get }) => { + const { category } = get(literatureState); + const sortedCategories = [...category].sort(); + return sortedCategories; + }, +}); + +export const litsCursorState = selector({ + key: "litsCursorState", + get: ({ get }) => { + const { cursor } = get(literatureState); + return cursor; + }, +}); + +export const tablePageState = selector({ + key: "tablePageState", + get: ({ get }) => { + const { page } = get(literatureState); + return page; + }, +}); + +export const tablePageSizeState = selector({ + key: "tablePageSizeState", + get: ({ get }) => { + const { pageSize } = get(literatureState); + return pageSize; + }, + set: ({ set, get }, newPageSize) => { + const currentState = get(literatureState); + const newState: LiteratureStateType = { + ...currentState, + pageSize: newPageSize, + }; + return set(literatureState, newState); + }, +}); + +export const litsCountState = selector({ + key: "litsCountState", + get: ({ get }) => { + const { litsCount } = get(literatureState); + return litsCount; + }, +}); + +export const litsIdsState = selector({ + key: "litsIdsState", + get: ({ get }) => { + const { litsIds } = get(literatureState); + return litsIds; + }, + set: ({ set, get }, newValue) => { + const currentState = get(literatureState); + const newState: LiteratureStateType = { + ...currentState, + litsIds: newValue, + }; + return set(literatureState, newState); + }, +}); + +export const displayedPublications = selector({ + key: "displayedPublications", + get: ({ get }) => { + const page = get(tablePageState); + const pageSize = get(tablePageSizeState); + const publications = get(litsIdsState); + if (isEmpty(publications)) return []; + const rows = getPage(publications, page, pageSize); + return rows; + }, +}); + +export const entitiesState = selector({ + key: "entitiesState", + get: ({ get }) => { + const { entities } = get(literatureState); + return entities; + }, +}); + +export const selectedEntitiesState = selector({ + key: "selectedEntitiesState", + get: ({ get }) => { + const { selectedEntities } = get(literatureState); + return selectedEntities; + }, + set: ({ set, get }, selectedEntities) => { + const currentState = get(literatureState); + const newState: LiteratureStateType = { ...currentState, selectedEntities }; + return set(literatureState, newState); + }, +}); + +export const updateLiteratureState = selector({ + key: "updateLiteratureState", + get: ({ get }) => get(literatureState), + set: ({ set, get }, stateUpdate) => { + const currentState = get(literatureState); + return set(literatureState, { ...currentState, ...stateUpdate }); + }, +}); + +// ------------------------------------------ +// Requests +// ------------------------------------------ + +const fetchLiteraturesFromPMC = async ({ + baseUrl, + requestOptions, +}: { + baseUrl: string; + requestOptions: any; +}) => fetch(baseUrl, requestOptions).then(response => response.json()); + +export const literaturesEuropePMCQuery = selectorFamily({ + key: "literaturesEuropePMCQuery", + get: + ({ literaturesIds }: { literaturesIds: string[] }) => + async () => { + if (literaturesIds.length === 0) return []; + const { baseUrl, requestOptions } = europePmcBiblioSearchPOSTQuery(literaturesIds); + const response = await fetchLiteraturesFromPMC({ + baseUrl, + requestOptions, + }); + if (response.error) { + throw response.error; + } + return response.resultList?.result; + }, +}); + +// gets simialar entities AND the publications info +export const fetchSimilarEntities = ({ + id = "", + threshold = 0.5, + size = 15, + query, + cursor = null, + category = [], + entities = [], + startYear = null, + startMonth = null, + endYear = null, + endMonth = null, +}: LiteratureStateType) => { + const entityNames = category.length === 0 ? null : category; + const ids = entities.map(c => c.object.id); + return client.query({ + query, + variables: { + cursor, + id, + ids, + startYear, + startMonth, + endYear, + endMonth, + threshold, + size, + entityNames, + }, + }); +}; diff --git a/packages/sections/src/common/LiteratureOld/index.js b/packages/sections/src/common/LiteratureOld/index.js new file mode 100644 index 000000000..fa2dac1d5 --- /dev/null +++ b/packages/sections/src/common/LiteratureOld/index.js @@ -0,0 +1,9 @@ +export const definition = { + id: "bibliography1", + name: "Bibliography", + shortName: "B", + hasData: data => (data.similarEntities?.length || 0) > 0, +}; + +export { default as Summary } from "./Summary"; +export { default as Body } from "./Body"; diff --git a/packages/sections/src/disease/BibliographyOld/BibliographyQuery.gql b/packages/sections/src/disease/BibliographyOld/BibliographyQuery.gql new file mode 100644 index 000000000..4f36f6a3e --- /dev/null +++ b/packages/sections/src/disease/BibliographyOld/BibliographyQuery.gql @@ -0,0 +1,58 @@ +query SimilarEntitiesQuery( + $id: String! + $ids: [String!] = [] + $startYear: Int = null + $startMonth: Int = null + $endYear: Int = null + $endMonth: Int = null + $threshold: Float = 0.5 + $size: Int! = 15 + $entityNames: [String!] = [] + $cursor: String = null +) { + disease(efoId: $id) { + id + name + similarEntities( + additionalIds: $ids + threshold: $threshold + size: $size + entityNames: $entityNames + ) { + score + id + object { + ... on Target { + id + approvedSymbol + } + ... on Drug { + id + name + } + ... on Disease { + id + name + } + } + } + literatureOcurrences( + additionalIds: $ids + cursor: $cursor + startYear: $startYear + startMonth: $startMonth + endYear: $endYear + endMonth: $endMonth + ) { + count + filteredCount + earliestPubYear + cursor + rows { + pmid + pmcid + publicationDate + } + } + } +} diff --git a/packages/sections/src/disease/BibliographyOld/BibliographySummaryFragment.gql b/packages/sections/src/disease/BibliographyOld/BibliographySummaryFragment.gql new file mode 100644 index 000000000..fa6318de5 --- /dev/null +++ b/packages/sections/src/disease/BibliographyOld/BibliographySummaryFragment.gql @@ -0,0 +1,6 @@ +fragment DiseaseBibliography on Disease { + literatureOcurrences { + count + filteredCount + } +} diff --git a/packages/sections/src/disease/BibliographyOld/Body.jsx b/packages/sections/src/disease/BibliographyOld/Body.jsx new file mode 100644 index 000000000..953891218 --- /dev/null +++ b/packages/sections/src/disease/BibliographyOld/Body.jsx @@ -0,0 +1,18 @@ +import { Body as Bibliography } from "../../common/LiteratureOld"; +import { definition } from "."; + +import DISEASE_LITERATURE_OCURRENCES from "./BibliographyQuery.gql"; + +function Body({ id, label: name, entity }) { + return ( + + ); +} + +export default Body; diff --git a/packages/sections/src/disease/BibliographyOld/Description.jsx b/packages/sections/src/disease/BibliographyOld/Description.jsx new file mode 100644 index 000000000..afd67b955 --- /dev/null +++ b/packages/sections/src/disease/BibliographyOld/Description.jsx @@ -0,0 +1,18 @@ +import { Link } from "ui"; + +const url = "http://platform-docs.opentargets.org/bibliography"; + +function Description({ name }) { + return ( + <> + Scientific literature mentioning NLP-recognised entity {name} and other + selected co-occurring entities. Source:{" "} + + Open Targets + + . + + ); +} + +export default Description; diff --git a/packages/sections/src/disease/BibliographyOld/Summary.jsx b/packages/sections/src/disease/BibliographyOld/Summary.jsx new file mode 100644 index 000000000..48d8ccafa --- /dev/null +++ b/packages/sections/src/disease/BibliographyOld/Summary.jsx @@ -0,0 +1,31 @@ +import { usePlatformApi, SummaryItem } from "ui"; + +import SIMILARENTTIES_SUMMARY_FRAGMENT from "./BibliographySummaryFragment.gql"; +import { definition } from "."; + +function Summary() { + const request = usePlatformApi(SIMILARENTTIES_SUMMARY_FRAGMENT); + + return ( + + data.literatureOcurrences?.filteredCount > 0 ? ( + <> + {data.literatureOcurrences.filteredCount.toLocaleString()} publication + {data.literatureOcurrences.filteredCount === 1 ? "" : "s"} + + ) : ( + <>no data + ) + } + /> + ); +} + +Summary.fragments = { + DiseaseBibliography: SIMILARENTTIES_SUMMARY_FRAGMENT, +}; + +export default Summary; diff --git a/packages/sections/src/disease/BibliographyOld/index.js b/packages/sections/src/disease/BibliographyOld/index.js new file mode 100644 index 000000000..69789b3ee --- /dev/null +++ b/packages/sections/src/disease/BibliographyOld/index.js @@ -0,0 +1,9 @@ +export const definition = { + id: "bibliography", + name: "Bibliography", + shortName: "B", + hasData: data => data.literatureOcurrences?.filteredCount > 0, +}; + +export { default as Summary } from "./Summary"; +export { default as Body } from "./Body"; diff --git a/packages/sections/src/drug/BibliographyOld/BibliographyQuery.gql b/packages/sections/src/drug/BibliographyOld/BibliographyQuery.gql new file mode 100644 index 000000000..52d127942 --- /dev/null +++ b/packages/sections/src/drug/BibliographyOld/BibliographyQuery.gql @@ -0,0 +1,58 @@ +query SimilarEntitiesQuery( + $id: String! + $ids: [String!] = [] + $startYear: Int = null + $startMonth: Int = null + $endYear: Int = null + $endMonth: Int = null + $threshold: Float = 0.5 + $size: Int! = 15 + $entityNames: [String!] = [] + $cursor: String = null +) { + drug(chemblId: $id) { + id + name + similarEntities( + additionalIds: $ids + threshold: $threshold + size: $size + entityNames: $entityNames + ) { + score + id + object { + ... on Target { + id + approvedSymbol + } + ... on Drug { + id + name + } + ... on Disease { + id + name + } + } + } + literatureOcurrences( + additionalIds: $ids + cursor: $cursor + startYear: $startYear + startMonth: $startMonth + endYear: $endYear + endMonth: $endMonth + ) { + count + filteredCount + earliestPubYear + cursor + rows { + pmid + pmcid + publicationDate + } + } + } +} diff --git a/packages/sections/src/drug/BibliographyOld/BibliographySummaryFragment.gql b/packages/sections/src/drug/BibliographyOld/BibliographySummaryFragment.gql new file mode 100644 index 000000000..3bbb11014 --- /dev/null +++ b/packages/sections/src/drug/BibliographyOld/BibliographySummaryFragment.gql @@ -0,0 +1,6 @@ +fragment DrugBibliography on Drug { + literatureOcurrences { + count + filteredCount + } +} diff --git a/packages/sections/src/drug/BibliographyOld/Body.jsx b/packages/sections/src/drug/BibliographyOld/Body.jsx new file mode 100644 index 000000000..6498bcdb0 --- /dev/null +++ b/packages/sections/src/drug/BibliographyOld/Body.jsx @@ -0,0 +1,22 @@ +import { definition } from "."; +import { Body as Bibliography } from "../../common/Literature"; + +import DRUGS_LITERATURE_OCURRENCES from "./BibliographyQuery.gql"; + +function Body({ id, label: name }) { + + return ( + <> + + + + ); +} + +export default Body; diff --git a/packages/sections/src/drug/BibliographyOld/Description.jsx b/packages/sections/src/drug/BibliographyOld/Description.jsx new file mode 100644 index 000000000..afd67b955 --- /dev/null +++ b/packages/sections/src/drug/BibliographyOld/Description.jsx @@ -0,0 +1,18 @@ +import { Link } from "ui"; + +const url = "http://platform-docs.opentargets.org/bibliography"; + +function Description({ name }) { + return ( + <> + Scientific literature mentioning NLP-recognised entity {name} and other + selected co-occurring entities. Source:{" "} + + Open Targets + + . + + ); +} + +export default Description; diff --git a/packages/sections/src/drug/BibliographyOld/Summary.jsx b/packages/sections/src/drug/BibliographyOld/Summary.jsx new file mode 100644 index 000000000..c3e6a9aa8 --- /dev/null +++ b/packages/sections/src/drug/BibliographyOld/Summary.jsx @@ -0,0 +1,31 @@ +import { SummaryItem, usePlatformApi } from "ui"; + +import { definition } from "."; +import SIMILARENTTIES_SUMMARY_FRAGMENT from "./BibliographySummaryFragment.gql"; + +function Summary() { + const request = usePlatformApi(SIMILARENTTIES_SUMMARY_FRAGMENT); + + return ( + + data.literatureOcurrences?.filteredCount > 0 ? ( + <> + {data.literatureOcurrences.filteredCount.toLocaleString()} publication + {data.literatureOcurrences.filteredCount === 1 ? "" : "s"} + + ) : ( + <>no data + ) + } + /> + ); +} + +Summary.fragments = { + DrugBibliography: SIMILARENTTIES_SUMMARY_FRAGMENT, +}; + +export default Summary; diff --git a/packages/sections/src/drug/BibliographyOld/index.js b/packages/sections/src/drug/BibliographyOld/index.js new file mode 100644 index 000000000..bbb93b9a9 --- /dev/null +++ b/packages/sections/src/drug/BibliographyOld/index.js @@ -0,0 +1,6 @@ +export const definition = { + id: "bibliography", + name: "Bibliography", + shortName: "B", + hasData: data => data.literatureOcurrences?.filteredCount > 0, +}; diff --git a/packages/sections/src/target/BibliographyOld/Body.jsx b/packages/sections/src/target/BibliographyOld/Body.jsx new file mode 100644 index 000000000..ca466edb3 --- /dev/null +++ b/packages/sections/src/target/BibliographyOld/Body.jsx @@ -0,0 +1,17 @@ +import { Body as Bibliography } from "../../common/Literature"; +import { definition } from "."; +import TARGET_LITERATURE_OCURRENCES from "./SimilarEntities.gql"; + +function Body({ id, label: name, entity }) { + return ( + + ); +} + +export default Body; diff --git a/packages/sections/src/target/BibliographyOld/Description.jsx b/packages/sections/src/target/BibliographyOld/Description.jsx new file mode 100644 index 000000000..afd67b955 --- /dev/null +++ b/packages/sections/src/target/BibliographyOld/Description.jsx @@ -0,0 +1,18 @@ +import { Link } from "ui"; + +const url = "http://platform-docs.opentargets.org/bibliography"; + +function Description({ name }) { + return ( + <> + Scientific literature mentioning NLP-recognised entity {name} and other + selected co-occurring entities. Source:{" "} + + Open Targets + + . + + ); +} + +export default Description; diff --git a/packages/sections/src/target/BibliographyOld/SimilarEntities.gql b/packages/sections/src/target/BibliographyOld/SimilarEntities.gql new file mode 100644 index 000000000..d33983f5c --- /dev/null +++ b/packages/sections/src/target/BibliographyOld/SimilarEntities.gql @@ -0,0 +1,58 @@ +query SimilarEntitiesQuery( + $id: String! + $ids: [String!] = [] + $startYear: Int = null + $startMonth: Int = null + $endYear: Int = null + $endMonth: Int = null + $threshold: Float = 0.5 + $size: Int! = 15 + $entityNames: [String!] = [] + $cursor: String = null +) { + target(ensemblId: $id) { + id + approvedName + similarEntities( + additionalIds: $ids + threshold: $threshold + size: $size + entityNames: $entityNames + ) { + id + score + object { + ... on Target { + id + approvedSymbol + } + ... on Drug { + id + name + } + ... on Disease { + id + name + } + } + } + literatureOcurrences( + additionalIds: $ids + cursor: $cursor + startYear: $startYear + startMonth: $startMonth + endYear: $endYear + endMonth: $endMonth + ) { + count + filteredCount + earliestPubYear + cursor + rows { + pmid + pmcid + publicationDate + } + } + } +} diff --git a/packages/sections/src/target/BibliographyOld/SimilarEntitiesSummary.gql b/packages/sections/src/target/BibliographyOld/SimilarEntitiesSummary.gql new file mode 100644 index 000000000..2a65351f8 --- /dev/null +++ b/packages/sections/src/target/BibliographyOld/SimilarEntitiesSummary.gql @@ -0,0 +1,6 @@ +fragment EntitiesSummaryFragment on Target { + literatureOcurrences { + count + filteredCount + } +} diff --git a/packages/sections/src/target/BibliographyOld/Summary.jsx b/packages/sections/src/target/BibliographyOld/Summary.jsx new file mode 100644 index 000000000..c26b2399d --- /dev/null +++ b/packages/sections/src/target/BibliographyOld/Summary.jsx @@ -0,0 +1,31 @@ +import { SummaryItem, usePlatformApi } from "ui"; + +import { definition } from "."; +import SIMILARENTTIES_SUMMARY_FRAGMENT from "./SimilarEntitiesSummary.gql"; + +function Summary() { + const request = usePlatformApi(SIMILARENTTIES_SUMMARY_FRAGMENT); + + return ( + + data.literatureOcurrences?.filteredCount > 0 ? ( + <> + {data.literatureOcurrences.filteredCount.toLocaleString()} publication + {data.literatureOcurrences.filteredCount === 1 ? "" : "s"} + + ) : ( + <>no data + ) + } + /> + ); +} + +Summary.fragments = { + EntitiesSummaryFragment: SIMILARENTTIES_SUMMARY_FRAGMENT, +}; + +export default Summary; diff --git a/packages/sections/src/target/BibliographyOld/index.js b/packages/sections/src/target/BibliographyOld/index.js new file mode 100644 index 000000000..bbb93b9a9 --- /dev/null +++ b/packages/sections/src/target/BibliographyOld/index.js @@ -0,0 +1,6 @@ +export const definition = { + id: "bibliography", + name: "Bibliography", + shortName: "B", + hasData: data => data.literatureOcurrences?.filteredCount > 0, +}; From 7e631fae7d81740748ad3bd05d87b79b1bdb8f78 Mon Sep 17 00:00:00 2001 From: Graham McNeill Date: Thu, 2 May 2024 14:40:52 +0100 Subject: [PATCH 02/10] use react for state management --- apps/platform/src/pages/DrugPage/Profile.jsx | 2 +- .../platform/src/pages/TargetPage/Profile.jsx | 4 +- .../sections/src/common/Literature/Body.jsx | 111 +++--- .../src/common/Literature/Category.jsx | 34 +- .../src/common/Literature/CountInfo.jsx | 13 +- .../{DateFilter.tsx => DateFilter.jsx} | 87 ++--- .../src/common/Literature/Description.jsx | 1 + .../src/common/Literature/Entities.jsx | 55 ++- .../common/Literature/LiteratureContext.tsx | 93 +++++ ...licationsList.jsx => PublicationsList.tsx} | 171 ++++----- .../sections/src/common/Literature/atoms.ts | 338 ------------------ .../src/common/Literature/requests.ts | 51 +++ .../sections/src/common/Literature/types.ts | 95 +++++ packages/sections/src/utils/urls.js | 2 +- 14 files changed, 476 insertions(+), 581 deletions(-) rename packages/sections/src/common/Literature/{DateFilter.tsx => DateFilter.jsx} (72%) create mode 100644 packages/sections/src/common/Literature/LiteratureContext.tsx rename packages/sections/src/common/Literature/{PublicationsList.jsx => PublicationsList.tsx} (56%) delete mode 100644 packages/sections/src/common/Literature/atoms.ts create mode 100644 packages/sections/src/common/Literature/requests.ts create mode 100644 packages/sections/src/common/Literature/types.ts diff --git a/apps/platform/src/pages/DrugPage/Profile.jsx b/apps/platform/src/pages/DrugPage/Profile.jsx index 04e75d3ca..7483bb8a3 100644 --- a/apps/platform/src/pages/DrugPage/Profile.jsx +++ b/apps/platform/src/pages/DrugPage/Profile.jsx @@ -72,7 +72,7 @@ function Profile({ chemblId, name }) { */} - + {/* */} diff --git a/apps/platform/src/pages/TargetPage/Profile.jsx b/apps/platform/src/pages/TargetPage/Profile.jsx index 178086e84..2da57eb2b 100644 --- a/apps/platform/src/pages/TargetPage/Profile.jsx +++ b/apps/platform/src/pages/TargetPage/Profile.jsx @@ -166,9 +166,9 @@ function Profile({ ensgId, symbol }) { }> */} - }> + {/* }> - + */} }> diff --git a/packages/sections/src/common/Literature/Body.jsx b/packages/sections/src/common/Literature/Body.jsx index feb5c8889..ed3f8c50e 100644 --- a/packages/sections/src/common/Literature/Body.jsx +++ b/packages/sections/src/common/Literature/Body.jsx @@ -1,62 +1,75 @@ import { useEffect, useState } from "react"; +import { + LiteratureProvider, + useLiterature, + useLiteratureDispatch, + defaultLiteratureState, +} from "./LiteratureContext"; +import { fetchSimilarEntities } from "./requests"; import { Box } from "@mui/material"; -import { useSetRecoilState, useRecoilValue, useResetRecoilState, RecoilRoot } from "recoil"; import { SectionItem } from "ui"; import PublicationsList from "./PublicationsList"; import Description from "./Description"; -import { literatureState, updateLiteratureState, fetchSimilarEntities } from "./atoms"; import Entities from "./Entities"; import Category from "./Category"; import CountInfo from "./CountInfo"; import { DateFilter } from "./DateFilter"; -function LiteratureList({ id, name, entity, BODY_QUERY, definition }) { - const [requestObj, setRequestObj] = useState({}); +// type LiteratureListParameter = { +// id: string, +// name: string, +// entity: any, // ADD LATER +// BODY_QUERY: string, +// definition: any, // ADD LATER +// }; - const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); - const resetLiteratureState = useResetRecoilState(literatureState); +function LiteratureList( + { id, name, entity, BODY_QUERY, definition }) { + // { id, name, entity, BODY_QUERY, definition }: LiteratureListParameter) { - const bibliographyState = useRecoilValue(literatureState); - const { category, startYear, startMonth, endYear, endMonth } = bibliographyState; + const [requestObj, setRequestObj] = useState({}); + const literature = useLiterature(); + const { category, startYear, startMonth, endYear, endMonth } = literature; + const literatureDispatch = useLiteratureDispatch(); - useEffect( - () => { - async function startRequest() { - const inintRequest = await fetchSimilarEntities({ - id, - query: BODY_QUERY, - category, - startYear, - startMonth, - endYear, - endMonth, - }); - setRequestObj(inintRequest); - const data = inintRequest.data[entity]; - const update = { - entities: data.similarEntities, - litsIds: data.literatureOcurrences?.rows?.map(({ pmid }) => ({ - id: pmid, - status: "ready", - publication: null, - })), - litsCount: data.literatureOcurrences?.filteredCount, - earliestPubYear: data.literatureOcurrences?.earliestPubYear, - cursor: data.literatureOcurrences?.cursor, - id, - query: BODY_QUERY, - globalEntity: entity, - }; - setLiteratureUpdate(update); - } - startRequest(); - return function cleanUp() { - resetLiteratureState(); + useEffect(() => { + async function startRequest() { + const initRequest = await fetchSimilarEntities({ + id, + query: BODY_QUERY, + category, + startYear, + startMonth, + endYear, + endMonth, + }); + setRequestObj(initRequest); + const data = initRequest.data[entity]; + const update = { + entities: data.similarEntities, + litsIds: data.literatureOcurrences?.rows?.map(({ pmid }) => ({ + id: pmid, + status: "ready", + publication: null, + })), + litsCount: data.literatureOcurrences?.filteredCount, + earliestPubYear: data.literatureOcurrences?.earliestPubYear, + cursor: data.literatureOcurrences?.cursor, + id, + query: BODY_QUERY, + globalEntity: entity, }; - }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [] - ); + literatureDispatch({ type: 'stateUpdate', value: update }); + } + startRequest(); + // return function cleanUp() { + // literatureDispatch({ + // type: 'stateUpdate', + // value: defaultLiteratureState + // }); + // }; + }, []); + return ( + - + /> + ); } -export default Body; +export default Body; \ No newline at end of file diff --git a/packages/sections/src/common/Literature/Category.jsx b/packages/sections/src/common/Literature/Category.jsx index 8dd350c99..8569d5a44 100644 --- a/packages/sections/src/common/Literature/Category.jsx +++ b/packages/sections/src/common/Literature/Category.jsx @@ -1,12 +1,8 @@ -import { InputLabel, FormGroup, Checkbox, FormControlLabel } from "@mui/material"; -import { useRecoilState, useRecoilValue, useSetRecoilState } from "recoil"; -import { - selectedCategoriesState, - loadingEntitiesState, - literatureState, - fetchSimilarEntities, - updateLiteratureState, -} from "./atoms"; +import { InputLabel, FormGroup, Checkbox, FormControlLabel } + from "@mui/material"; +import { useLiterature, useSelectedCategories, useLiteratureDispatch } + from "./LiteratureContext"; +import { fetchSimilarEntities } from "./requests"; const toggleValue = (selected, categories) => { const isChecked = categories.indexOf(selected) !== -1; @@ -21,11 +17,10 @@ const categories = [ ]; export default function Category() { - const category = useRecoilValue(selectedCategoriesState); - const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); - const [loadingEntities, setLoadingEntities] = useRecoilState(loadingEntitiesState); - const bibliographyState = useRecoilValue(literatureState); + const literature = useLiterature(); + const category = useSelectedCategories(); + const literatureDispatch = useLiteratureDispatch(); const handleChange = async event => { const { @@ -39,12 +34,10 @@ export default function Category() { endMonth, startYear, startMonth, - } = bibliographyState; - const { - target: { name: clicked }, - } = event; + } = literature; + const { target: { name: clicked } } = event; const newCategories = toggleValue(clicked, bibliographyCategory); - setLoadingEntities(true); + literatureDispatch({ type: 'loadingEntities', value: true }); const request = await fetchSimilarEntities({ query, id, @@ -57,7 +50,6 @@ export default function Category() { startMonth, }); const data = request.data[globalEntity]; - const update = { entities: data.similarEntities, earliestPubYear: data.literatureOcurrences?.earliestPubYear, @@ -65,7 +57,7 @@ export default function Category() { loadingEntities: false, category: newCategories, }; - setLiteratureUpdate(update); + literatureDispatch({ type: 'stateUpdate', value: update }); }; return ( @@ -88,7 +80,7 @@ export default function Category() { onChange={handleChange} name={name} color="primary" - disabled={loadingEntities} + disabled={literature.loadingEntities} /> } label={label} diff --git a/packages/sections/src/common/Literature/CountInfo.jsx b/packages/sections/src/common/Literature/CountInfo.jsx index 241aae271..62f2f6d94 100644 --- a/packages/sections/src/common/Literature/CountInfo.jsx +++ b/packages/sections/src/common/Literature/CountInfo.jsx @@ -1,7 +1,6 @@ import { InputLabel, Box } from "@mui/material"; import { makeStyles } from "@mui/styles"; -import { useRecoilValue } from "recoil"; -import { litsCountState, loadingEntitiesState, tablePageSizeState } from "./atoms"; +import { useLiterature } from "./LiteratureContext"; const useStyles = makeStyles(() => ({ resultCount: { @@ -11,14 +10,12 @@ const useStyles = makeStyles(() => ({ })); function CountInfo() { + const { pageSize, litsCount, loadingEntities } = useLiterature(); const classes = useStyles(); - const pageSize = useRecoilValue(tablePageSizeState); - const count = useRecoilValue(litsCountState); - const loadingEntities = useRecoilValue(loadingEntitiesState); - const getLabelText = () => { if (loadingEntities) return "Loading count..."; - return `Showing ${count > pageSize ? pageSize : count} of ${count} results`; + return `Showing ${ + litsCount > pageSize ? pageSize : litsCount} of ${litsCount} results`; }; return ( @@ -28,4 +25,4 @@ function CountInfo() { ); } -export default CountInfo; +export default CountInfo; \ No newline at end of file diff --git a/packages/sections/src/common/Literature/DateFilter.tsx b/packages/sections/src/common/Literature/DateFilter.jsx similarity index 72% rename from packages/sections/src/common/Literature/DateFilter.tsx rename to packages/sections/src/common/Literature/DateFilter.jsx index 3e9e7a595..879753e13 100644 --- a/packages/sections/src/common/Literature/DateFilter.tsx +++ b/packages/sections/src/common/Literature/DateFilter.jsx @@ -1,13 +1,8 @@ import { useEffect, useState } from "react"; import { FormControl, FormGroup, InputLabel, Slider } from "@mui/material"; -import { useRecoilState, useRecoilValue, useSetRecoilState } from "recoil"; -import { - fetchSimilarEntities, - literatureState, - loadingEntitiesState, - updateLiteratureState, -} from "./atoms"; import { styled } from "@mui/material/styles"; +import { useLiterature, useLiteratureDispatch } from "./LiteratureContext"; +import { fetchSimilarEntities } from "./requests"; const OTSlider = styled(Slider)({ root: { @@ -29,7 +24,7 @@ const DateIndicator = styled("span")({ maxWidth: 80, }); -const monthsBtwnDates = (startDate: Date, endDate: Date) => +const monthsBtwnDates = (startDate, endDate) => Math.max( (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth()), @@ -37,30 +32,31 @@ const monthsBtwnDates = (startDate: Date, endDate: Date) => ); export function DateFilter() { - const [filterDate, setFilterDate] = useState([0, 0]); + + const [filterDate, setFilterDate] = useState([0, 0]); const [numberOfMonths, setNumberOfMonths] = useState(0); const [pubYear, setPubYear] = useState(0); - const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); - const [_, setLoadingEntities] = useRecoilState(loadingEntitiesState); + const literature = useLiterature(); + const literatureDispatch = useLiteratureDispatch(); + const { query, id, category, earliestPubYear, selectedEntities, - cursor, globalEntity, litsIds, pageSize, litsCount, loadingEntities, - } = useRecoilValue(literatureState); + } = literature; - function getDateFromYear(year: number) { + function getDateFromYear(year) { return new Date(year, 0, 1, 1, 1, 1, 1); } - const sumMonthsSinceYear = (year: number) => (value: number) => { + const sumMonthsSinceYear = year => value => { const from = getDateFromYear(year); const date = new Date(from.setMonth(from.getMonth() + value)); return date; @@ -74,11 +70,8 @@ export function DateFilter() { if (earliestPubYear && earliestPubYear !== pubYear) { const earliestDate = getDateFromYear(earliestPubYear); const limit = monthsBtwnDates(earliestDate, new Date()); - const lowerLimit = getLowerLimit(earliestDate); - const higherLimit = getHigherLimit(earliestDate, limit); - setFilterDate([lowerLimit, higherLimit]); setNumberOfMonths(limit); setPubYear(earliestPubYear); @@ -89,15 +82,17 @@ export function DateFilter() { } }, [earliestPubYear]); - function getHigherLimit(earliestDate: Date, limit: number) { + function getHigherLimit(earliestDate, limit) { const oldHigherDate = oldSelectedDate(filterDate[1]); const newHighFilter = monthsBtwnDates(earliestDate, oldHigherDate); const higherLimit = - filterDate[1] > 0 && newHighFilter > 0 && newHighFilter < limit ? newHighFilter : limit; + filterDate[1] > 0 && newHighFilter > 0 && newHighFilter < limit + ? newHighFilter + : limit; return higherLimit; } - function getLowerLimit(earliestDate: Date) { + function getLowerLimit(earliestDate) { if (filterDate[0] == 0) return 0; const oldLowerDate = oldSelectedDate(filterDate[0]); const newLowerFilter = monthsBtwnDates(earliestDate, oldLowerDate); @@ -105,29 +100,24 @@ export function DateFilter() { return lowerLimit; } - const handleChange = async (values: { - startYear: number; - startMonth: number; - endYear: number; - endMonth: number; - }) => { - setLoadingEntities(true); - const entities = selectedEntities as any[]; + const handleChange = async values => { + literatureDispatch({ type: 'loadingEntities', value: true }); const request = await fetchSimilarEntities({ query, id, category, - entities, + entities: selectedEntities, //selectedEntities as any[], cursor: null, - earliestPubYear, - globalEntity, - selectedEntities, - litsIds, - page: 0, - pageSize, - litsCount, - loadingEntities, - ...values, + // ?? FOLLOWING PROPS WHERE BEING PASSED, BUT REQUEST DOESN'T TAKE THEM ??!! + // earliestPubYear, + // globalEntity, + // selectedEntities, + // litsIds, + // page: 0, + // pageSize, + // litsCount, + // loadingEntities, + ...values, // values has startYear, startMonth, endYear, endMonth }); const data = request.data[globalEntity]; const update = { @@ -137,7 +127,7 @@ export function DateFilter() { entities: data.similarEntities, loadingEntities: false, category, - litsIds: data.literatureOcurrences?.rows?.map(({ pmid }: { pmid: any }) => ({ + litsIds: data.literatureOcurrences?.rows?.map(({ pmid }) => ({ id: pmid, status: "ready", publication: null, @@ -148,27 +138,24 @@ export function DateFilter() { selectedEntities, page: 0, pageSize, - ...values, + ...values, // values has startYear, startMonth, endYear, endMonth }; - setLiteratureUpdate(update); + literatureDispatch({ type: 'stateUpdate', value: update }); }; - const valueLabelFormat = (value: number | number[]) => { + const valueLabelFormat = (value) => { if (earliestPubYear) { - const labelDate = selectedDate(value as number); + const labelDate = selectedDate(value); return `${labelDate.getFullYear()}-${labelDate.getMonth() + 1}`; } return "YYYY-MM"; }; - const handleDateRangeChange = (_event: Event, value: number[] | number, _activeThumb: number) => { - setFilterDate(value as number[]); + const handleDateRangeChange = (_event, value, _activeThumb) => { + setFilterDate(value); }; - const handleDateRangeChangeCommitted = ( - _event: Event | React.SyntheticEvent, - value: number | number[] - ) => { + const handleDateRangeChangeCommitted = (_event, value) => { if (Array.isArray(value)) { const startDate = selectedDate(value[0]); const endDate = selectedDate(value[1]); diff --git a/packages/sections/src/common/Literature/Description.jsx b/packages/sections/src/common/Literature/Description.jsx index afd67b955..24307cc36 100644 --- a/packages/sections/src/common/Literature/Description.jsx +++ b/packages/sections/src/common/Literature/Description.jsx @@ -5,6 +5,7 @@ const url = "http://platform-docs.opentargets.org/bibliography"; function Description({ name }) { return ( <> + !! NEW !! Scientific literature mentioning NLP-recognised entity {name} and other selected co-occurring entities. Source:{" "} diff --git a/packages/sections/src/common/Literature/Entities.jsx b/packages/sections/src/common/Literature/Entities.jsx index 3d7a119f2..91600e398 100644 --- a/packages/sections/src/common/Literature/Entities.jsx +++ b/packages/sections/src/common/Literature/Entities.jsx @@ -1,14 +1,7 @@ import { Chip, Grow } from "@mui/material"; import { makeStyles } from "@mui/styles"; -import { useRecoilState, useSetRecoilState, useRecoilValue } from "recoil"; -import { - entitiesState, - selectedEntitiesState, - fetchSimilarEntities, - literatureState, - loadingEntitiesState, - updateLiteratureState, -} from "./atoms"; +import { useLiterature, useLiteratureDispatch } from "./LiteratureContext"; +import { fetchSimilarEntities } from "./requests"; const useStyles = makeStyles(theme => ({ root: { @@ -25,11 +18,14 @@ const useStyles = makeStyles(theme => ({ })); function EntitiesToSelect({ id }) { - const entities = useRecoilValue(entitiesState); - const bibliographyState = useRecoilValue(literatureState); - const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); - const [selectedChips, setSelectedChips] = useRecoilState(selectedEntitiesState); - const [loadingEntities, setLoadingEntities] = useRecoilState(loadingEntitiesState); + + const literature = useLiterature(); + const { + entities, + selectedEntities: selectedChips, + loadingEntities, + } = literature; + const literatureDispatch = useLiteratureDispatch(); const handleSelectChip = async e => { const { @@ -41,7 +37,7 @@ function EntitiesToSelect({ id }) { endMonth, startYear, startMonth, - } = bibliographyState; + } = literature; const newChips = [ ...selectedChips, { @@ -52,8 +48,8 @@ function EntitiesToSelect({ id }) { }, }, ]; - setSelectedChips(newChips); - setLoadingEntities(true); + literatureDispatch({ type: 'selectedEntities', value: newChips }); + literatureDispatch({ type: 'loadingEntities', value: true }); const request = await fetchSimilarEntities({ query, id: bibliographyId, @@ -78,7 +74,7 @@ function EntitiesToSelect({ id }) { loadingEntities: false, page: 0, }; - setLiteratureUpdate(update); + literatureDispatch({ type: 'stateUpdate', value: update }); }; const validateEntity = entity => { @@ -121,12 +117,14 @@ function EntitiesToSelect({ id }) { } export default function Entities({ name, id }) { + const classes = useStyles(); - - const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); - const bibliographyState = useRecoilValue(literatureState); - const [loadingEntities, setLoadingEntities] = useRecoilState(loadingEntitiesState); - const [selectedChips, setSelectedChips] = useRecoilState(selectedEntitiesState); + const literature = useLiterature(); + const { + selectedEntities: selectedChips, + loadingEntities, + } = literature; + const literatureDispatch = useLiteratureDispatch(); const handleDeleteChip = async index => { const { @@ -138,10 +136,11 @@ export default function Entities({ name, id }) { endMonth, startYear, startMonth, - } = bibliographyState; - const newChips = [...selectedChips.slice(0, index), ...selectedChips.slice(index + 1)]; - setSelectedChips(newChips); - setLoadingEntities(true); + } = literature; + const newChips = + [...selectedChips.slice(0, index), ...selectedChips.slice(index + 1)]; + literatureDispatch({ type: 'selectedEntities', value: newChips }); + literatureDispatch({ type: 'loadingEntities', value: true }); const request = await fetchSimilarEntities({ query, id: bibliographyId, @@ -166,7 +165,7 @@ export default function Entities({ name, id }) { loadingEntities: false, page: 0, }; - setLiteratureUpdate(update); + literatureDispatch({ type: 'stateUpdate', value: update }); }; return ( diff --git a/packages/sections/src/common/Literature/LiteratureContext.tsx b/packages/sections/src/common/Literature/LiteratureContext.tsx new file mode 100644 index 000000000..1a7978056 --- /dev/null +++ b/packages/sections/src/common/Literature/LiteratureContext.tsx @@ -0,0 +1,93 @@ +import isEmpty from "lodash/isEmpty"; +import { createContext, useContext, useReducer } from 'react'; +import type { LiteratureStateType } from './types'; +import { getPage } from "ui"; + +export const defaultLiteratureState: LiteratureStateType = { + id: "", + cursor: "", + category: ["disease", "drug", "target"], + query: null, + globalEntity: null, + entities: [], + selectedEntities: [], + startYear: null, + startMonth: null, + endYear: null, + endMonth: null, + earliestPubYear: 0, + litsIds: [], + page: 0, + pageSize: 5, + litsCount: 0, + loadingEntities: false, +}; + +const LiteratureContext = createContext(null as any); +const LiteratureDispatchContext = createContext(null as any); + +function literatureReducer(literatureState: LiteratureStateType, action: any) { + console.log('LITERATURE REDUCER CALLED!'); + switch (action.type) { + case 'loadingEntities': + return { + ...literatureState, + loadingEntities: action.value, + }; + case 'tablePageSize': + return { + ...literatureState, + pageSize: action.value, + }; + case 'litsIds': + return { + ...literatureState, + litsIds: action.value, + }; + case 'selectedEntities': + return { + ...literatureState, + selectedEntities: action.value, + }; + case 'stateUpdate': + return { + ...literatureState, + ...action.value, + }; + default: + throw Error('invalid action type'); + } +} + +export function LiteratureProvider({ children }) { + + const [literature, literatureDispatch] = + useReducer(literatureReducer, defaultLiteratureState); + + return ( + + + {children} + + + ); + +} + +export function useLiterature() { + return useContext(LiteratureContext); +} + +export function useLiteratureDispatch() { + return useContext(LiteratureDispatchContext); +} + +export function useSelectedCategories() { + const { category } = useLiterature(); + return [...category].sort(); +} + +export function useDisplayedPublications() { + const { page, pageSize, litsIds } = useLiterature(); + return isEmpty(litsIds) ? [] : getPage(litsIds, page, pageSize); +} \ No newline at end of file diff --git a/packages/sections/src/common/Literature/PublicationsList.jsx b/packages/sections/src/common/Literature/PublicationsList.tsx similarity index 56% rename from packages/sections/src/common/Literature/PublicationsList.jsx rename to packages/sections/src/common/Literature/PublicationsList.tsx index eec522374..d44aca5a6 100644 --- a/packages/sections/src/common/Literature/PublicationsList.jsx +++ b/packages/sections/src/common/Literature/PublicationsList.tsx @@ -1,24 +1,13 @@ -import { useEffect } from "react"; -import { useRecoilState, useRecoilValue, useSetRecoilState, useRecoilCallback } from "recoil"; +import { useEffect, useState } from "react"; import { Box, Grid, Fade, Skeleton } from "@mui/material"; import { makeStyles } from "@mui/styles"; import { PublicationWrapper, Table } from "ui"; import Loader from "./Loader"; - +import type { PublicationType, RowType } from "./types"; import { - litsIdsState, - loadingEntitiesState, - displayedPublications, - literaturesEuropePMCQuery, - parsePublications, - tablePageState, - litsCountState, - litsCursorState, - literatureState, - fetchSimilarEntities, - updateLiteratureState, - tablePageSizeState, -} from "./atoms"; + useDisplayedPublications, useLiterature, useLiteratureDispatch, +} from "./LiteratureContext"; +import { fetchSimilarEntities, literaturesEuropePMCQuery } from "./requests"; const useStyles = makeStyles(() => ({ root: { @@ -26,6 +15,27 @@ const useStyles = makeStyles(() => ({ }, })); +function parsePublications(publications: PublicationType[]) { + return publications.map(pub => { + const row: RowType = { + source: pub.source, + patentDetails: pub.patentDetails, + europePmcId: pub.id, + fullTextOpen: !!(pub.inEPMC === "Y" || pub.inPMC === "Y"), + title: pub.title, + year: pub.pubYear, + abstract: pub.abstractText, + openAccess: pub.isOpenAccess !== "N", + authors: pub.authorList?.author || [], + journal: { + ...pub.journalInfo, + page: pub.pageInfo, + }, + }; + return row; + }); +} + function SkeletonRow() { return ( @@ -48,51 +58,42 @@ function SkeletonRow() { } function PublicationsList({ hideSearch = false }) { - const classes = useStyles(); - const lits = useRecoilValue(litsIdsState); - const [loadingEntities, setLoadingEntities] = useRecoilState(loadingEntitiesState); - const count = useRecoilValue(litsCountState); - const cursor = useRecoilValue(litsCursorState); - const displayedPubs = useRecoilValue(displayedPublications); - const bibliographyState = useRecoilValue(literatureState); - const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); - const page = useRecoilValue(tablePageState); - const pageSize = useRecoilValue(tablePageSizeState); - - // function to request 'ready' literatures ids - const syncLiteraturesState = useRecoilCallback(({ snapshot, set }) => async () => { - const AllLits = await snapshot.getPromise(litsIdsState); - const readyForRequest = AllLits.filter(x => x.status === "ready").map(x => x.id); - - if (readyForRequest.length === 0) return; - const queryResult = await snapshot.getPromise( - literaturesEuropePMCQuery({ - literaturesIds: readyForRequest, - }) - ); - - const parsedPublications = parsePublications(queryResult); - - const mapedResults = new Map(parsedPublications.map(key => [key.europePmcId, key])); - - const updatedPublications = AllLits.map(x => { - const publication = mapedResults.get(x.id); - if (x.status === "loaded") return x; - const status = publication ? "loaded" : "missing"; - return { ...x, status, publication }; - }); - set(litsIdsState, updatedPublications); - }); - useEffect( - () => { - if (lits.length !== 0) syncLiteraturesState(); - }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [lits] - ); + const [publicationDetails, setPublicationDetails] = useState(new Map); + const classes = useStyles(); + const literature = useLiterature(); + const { + loadingEntities, + litsCount: count, + cursor, + page, + pageSize, + litsIds: lits, + } = literature; + const displayedPubs = useDisplayedPublications(); + const literatureDispatch = useLiteratureDispatch(); + + // get publications details from Europe PMC + useEffect(() => { + const fetchFunction = async() => { + const missingDetails = + lits.filter(lit => !publicationDetails.has(lit.id)); + if (missingDetails.length === 0) return; + const queryResult = await literaturesEuropePMCQuery({ + literaturesIds: missingDetails.map(x => x.id) + }); + setPublicationDetails(currentMap => { + const newMap = new Map(currentMap); + for (const p of parsePublications(queryResult)) { + newMap.set(p.europePmcId, p); + }; + return newMap; + }); + }; + fetchFunction().catch(console.error); + }, [literature]); - const handleRowsPerPageChange = useRecoilCallback(({ snapshot }) => async newPageSize => { + const handleRowsPerPageChange = async newPageSize => { const pageSizeInt = Number(newPageSize); const expected = pageSizeInt * page + pageSizeInt; if (expected > lits.length && cursor !== null) { @@ -107,41 +108,42 @@ function PublicationsList({ hideSearch = false }) { endMonth, startYear, startMonth, - } = bibliographyState; - setLoadingEntities(true); + } = literature; + literatureDispatch({ type: 'loadingEntities', value: true }); const request = await fetchSimilarEntities({ query, id, category, entities: selectedEntities, cursor: newCursor, - page: 0, endYear, endMonth, startYear, startMonth, }); - setLoadingEntities(false); + literatureDispatch({ type: 'loadingEntities', value: false }); const data = request.data[globalEntity]; - const loadedPublications = await snapshot.getPromise(litsIdsState); const newLits = data.literatureOcurrences?.rows?.map(({ pmid }) => ({ id: pmid, status: "ready", publication: null, })); const update = { - litsIds: [...loadedPublications, ...newLits], + litsIds: [...lits, ...newLits], cursor: data.literatureOcurrences?.cursor, page: 0, pageSize: pageSizeInt, }; - setLiteratureUpdate(update); + literatureDispatch({ type: 'stateUpdate', value: update }); } else { - setLiteratureUpdate({ page: 0, pageSize: pageSizeInt }); + literatureDispatch({ + type: 'stateUpdate', + value: { page: 0, pageSize: pageSizeInt } + }); } - }); + }; - const handlePageChange = useRecoilCallback(({ snapshot }) => async newPage => { + const handlePageChange = async newPage => { const newPageInt = Number(newPage); if (pageSize * newPageInt + pageSize > lits.length && cursor !== null) { const { @@ -155,8 +157,8 @@ function PublicationsList({ hideSearch = false }) { endMonth, startYear, startMonth, - } = bibliographyState; - setLoadingEntities(true); + } = literature; + literatureDispatch({ type: 'loadingEntities', value: true }); const request = await fetchSimilarEntities({ query, id, @@ -168,32 +170,35 @@ function PublicationsList({ hideSearch = false }) { startYear, startMonth, }); - setLoadingEntities(false); + literatureDispatch({ type: 'loadingEntities', value: false }); const data = request.data[globalEntity]; - const loadedPublications = await snapshot.getPromise(litsIdsState); const newLits = data.literatureOcurrences?.rows?.map(({ pmid }) => ({ id: pmid, status: "ready", publication: null, })); const update = { - litsIds: [...loadedPublications, ...newLits], + litsIds: [...lits, ...newLits], cursor: data.literatureOcurrences?.cursor, page: newPageInt, }; - setLiteratureUpdate(update); + literatureDispatch({ type: 'stateUpdate', value: update }); } else { - setLiteratureUpdate({ page: newPageInt }); + literatureDispatch({ + type: 'stateUpdate', + value: ({ page: newPageInt }) + }); } - }); + }; const columns = [ { id: "publications", label: " ", - renderCell: ({ publication, status }) => { - if (status === "ready") return ; - if (status === "missing") return null; + renderCell({ id }) { + if (!publicationDetails?.has(id)) return ; + const publication = publicationDetails.get(id); + if (!publication) return null; return ( ); } -export default PublicationsList; +export default PublicationsList; \ No newline at end of file diff --git a/packages/sections/src/common/Literature/atoms.ts b/packages/sections/src/common/Literature/atoms.ts deleted file mode 100644 index 184d64acd..000000000 --- a/packages/sections/src/common/Literature/atoms.ts +++ /dev/null @@ -1,338 +0,0 @@ -import isEmpty from "lodash/isEmpty"; -import { atom, selectorFamily, selector, DefaultValue } from "recoil"; -import { getPage } from "ui"; -import client from "../../client"; -import { europePmcBiblioSearchPOSTQuery } from "../../utils/urls"; - -// ------------------------------------------ -// Helpers -// ------------------------------------------ - -type AuthorListType = { - fullName: string; - firstName: string; - lastName: string; - initials: string; - authorId: { - type: string; - value: string; - }; - authorAffiliationDetailsList: { - authorAffiliation: { - affiliation: string; - }[]; - }; -}; - -type JournalInfoType = { - issue: string; - volume: string; - journalIssueId: number; - dateOfPublication: string; - monthOfPublication: number; - yearOfPublication: number; - printPublicationDate: string; - journal: { - title: string; - medlineAbbreviation: string; - isoabbreviation: string; - nlmid: string; - issn: string; - essn: string; - }; -}; - -type PublicationType = { - source: string; - patentDetails: any; - id: string; - inEPMC: string; - inPMC: string; - title: string; - pubYear: string; - abstractText: string; - isOpenAccess: string; - authorList: { - author: AuthorListType; - }; - journalInfo: JournalInfoType; - pageInfo: string; -}; - -type RowType = { - source: string; - patentDetails: any; - europePmcId: string; - fullTextOpen: boolean; - title: string; - year: string; - abstract: string; - openAccess: boolean; - authors: AuthorListType; - journal: JournalInfoType & { page: string }; -}; - -export const parsePublications = (publications: PublicationType[]) => - publications.map(pub => { - const row: RowType = { - source: pub.source, - patentDetails: pub.patentDetails, - europePmcId: pub.id, - fullTextOpen: !!(pub.inEPMC === "Y" || pub.inPMC === "Y"), - title: pub.title, - year: pub.pubYear, - abstract: pub.abstractText, - openAccess: pub.isOpenAccess !== "N", - authors: pub.authorList?.author || [], - journal: { - ...pub.journalInfo, - page: pub.pageInfo, - }, - }; - return row; - }); - -type LiteratureStateType = { - id: string; - cursor: string | null; - threshold?: number; - size?: number; - category: string[]; - query: any | null; - globalEntity: any | null; - entities: any[]; - selectedEntities: any[] | DefaultValue; - startYear: number | null; - startMonth: number | null; - endYear: number | null; - endMonth: number | null; - earliestPubYear: number; - litsIds: - | { - id: string; - status: string; - publication: null; - }[] - | DefaultValue; - page: number; - pageSize: number | DefaultValue; - litsCount: number; - loadingEntities: boolean | DefaultValue; -}; - -// ------------------------------------------ -// ATOMS -// ------------------------------------------ - -const defaultState: LiteratureStateType = { - id: "", - cursor: "", - category: ["disease", "drug", "target"], - query: null, - globalEntity: null, - entities: [], - selectedEntities: [], - startYear: null, - startMonth: null, - endYear: null, - endMonth: null, - earliestPubYear: 0, - litsIds: [], - page: 0, - pageSize: 5, - litsCount: 0, - loadingEntities: false, -}; - -export const literatureState = atom({ - key: "literatureState", - default: defaultState, -}); - -// ------------------------------------------ -// SELECTORS -// ------------------------------------------ -export const loadingEntitiesState = selector({ - key: "loadingEntitiesState", - get: ({ get }) => { - const { loadingEntities } = get(literatureState); - return loadingEntities; - }, - set: ({ set, get }, newStatus) => { - const currentState = get(literatureState); - const newState: LiteratureStateType = { - ...currentState, - loadingEntities: newStatus, - }; - return set(literatureState, newState); - }, -}); - -export const selectedCategoriesState = selector({ - key: "selectedCategoriesState", - get: ({ get }) => { - const { category } = get(literatureState); - const sortedCategories = [...category].sort(); - return sortedCategories; - }, -}); - -export const litsCursorState = selector({ - key: "litsCursorState", - get: ({ get }) => { - const { cursor } = get(literatureState); - return cursor; - }, -}); - -export const tablePageState = selector({ - key: "tablePageState", - get: ({ get }) => { - const { page } = get(literatureState); - return page; - }, -}); - -export const tablePageSizeState = selector({ - key: "tablePageSizeState", - get: ({ get }) => { - const { pageSize } = get(literatureState); - return pageSize; - }, - set: ({ set, get }, newPageSize) => { - const currentState = get(literatureState); - const newState: LiteratureStateType = { - ...currentState, - pageSize: newPageSize, - }; - return set(literatureState, newState); - }, -}); - -export const litsCountState = selector({ - key: "litsCountState", - get: ({ get }) => { - const { litsCount } = get(literatureState); - return litsCount; - }, -}); - -export const litsIdsState = selector({ - key: "litsIdsState", - get: ({ get }) => { - const { litsIds } = get(literatureState); - return litsIds; - }, - set: ({ set, get }, newValue) => { - const currentState = get(literatureState); - const newState: LiteratureStateType = { - ...currentState, - litsIds: newValue, - }; - return set(literatureState, newState); - }, -}); - -export const displayedPublications = selector({ - key: "displayedPublications", - get: ({ get }) => { - const page = get(tablePageState); - const pageSize = get(tablePageSizeState); - const publications = get(litsIdsState); - if (isEmpty(publications)) return []; - const rows = getPage(publications, page, pageSize); - return rows; - }, -}); - -export const entitiesState = selector({ - key: "entitiesState", - get: ({ get }) => { - const { entities } = get(literatureState); - return entities; - }, -}); - -export const selectedEntitiesState = selector({ - key: "selectedEntitiesState", - get: ({ get }) => { - const { selectedEntities } = get(literatureState); - return selectedEntities; - }, - set: ({ set, get }, selectedEntities) => { - const currentState = get(literatureState); - const newState: LiteratureStateType = { ...currentState, selectedEntities }; - return set(literatureState, newState); - }, -}); - -export const updateLiteratureState = selector({ - key: "updateLiteratureState", - get: ({ get }) => get(literatureState), - set: ({ set, get }, stateUpdate) => { - const currentState = get(literatureState); - return set(literatureState, { ...currentState, ...stateUpdate }); - }, -}); - -// ------------------------------------------ -// Requests -// ------------------------------------------ - -const fetchLiteraturesFromPMC = async ({ - baseUrl, - requestOptions, -}: { - baseUrl: string; - requestOptions: any; -}) => fetch(baseUrl, requestOptions).then(response => response.json()); - -export const literaturesEuropePMCQuery = selectorFamily({ - key: "literaturesEuropePMCQuery", - get: - ({ literaturesIds }: { literaturesIds: string[] }) => - async () => { - if (literaturesIds.length === 0) return []; - const { baseUrl, requestOptions } = europePmcBiblioSearchPOSTQuery(literaturesIds); - const response = await fetchLiteraturesFromPMC({ - baseUrl, - requestOptions, - }); - if (response.error) { - throw response.error; - } - return response.resultList?.result; - }, -}); - -export const fetchSimilarEntities = ({ - id = "", - threshold = 0.5, - size = 15, - query, - cursor = null, - category = [], - entities = [], - startYear = null, - startMonth = null, - endYear = null, - endMonth = null, -}: LiteratureStateType) => { - const entityNames = category.length === 0 ? null : category; - const ids = entities.map(c => c.object.id); - return client.query({ - query, - variables: { - cursor, - id, - ids, - startYear, - startMonth, - endYear, - endMonth, - threshold, - size, - entityNames, - }, - }); -}; diff --git a/packages/sections/src/common/Literature/requests.ts b/packages/sections/src/common/Literature/requests.ts new file mode 100644 index 000000000..1a2b9db8c --- /dev/null +++ b/packages/sections/src/common/Literature/requests.ts @@ -0,0 +1,51 @@ +import client from "../../client"; +import { europePmcBiblioSearchPOSTQuery } from "../../utils/urls"; + +export async function literaturesEuropePMCQuery({ literaturesIds }) { + // console.log('PMC request!'); + if (literaturesIds.length === 0) return []; + const { baseUrl, requestOptions } = + europePmcBiblioSearchPOSTQuery(literaturesIds); + const response = + await fetch(baseUrl, requestOptions).then(response => response.json()); + if (response.error) throw response.error; + return response.resultList?.result; +}; + +export const fetchSimilarEntities = ({ + id = "", + threshold = 0.5, + size = 15, + query, + cursor = null, + category = [], + entities = [], + startYear = null, + startMonth = null, + endYear = null, + endMonth = null, +// DO NOT GIVE PARAM A TYPE FOR NOW SINCE TS COMPLAINS IF ANY MISSING PROPS - THE +// TYPE DEFN SAYS THEY CAN BE NULL BUT THIS IS NOT THE SAME AS MISSING (UNDEFINED) +// }: LiteratureStateType) => { +}) => { + const entityNames = category.length === 0 ? null : category; + // USE SQUARE BRACKETS TO STOP TYPESCRIPT COMPLAINING: + // https://stackoverflow.com/questions/44147937/property-does-not-exist-on-type-never + // const ids = entities.map(c => c.object.id); + const ids = entities.map(c => c['object']['id']); + return client.query({ + query, + variables: { + cursor, + id, + ids, + startYear, + startMonth, + endYear, + endMonth, + threshold, + size, + entityNames, + }, + }); +}; \ No newline at end of file diff --git a/packages/sections/src/common/Literature/types.ts b/packages/sections/src/common/Literature/types.ts new file mode 100644 index 000000000..8618e4756 --- /dev/null +++ b/packages/sections/src/common/Literature/types.ts @@ -0,0 +1,95 @@ +// !! NOTES !! +// - FOR NOW HAVE REPLACED RECOIL'S DefaultValue WITH null + + +type AuthorListType = { + fullName: string; + firstName: string; + lastName: string; + initials: string; + authorId: { + type: string; + value: string; + }; + authorAffiliationDetailsList: { + authorAffiliation: { + affiliation: string; + }[]; + }; + }; + + type JournalInfoType = { + issue: string; + volume: string; + journalIssueId: number; + dateOfPublication: string; + monthOfPublication: number; + yearOfPublication: number; + printPublicationDate: string; + journal: { + title: string; + medlineAbbreviation: string; + isoabbreviation: string; + nlmid: string; + issn: string; + essn: string; + }; + }; + + export type PublicationType = { + source: string; + patentDetails: any; + id: string; + inEPMC: string; + inPMC: string; + title: string; + pubYear: string; + abstractText: string; + isOpenAccess: string; + authorList: { + author: AuthorListType; + }; + journalInfo: JournalInfoType; + pageInfo: string; + }; + + export type RowType = { + source: string; + patentDetails: any; + europePmcId: string; + fullTextOpen: boolean; + title: string; + year: string; + abstract: string; + openAccess: boolean; + authors: AuthorListType; + journal: JournalInfoType & { page: string }; + }; + + export type LiteratureStateType = { + id: string; + cursor: string | null; + threshold?: number; + size?: number; + category: string[]; + query: any | null; + globalEntity: any | null; + entities: any[]; + selectedEntities: any[] | null; // DefaultValue; + startYear: number | null; + startMonth: number | null; + endYear: number | null; + endMonth: number | null; + earliestPubYear: number; + litsIds: + | { + id: string; + status: string; + publication: null; + }[] + | null; // DefaultValue; + page: number; + pageSize: number | null; // DefaultValue; + litsCount: number; + loadingEntities: boolean | null; // DefaultValue; + }; \ No newline at end of file diff --git a/packages/sections/src/utils/urls.js b/packages/sections/src/utils/urls.js index d949278f9..7ef544c27 100644 --- a/packages/sections/src/utils/urls.js +++ b/packages/sections/src/utils/urls.js @@ -43,7 +43,7 @@ export function europePmcSearchPOSTQuery(ids) { return { baseUrl, formBody }; } -export function europePmcBiblioSearchPOSTQuery(ids, size = 25) { +export function europePmcBiblioSearchPOSTQuery(ids, size = 25) { const baseUrl = "https://www.ebi.ac.uk/europepmc/webservices/rest/searchPOST"; const query = ids.join(" OR ext_id:"); const bodyOptions = { From d4ca4bf06ae1be1e91144d50926c3862ff0c1eab Mon Sep 17 00:00:00 2001 From: Graham McNeill Date: Fri, 10 May 2024 17:16:39 +0100 Subject: [PATCH 03/10] fix: move PMC lit details to context --- .../sections/src/common/Literature/Body.jsx | 6 +- .../src/common/Literature/DateFilter.jsx | 6 +- .../src/common/Literature/Entities.jsx | 12 +- .../common/Literature/LiteratureContext.tsx | 43 +++++-- .../common/Literature/PublicationsList.tsx | 113 ++++++++++-------- .../src/common/Literature/requests.ts | 1 - .../sections/src/common/Literature/types.ts | 13 +- 7 files changed, 104 insertions(+), 90 deletions(-) diff --git a/packages/sections/src/common/Literature/Body.jsx b/packages/sections/src/common/Literature/Body.jsx index ed3f8c50e..b69cd5625 100644 --- a/packages/sections/src/common/Literature/Body.jsx +++ b/packages/sections/src/common/Literature/Body.jsx @@ -47,11 +47,7 @@ function LiteratureList( const data = initRequest.data[entity]; const update = { entities: data.similarEntities, - litsIds: data.literatureOcurrences?.rows?.map(({ pmid }) => ({ - id: pmid, - status: "ready", - publication: null, - })), + litsIds: data.literatureOcurrences?.rows?.map(({ pmid }) => pmid), litsCount: data.literatureOcurrences?.filteredCount, earliestPubYear: data.literatureOcurrences?.earliestPubYear, cursor: data.literatureOcurrences?.cursor, diff --git a/packages/sections/src/common/Literature/DateFilter.jsx b/packages/sections/src/common/Literature/DateFilter.jsx index 879753e13..359e94fcf 100644 --- a/packages/sections/src/common/Literature/DateFilter.jsx +++ b/packages/sections/src/common/Literature/DateFilter.jsx @@ -127,11 +127,7 @@ export function DateFilter() { entities: data.similarEntities, loadingEntities: false, category, - litsIds: data.literatureOcurrences?.rows?.map(({ pmid }) => ({ - id: pmid, - status: "ready", - publication: null, - })), + litsIds: data.literatureOcurrences?.rows?.map(({ pmid }) => pmid), litsCount: data.literatureOcurrences?.filteredCount, earliestPubYear: data.literatureOcurrences?.earliestPubYear, globalEntity, diff --git a/packages/sections/src/common/Literature/Entities.jsx b/packages/sections/src/common/Literature/Entities.jsx index 91600e398..7657fefc0 100644 --- a/packages/sections/src/common/Literature/Entities.jsx +++ b/packages/sections/src/common/Literature/Entities.jsx @@ -63,11 +63,7 @@ function EntitiesToSelect({ id }) { const data = request.data[globalEntity]; const update = { entities: data.similarEntities, - litsIds: data.literatureOcurrences?.rows?.map(({ pmid }) => ({ - id: pmid, - status: "ready", - publication: null, - })), + litsIds: data.literatureOcurrences?.rows?.map(({ pmid }) => pmid), litsCount: data.literatureOcurrences?.filteredCount, earliestPubYear: data.literatureOcurrences?.earliestPubYear, cursor: data.literatureOcurrences?.cursor, @@ -154,11 +150,7 @@ export default function Entities({ name, id }) { const data = request.data[globalEntity]; const update = { entities: data.similarEntities, - litsIds: data.literatureOcurrences?.rows?.map(({ pmid }) => ({ - id: pmid, - status: "ready", - publication: null, - })), + litsIds: data.literatureOcurrences?.rows?.map(({ pmid }) => pmid), litsCount: data.literatureOcurrences?.filteredCount, earliestPubYear: data.literatureOcurrences?.earliestPubYear, cursor: data.literatureOcurrences?.cursor, diff --git a/packages/sections/src/common/Literature/LiteratureContext.tsx b/packages/sections/src/common/Literature/LiteratureContext.tsx index 1a7978056..f0a21b267 100644 --- a/packages/sections/src/common/Literature/LiteratureContext.tsx +++ b/packages/sections/src/common/Literature/LiteratureContext.tsx @@ -1,6 +1,6 @@ import isEmpty from "lodash/isEmpty"; import { createContext, useContext, useReducer } from 'react'; -import type { LiteratureStateType } from './types'; +import type { LiteratureStateType, DetailsStateType } from './types'; import { getPage } from "ui"; export const defaultLiteratureState: LiteratureStateType = { @@ -26,8 +26,11 @@ export const defaultLiteratureState: LiteratureStateType = { const LiteratureContext = createContext(null as any); const LiteratureDispatchContext = createContext(null as any); +const DetailsContext = createContext(null as any); +const DetailsDispatchContext = createContext(null as any); + function literatureReducer(literatureState: LiteratureStateType, action: any) { - console.log('LITERATURE REDUCER CALLED!'); + console.log(`LITERATURE REDUCER: ${action.type}`); switch (action.type) { case 'loadingEntities': return { @@ -39,11 +42,6 @@ function literatureReducer(literatureState: LiteratureStateType, action: any) { ...literatureState, pageSize: action.value, }; - case 'litsIds': - return { - ...literatureState, - litsIds: action.value, - }; case 'selectedEntities': return { ...literatureState, @@ -59,15 +57,36 @@ function literatureReducer(literatureState: LiteratureStateType, action: any) { } } +function detailsReducer(detailsState: DetailsStateType, action: any) { + console.log(`DETAILS REDUCER: ${action.type}`); + let newObj; + switch (action.type) { + case 'addDetails': + return { ...detailsState, ...action.value }; + case 'setToLoading': + newObj = { ...detailsState }; + for (const id of action.value) { + newObj[id] = 'loading'; + } + return newObj; + } +} + export function LiteratureProvider({ children }) { const [literature, literatureDispatch] = useReducer(literatureReducer, defaultLiteratureState); + const [details, detailsDispatch] = useReducer(detailsReducer, {}); + return ( - {children} + + + {children} + + ); @@ -90,4 +109,12 @@ export function useSelectedCategories() { export function useDisplayedPublications() { const { page, pageSize, litsIds } = useLiterature(); return isEmpty(litsIds) ? [] : getPage(litsIds, page, pageSize); +} + +export function useDetails() { + return useContext(DetailsContext); +} + +export function useDetailsDispatch() { + return useContext(DetailsDispatchContext); } \ No newline at end of file diff --git a/packages/sections/src/common/Literature/PublicationsList.tsx b/packages/sections/src/common/Literature/PublicationsList.tsx index d44aca5a6..a0eb9fb90 100644 --- a/packages/sections/src/common/Literature/PublicationsList.tsx +++ b/packages/sections/src/common/Literature/PublicationsList.tsx @@ -1,13 +1,18 @@ -import { useEffect, useState } from "react"; +import { useEffect } from "react"; import { Box, Grid, Fade, Skeleton } from "@mui/material"; import { makeStyles } from "@mui/styles"; import { PublicationWrapper, Table } from "ui"; import Loader from "./Loader"; -import type { PublicationType, RowType } from "./types"; +import type { PublicationType } from "./types"; import { - useDisplayedPublications, useLiterature, useLiteratureDispatch, + useDisplayedPublications, + useLiterature, + useLiteratureDispatch, + useDetails, + useDetailsDispatch, } from "./LiteratureContext"; import { fetchSimilarEntities, literaturesEuropePMCQuery } from "./requests"; +import { DetailsStateType } from "./types"; const useStyles = makeStyles(() => ({ root: { @@ -15,9 +20,12 @@ const useStyles = makeStyles(() => ({ }, })); -function parsePublications(publications: PublicationType[]) { - return publications.map(pub => { - const row: RowType = { + + +function parsePublications(publications: PublicationType[]): DetailsStateType { + const obj: DetailsStateType = {}; + for (const pub of publications) { + obj[pub.id] = { source: pub.source, patentDetails: pub.patentDetails, europePmcId: pub.id, @@ -32,8 +40,8 @@ function parsePublications(publications: PublicationType[]) { page: pub.pageInfo, }, }; - return row; - }); + } + return obj; } function SkeletonRow() { @@ -59,7 +67,6 @@ function SkeletonRow() { function PublicationsList({ hideSearch = false }) { - const [publicationDetails, setPublicationDetails] = useState(new Map); const classes = useStyles(); const literature = useLiterature(); const { @@ -68,35 +75,37 @@ function PublicationsList({ hideSearch = false }) { cursor, page, pageSize, - litsIds: lits, + litsIds, } = literature; + const details = useDetails(); const displayedPubs = useDisplayedPublications(); const literatureDispatch = useLiteratureDispatch(); + const detailsDispatch = useDetailsDispatch(); // get publications details from Europe PMC useEffect(() => { const fetchFunction = async() => { - const missingDetails = - lits.filter(lit => !publicationDetails.has(lit.id)); + const missingDetails = litsIds.filter((id: string) => !details[id]); if (missingDetails.length === 0) return; + detailsDispatch({ + type: 'setToLoading', + value: missingDetails, + }) const queryResult = await literaturesEuropePMCQuery({ - literaturesIds: missingDetails.map(x => x.id) + literaturesIds: missingDetails }); - setPublicationDetails(currentMap => { - const newMap = new Map(currentMap); - for (const p of parsePublications(queryResult)) { - newMap.set(p.europePmcId, p); - }; - return newMap; + detailsDispatch({ + type: 'addDetails', + value: parsePublications(queryResult), }); }; fetchFunction().catch(console.error); }, [literature]); - const handleRowsPerPageChange = async newPageSize => { + const handleRowsPerPageChange = async (newPageSize: string) => { const pageSizeInt = Number(newPageSize); const expected = pageSizeInt * page + pageSizeInt; - if (expected > lits.length && cursor !== null) { + if (expected > litsIds.length && cursor !== null) { const { query, id, @@ -123,13 +132,10 @@ function PublicationsList({ hideSearch = false }) { }); literatureDispatch({ type: 'loadingEntities', value: false }); const data = request.data[globalEntity]; - const newLits = data.literatureOcurrences?.rows?.map(({ pmid }) => ({ - id: pmid, - status: "ready", - publication: null, - })); + const newLitsIds = + data.literatureOcurrences?.rows?.map(({ pmid }) => pmid) ?? []; const update = { - litsIds: [...lits, ...newLits], + litsIds: [...litsIds, ...newLitsIds], cursor: data.literatureOcurrences?.cursor, page: 0, pageSize: pageSizeInt, @@ -143,9 +149,9 @@ function PublicationsList({ hideSearch = false }) { } }; - const handlePageChange = async newPage => { + const handlePageChange = async (newPage: string) => { const newPageInt = Number(newPage); - if (pageSize * newPageInt + pageSize > lits.length && cursor !== null) { + if (pageSize * newPageInt + pageSize > litsIds.length && cursor !== null) { const { query, id, @@ -172,13 +178,10 @@ function PublicationsList({ hideSearch = false }) { }); literatureDispatch({ type: 'loadingEntities', value: false }); const data = request.data[globalEntity]; - const newLits = data.literatureOcurrences?.rows?.map(({ pmid }) => ({ - id: pmid, - status: "ready", - publication: null, - })); + const newLitsIds = + data.literatureOcurrences?.rows?.map(({ pmid }) => pmid) ?? []; const update = { - litsIds: [...lits, ...newLits], + litsIds: [...litsIds, ...newLitsIds], cursor: data.literatureOcurrences?.cursor, page: newPageInt, }; @@ -195,24 +198,28 @@ function PublicationsList({ hideSearch = false }) { { id: "publications", label: " ", - renderCell({ id }) { - if (!publicationDetails?.has(id)) return ; - const publication = publicationDetails.get(id); - if (!publication) return null; - return ( - - ); + renderCell(id) { + const det = details[id]; + if (det === 'loading') { + return ; + } else if (!det) { + return null; + } else { + return ( + + ) + } }, filterValue: ({ row: publication }) => `${publication.journal.journal?.title} ${publication?.title} ${publication?.year} diff --git a/packages/sections/src/common/Literature/requests.ts b/packages/sections/src/common/Literature/requests.ts index 1a2b9db8c..f1e66a61f 100644 --- a/packages/sections/src/common/Literature/requests.ts +++ b/packages/sections/src/common/Literature/requests.ts @@ -2,7 +2,6 @@ import client from "../../client"; import { europePmcBiblioSearchPOSTQuery } from "../../utils/urls"; export async function literaturesEuropePMCQuery({ literaturesIds }) { - // console.log('PMC request!'); if (literaturesIds.length === 0) return []; const { baseUrl, requestOptions } = europePmcBiblioSearchPOSTQuery(literaturesIds); diff --git a/packages/sections/src/common/Literature/types.ts b/packages/sections/src/common/Literature/types.ts index 8618e4756..c8af87483 100644 --- a/packages/sections/src/common/Literature/types.ts +++ b/packages/sections/src/common/Literature/types.ts @@ -81,15 +81,12 @@ type AuthorListType = { endYear: number | null; endMonth: number | null; earliestPubYear: number; - litsIds: - | { - id: string; - status: string; - publication: null; - }[] - | null; // DefaultValue; - page: number; + litsIds: string[]; pageSize: number | null; // DefaultValue; litsCount: number; loadingEntities: boolean | null; // DefaultValue; + }; + + export type DetailsStateType = { + [index: string]: undefined | 'loading' | RowType; }; \ No newline at end of file From 50b88f69cc8b9b521f8dc61eed08a1c099eff52c Mon Sep 17 00:00:00 2001 From: Graham McNeill Date: Thu, 11 Jul 2024 10:56:04 +0100 Subject: [PATCH 04/10] remove comments --- packages/sections/src/common/Literature/DateFilter.jsx | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/sections/src/common/Literature/DateFilter.jsx b/packages/sections/src/common/Literature/DateFilter.jsx index 359e94fcf..28cc7927a 100644 --- a/packages/sections/src/common/Literature/DateFilter.jsx +++ b/packages/sections/src/common/Literature/DateFilter.jsx @@ -108,15 +108,6 @@ export function DateFilter() { category, entities: selectedEntities, //selectedEntities as any[], cursor: null, - // ?? FOLLOWING PROPS WHERE BEING PASSED, BUT REQUEST DOESN'T TAKE THEM ??!! - // earliestPubYear, - // globalEntity, - // selectedEntities, - // litsIds, - // page: 0, - // pageSize, - // litsCount, - // loadingEntities, ...values, // values has startYear, startMonth, endYear, endMonth }); const data = request.data[globalEntity]; From dd60a97cb7731e1b52a4242ece6fdad2faa42e08 Mon Sep 17 00:00:00 2001 From: Graham McNeill Date: Thu, 11 Jul 2024 11:31:17 +0100 Subject: [PATCH 05/10] show new and old widget on all pages --- apps/platform/src/pages/DrugPage/Profile.jsx | 2 +- apps/platform/src/pages/TargetPage/Profile.jsx | 4 ++-- packages/sections/src/drug/BibliographyOld/Body.jsx | 2 +- packages/sections/src/target/BibliographyOld/Body.jsx | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/platform/src/pages/DrugPage/Profile.jsx b/apps/platform/src/pages/DrugPage/Profile.jsx index 7483bb8a3..04e75d3ca 100644 --- a/apps/platform/src/pages/DrugPage/Profile.jsx +++ b/apps/platform/src/pages/DrugPage/Profile.jsx @@ -72,7 +72,7 @@ function Profile({ chemblId, name }) { */} - {/* */} + diff --git a/apps/platform/src/pages/TargetPage/Profile.jsx b/apps/platform/src/pages/TargetPage/Profile.jsx index 2da57eb2b..178086e84 100644 --- a/apps/platform/src/pages/TargetPage/Profile.jsx +++ b/apps/platform/src/pages/TargetPage/Profile.jsx @@ -166,9 +166,9 @@ function Profile({ ensgId, symbol }) { }> */} - {/* }> + }> - */} + }> diff --git a/packages/sections/src/drug/BibliographyOld/Body.jsx b/packages/sections/src/drug/BibliographyOld/Body.jsx index 6498bcdb0..d301d245d 100644 --- a/packages/sections/src/drug/BibliographyOld/Body.jsx +++ b/packages/sections/src/drug/BibliographyOld/Body.jsx @@ -1,5 +1,5 @@ import { definition } from "."; -import { Body as Bibliography } from "../../common/Literature"; +import { Body as Bibliography } from "../../common/LiteratureOld"; import DRUGS_LITERATURE_OCURRENCES from "./BibliographyQuery.gql"; diff --git a/packages/sections/src/target/BibliographyOld/Body.jsx b/packages/sections/src/target/BibliographyOld/Body.jsx index ca466edb3..f8bc8a8da 100644 --- a/packages/sections/src/target/BibliographyOld/Body.jsx +++ b/packages/sections/src/target/BibliographyOld/Body.jsx @@ -1,4 +1,4 @@ -import { Body as Bibliography } from "../../common/Literature"; +import { Body as Bibliography } from "../../common/LiteratureOld"; import { definition } from "."; import TARGET_LITERATURE_OCURRENCES from "./SimilarEntities.gql"; From d542c303c43b8e3fb0165c2650dc27e925745e39 Mon Sep 17 00:00:00 2001 From: Graham McNeill Date: Fri, 19 Jul 2024 13:34:23 +0100 Subject: [PATCH 06/10] remove old files --- .../src/pages/DiseasePage/Profile.jsx | 4 - apps/platform/src/pages/DrugPage/Profile.jsx | 2 - .../platform/src/pages/TargetPage/Profile.jsx | 4 - .../src/common/Literature/Description.jsx | 1 - .../common/Literature/LiteratureContext.tsx | 7 +- .../src/common/Literature/requests.ts | 2 +- .../src/common/LiteratureOld/Body.jsx | 97 ----- .../src/common/LiteratureOld/Category.jsx | 100 ------ .../src/common/LiteratureOld/CountInfo.jsx | 31 -- .../src/common/LiteratureOld/DateFilter.tsx | 223 ------------ .../src/common/LiteratureOld/Description.jsx | 18 - .../src/common/LiteratureOld/Entities.jsx | 199 ---------- .../src/common/LiteratureOld/Loader.jsx | 38 -- .../common/LiteratureOld/PublicationsList.jsx | 242 ------------- .../src/common/LiteratureOld/Summary.jsx | 31 -- .../LiteratureOld/TimeTravelObserver.jsx | 52 --- .../src/common/LiteratureOld/atoms.ts | 339 ------------------ .../src/common/LiteratureOld/index.js | 9 - .../BibliographyOld/BibliographyQuery.gql | 58 --- .../BibliographySummaryFragment.gql | 6 - .../src/disease/BibliographyOld/Body.jsx | 18 - .../disease/BibliographyOld/Description.jsx | 18 - .../src/disease/BibliographyOld/Summary.jsx | 31 -- .../src/disease/BibliographyOld/index.js | 9 - .../BibliographyOld/BibliographyQuery.gql | 58 --- .../BibliographySummaryFragment.gql | 6 - .../src/drug/BibliographyOld/Body.jsx | 22 -- .../src/drug/BibliographyOld/Description.jsx | 18 - .../src/drug/BibliographyOld/Summary.jsx | 31 -- .../src/drug/BibliographyOld/index.js | 6 - .../src/target/BibliographyOld/Body.jsx | 17 - .../target/BibliographyOld/Description.jsx | 18 - .../BibliographyOld/SimilarEntities.gql | 58 --- .../SimilarEntitiesSummary.gql | 6 - .../src/target/BibliographyOld/Summary.jsx | 31 -- .../src/target/BibliographyOld/index.js | 6 - 36 files changed, 4 insertions(+), 1812 deletions(-) delete mode 100644 packages/sections/src/common/LiteratureOld/Body.jsx delete mode 100644 packages/sections/src/common/LiteratureOld/Category.jsx delete mode 100644 packages/sections/src/common/LiteratureOld/CountInfo.jsx delete mode 100644 packages/sections/src/common/LiteratureOld/DateFilter.tsx delete mode 100644 packages/sections/src/common/LiteratureOld/Description.jsx delete mode 100644 packages/sections/src/common/LiteratureOld/Entities.jsx delete mode 100644 packages/sections/src/common/LiteratureOld/Loader.jsx delete mode 100644 packages/sections/src/common/LiteratureOld/PublicationsList.jsx delete mode 100644 packages/sections/src/common/LiteratureOld/Summary.jsx delete mode 100644 packages/sections/src/common/LiteratureOld/TimeTravelObserver.jsx delete mode 100644 packages/sections/src/common/LiteratureOld/atoms.ts delete mode 100644 packages/sections/src/common/LiteratureOld/index.js delete mode 100644 packages/sections/src/disease/BibliographyOld/BibliographyQuery.gql delete mode 100644 packages/sections/src/disease/BibliographyOld/BibliographySummaryFragment.gql delete mode 100644 packages/sections/src/disease/BibliographyOld/Body.jsx delete mode 100644 packages/sections/src/disease/BibliographyOld/Description.jsx delete mode 100644 packages/sections/src/disease/BibliographyOld/Summary.jsx delete mode 100644 packages/sections/src/disease/BibliographyOld/index.js delete mode 100644 packages/sections/src/drug/BibliographyOld/BibliographyQuery.gql delete mode 100644 packages/sections/src/drug/BibliographyOld/BibliographySummaryFragment.gql delete mode 100644 packages/sections/src/drug/BibliographyOld/Body.jsx delete mode 100644 packages/sections/src/drug/BibliographyOld/Description.jsx delete mode 100644 packages/sections/src/drug/BibliographyOld/Summary.jsx delete mode 100644 packages/sections/src/drug/BibliographyOld/index.js delete mode 100644 packages/sections/src/target/BibliographyOld/Body.jsx delete mode 100644 packages/sections/src/target/BibliographyOld/Description.jsx delete mode 100644 packages/sections/src/target/BibliographyOld/SimilarEntities.gql delete mode 100644 packages/sections/src/target/BibliographyOld/SimilarEntitiesSummary.gql delete mode 100644 packages/sections/src/target/BibliographyOld/Summary.jsx delete mode 100644 packages/sections/src/target/BibliographyOld/index.js diff --git a/apps/platform/src/pages/DiseasePage/Profile.jsx b/apps/platform/src/pages/DiseasePage/Profile.jsx index 77c1a1b8a..61fcc3d09 100644 --- a/apps/platform/src/pages/DiseasePage/Profile.jsx +++ b/apps/platform/src/pages/DiseasePage/Profile.jsx @@ -23,7 +23,6 @@ import ProfileHeader from "./ProfileHeader"; // const OntologySection = lazy(() => import("sections/src/disease/Ontology/Body")); // const KnownDrugsSection = lazy(() => import("sections/src/disease/KnownDrugs/Body")); const BibliographySection = lazy(() => import("sections/src/disease/Bibliography/Body")); -const BibliographySectionOld = lazy(() => import("sections/src/disease/BibliographyOld/Body")); // const PhenotypesSection = lazy(() => import("sections/src/disease/Phenotypes/Body")); // const OTProjectsSection = lazy(() => import("sections/src/disease/OTProjects/Body")); @@ -81,9 +80,6 @@ function Profile({ efoId, name }) { }> - }> - - {/* }> diff --git a/apps/platform/src/pages/DrugPage/Profile.jsx b/apps/platform/src/pages/DrugPage/Profile.jsx index 04e75d3ca..868b5e90f 100644 --- a/apps/platform/src/pages/DrugPage/Profile.jsx +++ b/apps/platform/src/pages/DrugPage/Profile.jsx @@ -15,7 +15,6 @@ import BibliographySummary from "sections/src/drug/Bibliography/Summary"; // import PharmacogenomicsSection from "sections/src/drug/Pharmacogenomics/Body"; // import AdverseEventsSection from "sections/src/drug/AdverseEvents/Body"; import BibliographySection from "sections/src/drug/Bibliography/Body"; -import BibliographySectionOld from "sections/src/drug/BibliographyOld/Body"; import client from "../../client"; import ProfileHeader from "./ProfileHeader"; @@ -73,7 +72,6 @@ function Profile({ chemblId, name }) { */} - ); diff --git a/apps/platform/src/pages/TargetPage/Profile.jsx b/apps/platform/src/pages/TargetPage/Profile.jsx index 178086e84..a85cc03e4 100644 --- a/apps/platform/src/pages/TargetPage/Profile.jsx +++ b/apps/platform/src/pages/TargetPage/Profile.jsx @@ -52,7 +52,6 @@ import client from "../../client"; // import("sections/src/target/SubcellularLocation/Body") // ); const BibliographySection = lazy(() => import("sections/src/target/Bibliography/Body")); -const BibliographySectionOld = lazy(() => import("sections/src/target/BibliographyOld/Body")); const summaries = [ // KnownDrugsSummary, @@ -169,9 +168,6 @@ function Profile({ ensgId, symbol }) { }> - }> - - ); diff --git a/packages/sections/src/common/Literature/Description.jsx b/packages/sections/src/common/Literature/Description.jsx index 24307cc36..afd67b955 100644 --- a/packages/sections/src/common/Literature/Description.jsx +++ b/packages/sections/src/common/Literature/Description.jsx @@ -5,7 +5,6 @@ const url = "http://platform-docs.opentargets.org/bibliography"; function Description({ name }) { return ( <> - !! NEW !! Scientific literature mentioning NLP-recognised entity {name} and other selected co-occurring entities. Source:{" "} diff --git a/packages/sections/src/common/Literature/LiteratureContext.tsx b/packages/sections/src/common/Literature/LiteratureContext.tsx index f0a21b267..504cf8cae 100644 --- a/packages/sections/src/common/Literature/LiteratureContext.tsx +++ b/packages/sections/src/common/Literature/LiteratureContext.tsx @@ -17,7 +17,6 @@ export const defaultLiteratureState: LiteratureStateType = { endMonth: null, earliestPubYear: 0, litsIds: [], - page: 0, pageSize: 5, litsCount: 0, loadingEntities: false, @@ -59,16 +58,16 @@ function literatureReducer(literatureState: LiteratureStateType, action: any) { function detailsReducer(detailsState: DetailsStateType, action: any) { console.log(`DETAILS REDUCER: ${action.type}`); - let newObj; switch (action.type) { case 'addDetails': return { ...detailsState, ...action.value }; - case 'setToLoading': - newObj = { ...detailsState }; + case 'setToLoading': { + const newObj = { ...detailsState }; for (const id of action.value) { newObj[id] = 'loading'; } return newObj; + } } } diff --git a/packages/sections/src/common/Literature/requests.ts b/packages/sections/src/common/Literature/requests.ts index f1e66a61f..3d38ffa50 100644 --- a/packages/sections/src/common/Literature/requests.ts +++ b/packages/sections/src/common/Literature/requests.ts @@ -10,7 +10,7 @@ export async function literaturesEuropePMCQuery({ literaturesIds }) { if (response.error) throw response.error; return response.resultList?.result; }; - + export const fetchSimilarEntities = ({ id = "", threshold = 0.5, diff --git a/packages/sections/src/common/LiteratureOld/Body.jsx b/packages/sections/src/common/LiteratureOld/Body.jsx deleted file mode 100644 index feb5c8889..000000000 --- a/packages/sections/src/common/LiteratureOld/Body.jsx +++ /dev/null @@ -1,97 +0,0 @@ -import { useEffect, useState } from "react"; -import { Box } from "@mui/material"; -import { useSetRecoilState, useRecoilValue, useResetRecoilState, RecoilRoot } from "recoil"; -import { SectionItem } from "ui"; -import PublicationsList from "./PublicationsList"; -import Description from "./Description"; -import { literatureState, updateLiteratureState, fetchSimilarEntities } from "./atoms"; -import Entities from "./Entities"; -import Category from "./Category"; -import CountInfo from "./CountInfo"; -import { DateFilter } from "./DateFilter"; - -function LiteratureList({ id, name, entity, BODY_QUERY, definition }) { - const [requestObj, setRequestObj] = useState({}); - - const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); - const resetLiteratureState = useResetRecoilState(literatureState); - - const bibliographyState = useRecoilValue(literatureState); - const { category, startYear, startMonth, endYear, endMonth } = bibliographyState; - - useEffect( - () => { - async function startRequest() { - const inintRequest = await fetchSimilarEntities({ - id, - query: BODY_QUERY, - category, - startYear, - startMonth, - endYear, - endMonth, - }); - setRequestObj(inintRequest); - const data = inintRequest.data[entity]; - const update = { - entities: data.similarEntities, - litsIds: data.literatureOcurrences?.rows?.map(({ pmid }) => ({ - id: pmid, - status: "ready", - publication: null, - })), - litsCount: data.literatureOcurrences?.filteredCount, - earliestPubYear: data.literatureOcurrences?.earliestPubYear, - cursor: data.literatureOcurrences?.cursor, - id, - query: BODY_QUERY, - globalEntity: entity, - }; - setLiteratureUpdate(update); - } - startRequest(); - return function cleanUp() { - resetLiteratureState(); - }; - }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [] - ); - return ( - } - renderBody={() => ( - <> - - - - - - - - - - - )} - /> - ); -} - -function Body({ definition, name, id, entity, BODY_QUERY }) { - return ( - - - - ); -} - -export default Body; diff --git a/packages/sections/src/common/LiteratureOld/Category.jsx b/packages/sections/src/common/LiteratureOld/Category.jsx deleted file mode 100644 index 8dd350c99..000000000 --- a/packages/sections/src/common/LiteratureOld/Category.jsx +++ /dev/null @@ -1,100 +0,0 @@ -import { InputLabel, FormGroup, Checkbox, FormControlLabel } from "@mui/material"; -import { useRecoilState, useRecoilValue, useSetRecoilState } from "recoil"; -import { - selectedCategoriesState, - loadingEntitiesState, - literatureState, - fetchSimilarEntities, - updateLiteratureState, -} from "./atoms"; - -const toggleValue = (selected, categories) => { - const isChecked = categories.indexOf(selected) !== -1; - if (!isChecked) return [...categories, selected]; - return [...categories.filter(value => value !== selected).sort()]; -}; - -const categories = [ - { name: "target", label: "Target" }, - { name: "disease", label: "Disease" }, - { name: "drug", label: "Drug" }, -]; - -export default function Category() { - const category = useRecoilValue(selectedCategoriesState); - const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); - const [loadingEntities, setLoadingEntities] = useRecoilState(loadingEntitiesState); - - const bibliographyState = useRecoilValue(literatureState); - - const handleChange = async event => { - const { - query, - id, - category: bibliographyCategory, - selectedEntities, - globalEntity, - cursor, - endYear, - endMonth, - startYear, - startMonth, - } = bibliographyState; - const { - target: { name: clicked }, - } = event; - const newCategories = toggleValue(clicked, bibliographyCategory); - setLoadingEntities(true); - const request = await fetchSimilarEntities({ - query, - id, - category: newCategories, - entities: selectedEntities, - cursor, - endYear, - endMonth, - startYear, - startMonth, - }); - const data = request.data[globalEntity]; - - const update = { - entities: data.similarEntities, - earliestPubYear: data.literatureOcurrences?.earliestPubYear, - litsCount: data.literatureOcurrences?.filteredCount, - loadingEntities: false, - category: newCategories, - }; - setLiteratureUpdate(update); - }; - - return ( -
- - Tag category: - - - {categories.map(({ name, label }) => ( - - } - label={label} - /> - ))} - -
- ); -} diff --git a/packages/sections/src/common/LiteratureOld/CountInfo.jsx b/packages/sections/src/common/LiteratureOld/CountInfo.jsx deleted file mode 100644 index 241aae271..000000000 --- a/packages/sections/src/common/LiteratureOld/CountInfo.jsx +++ /dev/null @@ -1,31 +0,0 @@ -import { InputLabel, Box } from "@mui/material"; -import { makeStyles } from "@mui/styles"; -import { useRecoilValue } from "recoil"; -import { litsCountState, loadingEntitiesState, tablePageSizeState } from "./atoms"; - -const useStyles = makeStyles(() => ({ - resultCount: { - // marginLeft: "2rem", - // marginRight: "6rem", - }, -})); - -function CountInfo() { - const classes = useStyles(); - const pageSize = useRecoilValue(tablePageSizeState); - const count = useRecoilValue(litsCountState); - const loadingEntities = useRecoilValue(loadingEntitiesState); - - const getLabelText = () => { - if (loadingEntities) return "Loading count..."; - return `Showing ${count > pageSize ? pageSize : count} of ${count} results`; - }; - - return ( - - {getLabelText()} - - ); -} - -export default CountInfo; diff --git a/packages/sections/src/common/LiteratureOld/DateFilter.tsx b/packages/sections/src/common/LiteratureOld/DateFilter.tsx deleted file mode 100644 index 3e9e7a595..000000000 --- a/packages/sections/src/common/LiteratureOld/DateFilter.tsx +++ /dev/null @@ -1,223 +0,0 @@ -import { useEffect, useState } from "react"; -import { FormControl, FormGroup, InputLabel, Slider } from "@mui/material"; -import { useRecoilState, useRecoilValue, useSetRecoilState } from "recoil"; -import { - fetchSimilarEntities, - literatureState, - loadingEntitiesState, - updateLiteratureState, -} from "./atoms"; -import { styled } from "@mui/material/styles"; - -const OTSlider = styled(Slider)({ - root: { - padding: "0 10px !important", - }, - mark: { - backgroundColor: "#b8b8b8", - width: 10, - height: 1, - marginLeft: -4, - }, - valueLabel: { - zIndex: "9999", - }, -}); - -const DateIndicator = styled("span")({ - minWidth: 65, - maxWidth: 80, -}); - -const monthsBtwnDates = (startDate: Date, endDate: Date) => - Math.max( - (endDate.getFullYear() - startDate.getFullYear()) * 12 + - (endDate.getMonth() - startDate.getMonth()), - 0 - ); - -export function DateFilter() { - const [filterDate, setFilterDate] = useState([0, 0]); - const [numberOfMonths, setNumberOfMonths] = useState(0); - const [pubYear, setPubYear] = useState(0); - const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); - const [_, setLoadingEntities] = useRecoilState(loadingEntitiesState); - const { - query, - id, - category, - earliestPubYear, - selectedEntities, - cursor, - globalEntity, - litsIds, - pageSize, - litsCount, - loadingEntities, - } = useRecoilValue(literatureState); - - function getDateFromYear(year: number) { - return new Date(year, 0, 1, 1, 1, 1, 1); - } - - const sumMonthsSinceYear = (year: number) => (value: number) => { - const from = getDateFromYear(year); - const date = new Date(from.setMonth(from.getMonth() + value)); - return date; - }; - - const selectedDate = sumMonthsSinceYear(earliestPubYear); - const oldSelectedDate = sumMonthsSinceYear(pubYear); - - useEffect(() => { - // the publication year has changed - if (earliestPubYear && earliestPubYear !== pubYear) { - const earliestDate = getDateFromYear(earliestPubYear); - const limit = monthsBtwnDates(earliestDate, new Date()); - - const lowerLimit = getLowerLimit(earliestDate); - - const higherLimit = getHigherLimit(earliestDate, limit); - - setFilterDate([lowerLimit, higherLimit]); - setNumberOfMonths(limit); - setPubYear(earliestPubYear); - } else { - setPubYear(0); - setNumberOfMonths(0); - setFilterDate([0, 0]); - } - }, [earliestPubYear]); - - function getHigherLimit(earliestDate: Date, limit: number) { - const oldHigherDate = oldSelectedDate(filterDate[1]); - const newHighFilter = monthsBtwnDates(earliestDate, oldHigherDate); - const higherLimit = - filterDate[1] > 0 && newHighFilter > 0 && newHighFilter < limit ? newHighFilter : limit; - return higherLimit; - } - - function getLowerLimit(earliestDate: Date) { - if (filterDate[0] == 0) return 0; - const oldLowerDate = oldSelectedDate(filterDate[0]); - const newLowerFilter = monthsBtwnDates(earliestDate, oldLowerDate); - const lowerLimit = newLowerFilter > 0 ? newLowerFilter : 0; - return lowerLimit; - } - - const handleChange = async (values: { - startYear: number; - startMonth: number; - endYear: number; - endMonth: number; - }) => { - setLoadingEntities(true); - const entities = selectedEntities as any[]; - const request = await fetchSimilarEntities({ - query, - id, - category, - entities, - cursor: null, - earliestPubYear, - globalEntity, - selectedEntities, - litsIds, - page: 0, - pageSize, - litsCount, - loadingEntities, - ...values, - }); - const data = request.data[globalEntity]; - const update = { - id, - cursor: data.literatureOcurrences?.cursor, - query, - entities: data.similarEntities, - loadingEntities: false, - category, - litsIds: data.literatureOcurrences?.rows?.map(({ pmid }: { pmid: any }) => ({ - id: pmid, - status: "ready", - publication: null, - })), - litsCount: data.literatureOcurrences?.filteredCount, - earliestPubYear: data.literatureOcurrences?.earliestPubYear, - globalEntity, - selectedEntities, - page: 0, - pageSize, - ...values, - }; - setLiteratureUpdate(update); - }; - - const valueLabelFormat = (value: number | number[]) => { - if (earliestPubYear) { - const labelDate = selectedDate(value as number); - return `${labelDate.getFullYear()}-${labelDate.getMonth() + 1}`; - } - return "YYYY-MM"; - }; - - const handleDateRangeChange = (_event: Event, value: number[] | number, _activeThumb: number) => { - setFilterDate(value as number[]); - }; - - const handleDateRangeChangeCommitted = ( - _event: Event | React.SyntheticEvent, - value: number | number[] - ) => { - if (Array.isArray(value)) { - const startDate = selectedDate(value[0]); - const endDate = selectedDate(value[1]); - handleChange({ - startYear: startDate.getFullYear(), - startMonth: startDate.getMonth() + 1, - endYear: endDate.getFullYear(), - endMonth: endDate.getMonth() + 1, - }); - } - }; - - return ( -
- Date Filter: - - - {valueLabelFormat(filterDate[0])} - "date-range-slider"} - max={numberOfMonths} - valueLabelFormat={valueLabelFormat} - /> - {valueLabelFormat(filterDate[1])} - - -
- ); -} diff --git a/packages/sections/src/common/LiteratureOld/Description.jsx b/packages/sections/src/common/LiteratureOld/Description.jsx deleted file mode 100644 index afd67b955..000000000 --- a/packages/sections/src/common/LiteratureOld/Description.jsx +++ /dev/null @@ -1,18 +0,0 @@ -import { Link } from "ui"; - -const url = "http://platform-docs.opentargets.org/bibliography"; - -function Description({ name }) { - return ( - <> - Scientific literature mentioning NLP-recognised entity {name} and other - selected co-occurring entities. Source:{" "} - - Open Targets - - . - - ); -} - -export default Description; diff --git a/packages/sections/src/common/LiteratureOld/Entities.jsx b/packages/sections/src/common/LiteratureOld/Entities.jsx deleted file mode 100644 index 3d7a119f2..000000000 --- a/packages/sections/src/common/LiteratureOld/Entities.jsx +++ /dev/null @@ -1,199 +0,0 @@ -import { Chip, Grow } from "@mui/material"; -import { makeStyles } from "@mui/styles"; -import { useRecoilState, useSetRecoilState, useRecoilValue } from "recoil"; -import { - entitiesState, - selectedEntitiesState, - fetchSimilarEntities, - literatureState, - loadingEntitiesState, - updateLiteratureState, -} from "./atoms"; - -const useStyles = makeStyles(theme => ({ - root: { - display: "flex", - flexWrap: "wrap", - "& > *": { - margin: `${theme.spacing(0.5)} !important`, - }, - }, - loadingContainer: { - display: "flex", - margin: "10px", - }, -})); - -function EntitiesToSelect({ id }) { - const entities = useRecoilValue(entitiesState); - const bibliographyState = useRecoilValue(literatureState); - const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); - const [selectedChips, setSelectedChips] = useRecoilState(selectedEntitiesState); - const [loadingEntities, setLoadingEntities] = useRecoilState(loadingEntitiesState); - - const handleSelectChip = async e => { - const { - query, - id: bibliographyId, - category, - globalEntity, - endYear, - endMonth, - startYear, - startMonth, - } = bibliographyState; - const newChips = [ - ...selectedChips, - { - score: e.score, - object: { - name: e.object.name || e.object.approvedSymbol, - id: e.object.id, - }, - }, - ]; - setSelectedChips(newChips); - setLoadingEntities(true); - const request = await fetchSimilarEntities({ - query, - id: bibliographyId, - category, - entities: newChips, - endYear, - endMonth, - startYear, - startMonth, - }); - const data = request.data[globalEntity]; - const update = { - entities: data.similarEntities, - litsIds: data.literatureOcurrences?.rows?.map(({ pmid }) => ({ - id: pmid, - status: "ready", - publication: null, - })), - litsCount: data.literatureOcurrences?.filteredCount, - earliestPubYear: data.literatureOcurrences?.earliestPubYear, - cursor: data.literatureOcurrences?.cursor, - loadingEntities: false, - page: 0, - }; - setLiteratureUpdate(update); - }; - - const validateEntity = entity => { - if (id === entity.object?.id) return null; - if (selectedChips.find(s => s.object.id === entity.object.id)) return null; - return entity; - }; - - return entities.map(e => { - if (!e.object) - return ( - - - - ); - return validateEntity(e) ? ( - - { - handleSelectChip(e); - }} - title={`Score: ${e.score} ID: ${e.object.id}`} - color="primary" - variant="outlined" - /> - - ) : null; - }); -} - -export default function Entities({ name, id }) { - const classes = useStyles(); - - const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); - const bibliographyState = useRecoilValue(literatureState); - const [loadingEntities, setLoadingEntities] = useRecoilState(loadingEntitiesState); - const [selectedChips, setSelectedChips] = useRecoilState(selectedEntitiesState); - - const handleDeleteChip = async index => { - const { - query, - id: bibliographyId, - category, - globalEntity, - endYear, - endMonth, - startYear, - startMonth, - } = bibliographyState; - const newChips = [...selectedChips.slice(0, index), ...selectedChips.slice(index + 1)]; - setSelectedChips(newChips); - setLoadingEntities(true); - const request = await fetchSimilarEntities({ - query, - id: bibliographyId, - category, - entities: newChips, - endYear, - endMonth, - startYear, - startMonth, - }); - const data = request.data[globalEntity]; - const update = { - entities: data.similarEntities, - litsIds: data.literatureOcurrences?.rows?.map(({ pmid }) => ({ - id: pmid, - status: "ready", - publication: null, - })), - litsCount: data.literatureOcurrences?.filteredCount, - earliestPubYear: data.literatureOcurrences?.earliestPubYear, - cursor: data.literatureOcurrences?.cursor, - loadingEntities: false, - page: 0, - }; - setLiteratureUpdate(update); - }; - - return ( -
-
- - {selectedChips.map((e, i) => ( - - { - handleDeleteChip(i); - }} - onDelete={() => { - handleDeleteChip(i); - }} - /> - - ))} -
-
- -
-
- ); -} diff --git a/packages/sections/src/common/LiteratureOld/Loader.jsx b/packages/sections/src/common/LiteratureOld/Loader.jsx deleted file mode 100644 index 435a04263..000000000 --- a/packages/sections/src/common/LiteratureOld/Loader.jsx +++ /dev/null @@ -1,38 +0,0 @@ -import { Box, Typography, CircularProgress } from "@mui/material"; -import { makeStyles } from "@mui/styles"; -import { useEffect, useState } from "react"; - -const listComponentStyles = makeStyles(() => ({ - loader: { - display: "flex", - justifyContent: "center", - alignItems: "center", - }, -})); - -function Loader({ message = "", pageSize = 5 }) { - const [height, setHeight] = useState("4040px"); - - useEffect(() => { - if (pageSize === 5) setHeight("850px"); - else if (pageSize === 10) setHeight("1640px"); - else setHeight("4040px"); - }, [pageSize]); - - return ( - - - - {message} - - - ); -} - -export default Loader; diff --git a/packages/sections/src/common/LiteratureOld/PublicationsList.jsx b/packages/sections/src/common/LiteratureOld/PublicationsList.jsx deleted file mode 100644 index eec522374..000000000 --- a/packages/sections/src/common/LiteratureOld/PublicationsList.jsx +++ /dev/null @@ -1,242 +0,0 @@ -import { useEffect } from "react"; -import { useRecoilState, useRecoilValue, useSetRecoilState, useRecoilCallback } from "recoil"; -import { Box, Grid, Fade, Skeleton } from "@mui/material"; -import { makeStyles } from "@mui/styles"; -import { PublicationWrapper, Table } from "ui"; -import Loader from "./Loader"; - -import { - litsIdsState, - loadingEntitiesState, - displayedPublications, - literaturesEuropePMCQuery, - parsePublications, - tablePageState, - litsCountState, - litsCursorState, - literatureState, - fetchSimilarEntities, - updateLiteratureState, - tablePageSizeState, -} from "./atoms"; - -const useStyles = makeStyles(() => ({ - root: { - marginTop: 0, - }, -})); - -function SkeletonRow() { - return ( - - - - {/* */} - - {/* */} - - - - - - - - - - - ); -} - -function PublicationsList({ hideSearch = false }) { - const classes = useStyles(); - const lits = useRecoilValue(litsIdsState); - const [loadingEntities, setLoadingEntities] = useRecoilState(loadingEntitiesState); - const count = useRecoilValue(litsCountState); - const cursor = useRecoilValue(litsCursorState); - const displayedPubs = useRecoilValue(displayedPublications); - const bibliographyState = useRecoilValue(literatureState); - const setLiteratureUpdate = useSetRecoilState(updateLiteratureState); - const page = useRecoilValue(tablePageState); - const pageSize = useRecoilValue(tablePageSizeState); - - // function to request 'ready' literatures ids - const syncLiteraturesState = useRecoilCallback(({ snapshot, set }) => async () => { - const AllLits = await snapshot.getPromise(litsIdsState); - const readyForRequest = AllLits.filter(x => x.status === "ready").map(x => x.id); - - if (readyForRequest.length === 0) return; - const queryResult = await snapshot.getPromise( - literaturesEuropePMCQuery({ - literaturesIds: readyForRequest, - }) - ); - - const parsedPublications = parsePublications(queryResult); - - const mapedResults = new Map(parsedPublications.map(key => [key.europePmcId, key])); - - const updatedPublications = AllLits.map(x => { - const publication = mapedResults.get(x.id); - if (x.status === "loaded") return x; - const status = publication ? "loaded" : "missing"; - return { ...x, status, publication }; - }); - set(litsIdsState, updatedPublications); - }); - - useEffect( - () => { - if (lits.length !== 0) syncLiteraturesState(); - }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [lits] - ); - - const handleRowsPerPageChange = useRecoilCallback(({ snapshot }) => async newPageSize => { - const pageSizeInt = Number(newPageSize); - const expected = pageSizeInt * page + pageSizeInt; - if (expected > lits.length && cursor !== null) { - const { - query, - id, - category, - selectedEntities, - cursor: newCursor, - globalEntity, - endYear, - endMonth, - startYear, - startMonth, - } = bibliographyState; - setLoadingEntities(true); - const request = await fetchSimilarEntities({ - query, - id, - category, - entities: selectedEntities, - cursor: newCursor, - page: 0, - endYear, - endMonth, - startYear, - startMonth, - }); - setLoadingEntities(false); - const data = request.data[globalEntity]; - const loadedPublications = await snapshot.getPromise(litsIdsState); - const newLits = data.literatureOcurrences?.rows?.map(({ pmid }) => ({ - id: pmid, - status: "ready", - publication: null, - })); - const update = { - litsIds: [...loadedPublications, ...newLits], - cursor: data.literatureOcurrences?.cursor, - page: 0, - pageSize: pageSizeInt, - }; - setLiteratureUpdate(update); - } else { - setLiteratureUpdate({ page: 0, pageSize: pageSizeInt }); - } - }); - - const handlePageChange = useRecoilCallback(({ snapshot }) => async newPage => { - const newPageInt = Number(newPage); - if (pageSize * newPageInt + pageSize > lits.length && cursor !== null) { - const { - query, - id, - category, - selectedEntities, - cursor: newCursor, - globalEntity, - endYear, - endMonth, - startYear, - startMonth, - } = bibliographyState; - setLoadingEntities(true); - const request = await fetchSimilarEntities({ - query, - id, - category, - entities: selectedEntities, - cursor: newCursor, - endYear, - endMonth, - startYear, - startMonth, - }); - setLoadingEntities(false); - const data = request.data[globalEntity]; - const loadedPublications = await snapshot.getPromise(litsIdsState); - const newLits = data.literatureOcurrences?.rows?.map(({ pmid }) => ({ - id: pmid, - status: "ready", - publication: null, - })); - const update = { - litsIds: [...loadedPublications, ...newLits], - cursor: data.literatureOcurrences?.cursor, - page: newPageInt, - }; - setLiteratureUpdate(update); - } else { - setLiteratureUpdate({ page: newPageInt }); - } - }); - - const columns = [ - { - id: "publications", - label: " ", - renderCell: ({ publication, status }) => { - if (status === "ready") return ; - if (status === "missing") return null; - return ( - - ); - }, - filterValue: ({ row: publication }) => - `${publication.journal.journal?.title} ${publication?.title} ${publication?.year} - ${publication.authors - .reduce((acc, author) => { - if (author.fullName) acc.push(author.fullName); - return acc; - }, []) - .join(" ")}`, - }, - ]; - - if (loadingEntities) - return ; - - return ( -
- ); -} - -export default PublicationsList; diff --git a/packages/sections/src/common/LiteratureOld/Summary.jsx b/packages/sections/src/common/LiteratureOld/Summary.jsx deleted file mode 100644 index 155251c7a..000000000 --- a/packages/sections/src/common/LiteratureOld/Summary.jsx +++ /dev/null @@ -1,31 +0,0 @@ -import { gql } from "@apollo/client"; - -import { SummaryItem, usePlatformApi } from "ui"; - -const SIMILARENTTIES_SUMMARY_FRAGMENT = gql` - fragment SimilarEntitiesDisease on Disease { - similarEntities(threshold: 0.5, size: 20) { - score - } - } -`; - -function Summary({ definition }) { - const request = usePlatformApi(SIMILARENTTIES_SUMMARY_FRAGMENT); - - return ( - - data.similarEntities?.length > 0 ? <>Data available : <>no data - } - /> - ); -} - -Summary.fragments = { - SimilarEntitiesDisease: SIMILARENTTIES_SUMMARY_FRAGMENT, -}; - -export default Summary; diff --git a/packages/sections/src/common/LiteratureOld/TimeTravelObserver.jsx b/packages/sections/src/common/LiteratureOld/TimeTravelObserver.jsx deleted file mode 100644 index 00843e92e..000000000 --- a/packages/sections/src/common/LiteratureOld/TimeTravelObserver.jsx +++ /dev/null @@ -1,52 +0,0 @@ -import { useState, useEffect } from "react"; -import { List, ListItem, Drawer, Box, Link as MUILink, Button } from "@mui/material"; -import { useRecoilSnapshot, useGotoRecoilSnapshot } from "recoil"; - -export default function TimeTravelObserver() { - const [snapshots, setSnapshots] = useState([]); - const [open, setOpen] = useState(false); - - const snapshot = useRecoilSnapshot(); - - const toggleDrawer = event => { - if (event.type === "keydown" && (event.key === "Tab" || event.key === "Shift")) { - return; - } - - setOpen(true); - }; - - const closeDrawer = () => { - setOpen(false); - }; - - useEffect( - () => { - if (snapshots.every(s => s.getID() !== snapshot.getID())) { - setSnapshots([...snapshots, snapshot]); - } - }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [snapshot] - ); - - const gotoSnapshot = useGotoRecoilSnapshot(); - - return ( - <> - Time Travel Observer - - - - {snapshots.map((snapshotItem, i) => ( - - Snapshot {i} - - - ))} - - - - - ); -} diff --git a/packages/sections/src/common/LiteratureOld/atoms.ts b/packages/sections/src/common/LiteratureOld/atoms.ts deleted file mode 100644 index aeea0a4e5..000000000 --- a/packages/sections/src/common/LiteratureOld/atoms.ts +++ /dev/null @@ -1,339 +0,0 @@ -import isEmpty from "lodash/isEmpty"; -import { atom, selectorFamily, selector, DefaultValue } from "recoil"; -import { getPage } from "ui"; -import client from "../../client"; -import { europePmcBiblioSearchPOSTQuery } from "../../utils/urls"; - -// ------------------------------------------ -// Helpers -// ------------------------------------------ - -type AuthorListType = { - fullName: string; - firstName: string; - lastName: string; - initials: string; - authorId: { - type: string; - value: string; - }; - authorAffiliationDetailsList: { - authorAffiliation: { - affiliation: string; - }[]; - }; -}; - -type JournalInfoType = { - issue: string; - volume: string; - journalIssueId: number; - dateOfPublication: string; - monthOfPublication: number; - yearOfPublication: number; - printPublicationDate: string; - journal: { - title: string; - medlineAbbreviation: string; - isoabbreviation: string; - nlmid: string; - issn: string; - essn: string; - }; -}; - -type PublicationType = { - source: string; - patentDetails: any; - id: string; - inEPMC: string; - inPMC: string; - title: string; - pubYear: string; - abstractText: string; - isOpenAccess: string; - authorList: { - author: AuthorListType; - }; - journalInfo: JournalInfoType; - pageInfo: string; -}; - -type RowType = { - source: string; - patentDetails: any; - europePmcId: string; - fullTextOpen: boolean; - title: string; - year: string; - abstract: string; - openAccess: boolean; - authors: AuthorListType; - journal: JournalInfoType & { page: string }; -}; - -export const parsePublications = (publications: PublicationType[]) => - publications.map(pub => { - const row: RowType = { - source: pub.source, - patentDetails: pub.patentDetails, - europePmcId: pub.id, - fullTextOpen: !!(pub.inEPMC === "Y" || pub.inPMC === "Y"), - title: pub.title, - year: pub.pubYear, - abstract: pub.abstractText, - openAccess: pub.isOpenAccess !== "N", - authors: pub.authorList?.author || [], - journal: { - ...pub.journalInfo, - page: pub.pageInfo, - }, - }; - return row; - }); - -type LiteratureStateType = { - id: string; - cursor: string | null; - threshold?: number; - size?: number; - category: string[]; - query: any | null; - globalEntity: any | null; - entities: any[]; - selectedEntities: any[] | DefaultValue; - startYear: number | null; - startMonth: number | null; - endYear: number | null; - endMonth: number | null; - earliestPubYear: number; - litsIds: - | { - id: string; - status: string; - publication: null; - }[] - | DefaultValue; - page: number; - pageSize: number | DefaultValue; - litsCount: number; - loadingEntities: boolean | DefaultValue; -}; - -// ------------------------------------------ -// ATOMS -// ------------------------------------------ - -const defaultState: LiteratureStateType = { - id: "", - cursor: "", - category: ["disease", "drug", "target"], - query: null, - globalEntity: null, - entities: [], - selectedEntities: [], - startYear: null, - startMonth: null, - endYear: null, - endMonth: null, - earliestPubYear: 0, - litsIds: [], - page: 0, - pageSize: 5, - litsCount: 0, - loadingEntities: false, -}; - -export const literatureState = atom({ - key: "literatureState", - default: defaultState, -}); - -// ------------------------------------------ -// SELECTORS -// ------------------------------------------ -export const loadingEntitiesState = selector({ - key: "loadingEntitiesState", - get: ({ get }) => { - const { loadingEntities } = get(literatureState); - return loadingEntities; - }, - set: ({ set, get }, newStatus) => { - const currentState = get(literatureState); - const newState: LiteratureStateType = { - ...currentState, - loadingEntities: newStatus, - }; - return set(literatureState, newState); - }, -}); - -export const selectedCategoriesState = selector({ - key: "selectedCategoriesState", - get: ({ get }) => { - const { category } = get(literatureState); - const sortedCategories = [...category].sort(); - return sortedCategories; - }, -}); - -export const litsCursorState = selector({ - key: "litsCursorState", - get: ({ get }) => { - const { cursor } = get(literatureState); - return cursor; - }, -}); - -export const tablePageState = selector({ - key: "tablePageState", - get: ({ get }) => { - const { page } = get(literatureState); - return page; - }, -}); - -export const tablePageSizeState = selector({ - key: "tablePageSizeState", - get: ({ get }) => { - const { pageSize } = get(literatureState); - return pageSize; - }, - set: ({ set, get }, newPageSize) => { - const currentState = get(literatureState); - const newState: LiteratureStateType = { - ...currentState, - pageSize: newPageSize, - }; - return set(literatureState, newState); - }, -}); - -export const litsCountState = selector({ - key: "litsCountState", - get: ({ get }) => { - const { litsCount } = get(literatureState); - return litsCount; - }, -}); - -export const litsIdsState = selector({ - key: "litsIdsState", - get: ({ get }) => { - const { litsIds } = get(literatureState); - return litsIds; - }, - set: ({ set, get }, newValue) => { - const currentState = get(literatureState); - const newState: LiteratureStateType = { - ...currentState, - litsIds: newValue, - }; - return set(literatureState, newState); - }, -}); - -export const displayedPublications = selector({ - key: "displayedPublications", - get: ({ get }) => { - const page = get(tablePageState); - const pageSize = get(tablePageSizeState); - const publications = get(litsIdsState); - if (isEmpty(publications)) return []; - const rows = getPage(publications, page, pageSize); - return rows; - }, -}); - -export const entitiesState = selector({ - key: "entitiesState", - get: ({ get }) => { - const { entities } = get(literatureState); - return entities; - }, -}); - -export const selectedEntitiesState = selector({ - key: "selectedEntitiesState", - get: ({ get }) => { - const { selectedEntities } = get(literatureState); - return selectedEntities; - }, - set: ({ set, get }, selectedEntities) => { - const currentState = get(literatureState); - const newState: LiteratureStateType = { ...currentState, selectedEntities }; - return set(literatureState, newState); - }, -}); - -export const updateLiteratureState = selector({ - key: "updateLiteratureState", - get: ({ get }) => get(literatureState), - set: ({ set, get }, stateUpdate) => { - const currentState = get(literatureState); - return set(literatureState, { ...currentState, ...stateUpdate }); - }, -}); - -// ------------------------------------------ -// Requests -// ------------------------------------------ - -const fetchLiteraturesFromPMC = async ({ - baseUrl, - requestOptions, -}: { - baseUrl: string; - requestOptions: any; -}) => fetch(baseUrl, requestOptions).then(response => response.json()); - -export const literaturesEuropePMCQuery = selectorFamily({ - key: "literaturesEuropePMCQuery", - get: - ({ literaturesIds }: { literaturesIds: string[] }) => - async () => { - if (literaturesIds.length === 0) return []; - const { baseUrl, requestOptions } = europePmcBiblioSearchPOSTQuery(literaturesIds); - const response = await fetchLiteraturesFromPMC({ - baseUrl, - requestOptions, - }); - if (response.error) { - throw response.error; - } - return response.resultList?.result; - }, -}); - -// gets simialar entities AND the publications info -export const fetchSimilarEntities = ({ - id = "", - threshold = 0.5, - size = 15, - query, - cursor = null, - category = [], - entities = [], - startYear = null, - startMonth = null, - endYear = null, - endMonth = null, -}: LiteratureStateType) => { - const entityNames = category.length === 0 ? null : category; - const ids = entities.map(c => c.object.id); - return client.query({ - query, - variables: { - cursor, - id, - ids, - startYear, - startMonth, - endYear, - endMonth, - threshold, - size, - entityNames, - }, - }); -}; diff --git a/packages/sections/src/common/LiteratureOld/index.js b/packages/sections/src/common/LiteratureOld/index.js deleted file mode 100644 index fa2dac1d5..000000000 --- a/packages/sections/src/common/LiteratureOld/index.js +++ /dev/null @@ -1,9 +0,0 @@ -export const definition = { - id: "bibliography1", - name: "Bibliography", - shortName: "B", - hasData: data => (data.similarEntities?.length || 0) > 0, -}; - -export { default as Summary } from "./Summary"; -export { default as Body } from "./Body"; diff --git a/packages/sections/src/disease/BibliographyOld/BibliographyQuery.gql b/packages/sections/src/disease/BibliographyOld/BibliographyQuery.gql deleted file mode 100644 index 4f36f6a3e..000000000 --- a/packages/sections/src/disease/BibliographyOld/BibliographyQuery.gql +++ /dev/null @@ -1,58 +0,0 @@ -query SimilarEntitiesQuery( - $id: String! - $ids: [String!] = [] - $startYear: Int = null - $startMonth: Int = null - $endYear: Int = null - $endMonth: Int = null - $threshold: Float = 0.5 - $size: Int! = 15 - $entityNames: [String!] = [] - $cursor: String = null -) { - disease(efoId: $id) { - id - name - similarEntities( - additionalIds: $ids - threshold: $threshold - size: $size - entityNames: $entityNames - ) { - score - id - object { - ... on Target { - id - approvedSymbol - } - ... on Drug { - id - name - } - ... on Disease { - id - name - } - } - } - literatureOcurrences( - additionalIds: $ids - cursor: $cursor - startYear: $startYear - startMonth: $startMonth - endYear: $endYear - endMonth: $endMonth - ) { - count - filteredCount - earliestPubYear - cursor - rows { - pmid - pmcid - publicationDate - } - } - } -} diff --git a/packages/sections/src/disease/BibliographyOld/BibliographySummaryFragment.gql b/packages/sections/src/disease/BibliographyOld/BibliographySummaryFragment.gql deleted file mode 100644 index fa6318de5..000000000 --- a/packages/sections/src/disease/BibliographyOld/BibliographySummaryFragment.gql +++ /dev/null @@ -1,6 +0,0 @@ -fragment DiseaseBibliography on Disease { - literatureOcurrences { - count - filteredCount - } -} diff --git a/packages/sections/src/disease/BibliographyOld/Body.jsx b/packages/sections/src/disease/BibliographyOld/Body.jsx deleted file mode 100644 index 953891218..000000000 --- a/packages/sections/src/disease/BibliographyOld/Body.jsx +++ /dev/null @@ -1,18 +0,0 @@ -import { Body as Bibliography } from "../../common/LiteratureOld"; -import { definition } from "."; - -import DISEASE_LITERATURE_OCURRENCES from "./BibliographyQuery.gql"; - -function Body({ id, label: name, entity }) { - return ( - - ); -} - -export default Body; diff --git a/packages/sections/src/disease/BibliographyOld/Description.jsx b/packages/sections/src/disease/BibliographyOld/Description.jsx deleted file mode 100644 index afd67b955..000000000 --- a/packages/sections/src/disease/BibliographyOld/Description.jsx +++ /dev/null @@ -1,18 +0,0 @@ -import { Link } from "ui"; - -const url = "http://platform-docs.opentargets.org/bibliography"; - -function Description({ name }) { - return ( - <> - Scientific literature mentioning NLP-recognised entity {name} and other - selected co-occurring entities. Source:{" "} - - Open Targets - - . - - ); -} - -export default Description; diff --git a/packages/sections/src/disease/BibliographyOld/Summary.jsx b/packages/sections/src/disease/BibliographyOld/Summary.jsx deleted file mode 100644 index 48d8ccafa..000000000 --- a/packages/sections/src/disease/BibliographyOld/Summary.jsx +++ /dev/null @@ -1,31 +0,0 @@ -import { usePlatformApi, SummaryItem } from "ui"; - -import SIMILARENTTIES_SUMMARY_FRAGMENT from "./BibliographySummaryFragment.gql"; -import { definition } from "."; - -function Summary() { - const request = usePlatformApi(SIMILARENTTIES_SUMMARY_FRAGMENT); - - return ( - - data.literatureOcurrences?.filteredCount > 0 ? ( - <> - {data.literatureOcurrences.filteredCount.toLocaleString()} publication - {data.literatureOcurrences.filteredCount === 1 ? "" : "s"} - - ) : ( - <>no data - ) - } - /> - ); -} - -Summary.fragments = { - DiseaseBibliography: SIMILARENTTIES_SUMMARY_FRAGMENT, -}; - -export default Summary; diff --git a/packages/sections/src/disease/BibliographyOld/index.js b/packages/sections/src/disease/BibliographyOld/index.js deleted file mode 100644 index 69789b3ee..000000000 --- a/packages/sections/src/disease/BibliographyOld/index.js +++ /dev/null @@ -1,9 +0,0 @@ -export const definition = { - id: "bibliography", - name: "Bibliography", - shortName: "B", - hasData: data => data.literatureOcurrences?.filteredCount > 0, -}; - -export { default as Summary } from "./Summary"; -export { default as Body } from "./Body"; diff --git a/packages/sections/src/drug/BibliographyOld/BibliographyQuery.gql b/packages/sections/src/drug/BibliographyOld/BibliographyQuery.gql deleted file mode 100644 index 52d127942..000000000 --- a/packages/sections/src/drug/BibliographyOld/BibliographyQuery.gql +++ /dev/null @@ -1,58 +0,0 @@ -query SimilarEntitiesQuery( - $id: String! - $ids: [String!] = [] - $startYear: Int = null - $startMonth: Int = null - $endYear: Int = null - $endMonth: Int = null - $threshold: Float = 0.5 - $size: Int! = 15 - $entityNames: [String!] = [] - $cursor: String = null -) { - drug(chemblId: $id) { - id - name - similarEntities( - additionalIds: $ids - threshold: $threshold - size: $size - entityNames: $entityNames - ) { - score - id - object { - ... on Target { - id - approvedSymbol - } - ... on Drug { - id - name - } - ... on Disease { - id - name - } - } - } - literatureOcurrences( - additionalIds: $ids - cursor: $cursor - startYear: $startYear - startMonth: $startMonth - endYear: $endYear - endMonth: $endMonth - ) { - count - filteredCount - earliestPubYear - cursor - rows { - pmid - pmcid - publicationDate - } - } - } -} diff --git a/packages/sections/src/drug/BibliographyOld/BibliographySummaryFragment.gql b/packages/sections/src/drug/BibliographyOld/BibliographySummaryFragment.gql deleted file mode 100644 index 3bbb11014..000000000 --- a/packages/sections/src/drug/BibliographyOld/BibliographySummaryFragment.gql +++ /dev/null @@ -1,6 +0,0 @@ -fragment DrugBibliography on Drug { - literatureOcurrences { - count - filteredCount - } -} diff --git a/packages/sections/src/drug/BibliographyOld/Body.jsx b/packages/sections/src/drug/BibliographyOld/Body.jsx deleted file mode 100644 index d301d245d..000000000 --- a/packages/sections/src/drug/BibliographyOld/Body.jsx +++ /dev/null @@ -1,22 +0,0 @@ -import { definition } from "."; -import { Body as Bibliography } from "../../common/LiteratureOld"; - -import DRUGS_LITERATURE_OCURRENCES from "./BibliographyQuery.gql"; - -function Body({ id, label: name }) { - - return ( - <> - - - - ); -} - -export default Body; diff --git a/packages/sections/src/drug/BibliographyOld/Description.jsx b/packages/sections/src/drug/BibliographyOld/Description.jsx deleted file mode 100644 index afd67b955..000000000 --- a/packages/sections/src/drug/BibliographyOld/Description.jsx +++ /dev/null @@ -1,18 +0,0 @@ -import { Link } from "ui"; - -const url = "http://platform-docs.opentargets.org/bibliography"; - -function Description({ name }) { - return ( - <> - Scientific literature mentioning NLP-recognised entity {name} and other - selected co-occurring entities. Source:{" "} - - Open Targets - - . - - ); -} - -export default Description; diff --git a/packages/sections/src/drug/BibliographyOld/Summary.jsx b/packages/sections/src/drug/BibliographyOld/Summary.jsx deleted file mode 100644 index c3e6a9aa8..000000000 --- a/packages/sections/src/drug/BibliographyOld/Summary.jsx +++ /dev/null @@ -1,31 +0,0 @@ -import { SummaryItem, usePlatformApi } from "ui"; - -import { definition } from "."; -import SIMILARENTTIES_SUMMARY_FRAGMENT from "./BibliographySummaryFragment.gql"; - -function Summary() { - const request = usePlatformApi(SIMILARENTTIES_SUMMARY_FRAGMENT); - - return ( - - data.literatureOcurrences?.filteredCount > 0 ? ( - <> - {data.literatureOcurrences.filteredCount.toLocaleString()} publication - {data.literatureOcurrences.filteredCount === 1 ? "" : "s"} - - ) : ( - <>no data - ) - } - /> - ); -} - -Summary.fragments = { - DrugBibliography: SIMILARENTTIES_SUMMARY_FRAGMENT, -}; - -export default Summary; diff --git a/packages/sections/src/drug/BibliographyOld/index.js b/packages/sections/src/drug/BibliographyOld/index.js deleted file mode 100644 index bbb93b9a9..000000000 --- a/packages/sections/src/drug/BibliographyOld/index.js +++ /dev/null @@ -1,6 +0,0 @@ -export const definition = { - id: "bibliography", - name: "Bibliography", - shortName: "B", - hasData: data => data.literatureOcurrences?.filteredCount > 0, -}; diff --git a/packages/sections/src/target/BibliographyOld/Body.jsx b/packages/sections/src/target/BibliographyOld/Body.jsx deleted file mode 100644 index f8bc8a8da..000000000 --- a/packages/sections/src/target/BibliographyOld/Body.jsx +++ /dev/null @@ -1,17 +0,0 @@ -import { Body as Bibliography } from "../../common/LiteratureOld"; -import { definition } from "."; -import TARGET_LITERATURE_OCURRENCES from "./SimilarEntities.gql"; - -function Body({ id, label: name, entity }) { - return ( - - ); -} - -export default Body; diff --git a/packages/sections/src/target/BibliographyOld/Description.jsx b/packages/sections/src/target/BibliographyOld/Description.jsx deleted file mode 100644 index afd67b955..000000000 --- a/packages/sections/src/target/BibliographyOld/Description.jsx +++ /dev/null @@ -1,18 +0,0 @@ -import { Link } from "ui"; - -const url = "http://platform-docs.opentargets.org/bibliography"; - -function Description({ name }) { - return ( - <> - Scientific literature mentioning NLP-recognised entity {name} and other - selected co-occurring entities. Source:{" "} - - Open Targets - - . - - ); -} - -export default Description; diff --git a/packages/sections/src/target/BibliographyOld/SimilarEntities.gql b/packages/sections/src/target/BibliographyOld/SimilarEntities.gql deleted file mode 100644 index d33983f5c..000000000 --- a/packages/sections/src/target/BibliographyOld/SimilarEntities.gql +++ /dev/null @@ -1,58 +0,0 @@ -query SimilarEntitiesQuery( - $id: String! - $ids: [String!] = [] - $startYear: Int = null - $startMonth: Int = null - $endYear: Int = null - $endMonth: Int = null - $threshold: Float = 0.5 - $size: Int! = 15 - $entityNames: [String!] = [] - $cursor: String = null -) { - target(ensemblId: $id) { - id - approvedName - similarEntities( - additionalIds: $ids - threshold: $threshold - size: $size - entityNames: $entityNames - ) { - id - score - object { - ... on Target { - id - approvedSymbol - } - ... on Drug { - id - name - } - ... on Disease { - id - name - } - } - } - literatureOcurrences( - additionalIds: $ids - cursor: $cursor - startYear: $startYear - startMonth: $startMonth - endYear: $endYear - endMonth: $endMonth - ) { - count - filteredCount - earliestPubYear - cursor - rows { - pmid - pmcid - publicationDate - } - } - } -} diff --git a/packages/sections/src/target/BibliographyOld/SimilarEntitiesSummary.gql b/packages/sections/src/target/BibliographyOld/SimilarEntitiesSummary.gql deleted file mode 100644 index 2a65351f8..000000000 --- a/packages/sections/src/target/BibliographyOld/SimilarEntitiesSummary.gql +++ /dev/null @@ -1,6 +0,0 @@ -fragment EntitiesSummaryFragment on Target { - literatureOcurrences { - count - filteredCount - } -} diff --git a/packages/sections/src/target/BibliographyOld/Summary.jsx b/packages/sections/src/target/BibliographyOld/Summary.jsx deleted file mode 100644 index c26b2399d..000000000 --- a/packages/sections/src/target/BibliographyOld/Summary.jsx +++ /dev/null @@ -1,31 +0,0 @@ -import { SummaryItem, usePlatformApi } from "ui"; - -import { definition } from "."; -import SIMILARENTTIES_SUMMARY_FRAGMENT from "./SimilarEntitiesSummary.gql"; - -function Summary() { - const request = usePlatformApi(SIMILARENTTIES_SUMMARY_FRAGMENT); - - return ( - - data.literatureOcurrences?.filteredCount > 0 ? ( - <> - {data.literatureOcurrences.filteredCount.toLocaleString()} publication - {data.literatureOcurrences.filteredCount === 1 ? "" : "s"} - - ) : ( - <>no data - ) - } - /> - ); -} - -Summary.fragments = { - EntitiesSummaryFragment: SIMILARENTTIES_SUMMARY_FRAGMENT, -}; - -export default Summary; diff --git a/packages/sections/src/target/BibliographyOld/index.js b/packages/sections/src/target/BibliographyOld/index.js deleted file mode 100644 index bbb93b9a9..000000000 --- a/packages/sections/src/target/BibliographyOld/index.js +++ /dev/null @@ -1,6 +0,0 @@ -export const definition = { - id: "bibliography", - name: "Bibliography", - shortName: "B", - hasData: data => data.literatureOcurrences?.filteredCount > 0, -}; From 2571cce29eed2dd12d4021fdfc49ccb17c0033d5 Mon Sep 17 00:00:00 2001 From: Graham McNeill Date: Fri, 19 Jul 2024 13:47:46 +0100 Subject: [PATCH 07/10] uncomment sections --- .../src/pages/DiseasePage/Profile.jsx | 41 +++---- apps/platform/src/pages/DrugPage/Profile.jsx | 44 +++---- .../platform/src/pages/TargetPage/Profile.jsx | 116 +++++++++--------- 3 files changed, 100 insertions(+), 101 deletions(-) diff --git a/apps/platform/src/pages/DiseasePage/Profile.jsx b/apps/platform/src/pages/DiseasePage/Profile.jsx index 61fcc3d09..9992506cf 100644 --- a/apps/platform/src/pages/DiseasePage/Profile.jsx +++ b/apps/platform/src/pages/DiseasePage/Profile.jsx @@ -10,28 +10,27 @@ import { SectionLoader, } from "ui"; -// import OntologySummary from "sections/src/disease/Ontology/Summary"; -// import KnownDrugsSummary from "sections/src/disease/KnownDrugs/Summary"; - +import OntologySummary from "sections/src/disease/Ontology/Summary"; +import KnownDrugsSummary from "sections/src/disease/KnownDrugs/Summary"; import BibliographySummary from "sections/src/disease/Bibliography/Summary"; -// import PhenotypesSummary from "sections/src/disease/Phenotypes/Summary"; -// import OTProjectsSummary from "sections/src/disease/OTProjects/Summary"; +import PhenotypesSummary from "sections/src/disease/Phenotypes/Summary"; +import OTProjectsSummary from "sections/src/disease/OTProjects/Summary"; import client from "../../client"; import ProfileHeader from "./ProfileHeader"; -// const OntologySection = lazy(() => import("sections/src/disease/Ontology/Body")); -// const KnownDrugsSection = lazy(() => import("sections/src/disease/KnownDrugs/Body")); +const OntologySection = lazy(() => import("sections/src/disease/Ontology/Body")); +const KnownDrugsSection = lazy(() => import("sections/src/disease/KnownDrugs/Body")); const BibliographySection = lazy(() => import("sections/src/disease/Bibliography/Body")); -// const PhenotypesSection = lazy(() => import("sections/src/disease/Phenotypes/Body")); -// const OTProjectsSection = lazy(() => import("sections/src/disease/OTProjects/Body")); +const PhenotypesSection = lazy(() => import("sections/src/disease/Phenotypes/Body")); +const OTProjectsSection = lazy(() => import("sections/src/disease/OTProjects/Body")); const summaries = [ - // OntologySummary, - // KnownDrugsSummary, + OntologySummary, + KnownDrugsSummary, BibliographySummary, - // PhenotypesSummary, - // OTProjectsSummary, + PhenotypesSummary, + OTProjectsSummary, ]; const DISEASE = "disease"; @@ -58,17 +57,17 @@ function Profile({ efoId, name }) { > - {/* + - */} + - {/* + - */} + - {/* }> + }> }> @@ -76,15 +75,15 @@ function Profile({ efoId, name }) { }> - */} + }> - {/* + }> - */} + ); diff --git a/apps/platform/src/pages/DrugPage/Profile.jsx b/apps/platform/src/pages/DrugPage/Profile.jsx index 868b5e90f..06f74eaa3 100644 --- a/apps/platform/src/pages/DrugPage/Profile.jsx +++ b/apps/platform/src/pages/DrugPage/Profile.jsx @@ -1,31 +1,31 @@ import { gql } from "@apollo/client"; import { PlatformApiProvider, SectionContainer, SummaryContainer, summaryUtils } from "ui"; -// import MechanismsOfActionSummary from "sections/src/drug/MechanismsOfAction/Summary"; -// import IndicationsSummary from "sections/src/drug/Indications/Summary"; -// import KnownDrugsSummary from "sections/src/drug/KnownDrugs/Summary"; -// import DrugWarningsSummary from "sections/src/drug/DrugWarnings/Summary"; -// import PharmacogenomicsSummary from "sections/src/drug/Pharmacogenomics/Summary"; -// import AdverseEventsSummary from "sections/src/drug/AdverseEvents/Summary"; +import MechanismsOfActionSummary from "sections/src/drug/MechanismsOfAction/Summary"; +import IndicationsSummary from "sections/src/drug/Indications/Summary"; +import KnownDrugsSummary from "sections/src/drug/KnownDrugs/Summary"; +import DrugWarningsSummary from "sections/src/drug/DrugWarnings/Summary"; +import PharmacogenomicsSummary from "sections/src/drug/Pharmacogenomics/Summary"; +import AdverseEventsSummary from "sections/src/drug/AdverseEvents/Summary"; import BibliographySummary from "sections/src/drug/Bibliography/Summary"; -// import MechanismsOfActionSection from "sections/src/drug/MechanismsOfAction/Body"; -// import IndicationsSection from "sections/src/drug/Indications/Body"; -// import KnownDrugsSection from "sections/src/drug/KnownDrugs/Body"; -// import DrugWarningsSection from "sections/src/drug/DrugWarnings/Body"; -// import PharmacogenomicsSection from "sections/src/drug/Pharmacogenomics/Body"; -// import AdverseEventsSection from "sections/src/drug/AdverseEvents/Body"; +import MechanismsOfActionSection from "sections/src/drug/MechanismsOfAction/Body"; +import IndicationsSection from "sections/src/drug/Indications/Body"; +import KnownDrugsSection from "sections/src/drug/KnownDrugs/Body"; +import DrugWarningsSection from "sections/src/drug/DrugWarnings/Body"; +import PharmacogenomicsSection from "sections/src/drug/Pharmacogenomics/Body"; +import AdverseEventsSection from "sections/src/drug/AdverseEvents/Body"; import BibliographySection from "sections/src/drug/Bibliography/Body"; import client from "../../client"; import ProfileHeader from "./ProfileHeader"; const summaries = [ - // MechanismsOfActionSummary, - // IndicationsSummary, - // KnownDrugsSummary, - // DrugWarningsSummary, - // PharmacogenomicsSummary, - // AdverseEventsSummary, + MechanismsOfActionSummary, + IndicationsSummary, + KnownDrugsSummary, + DrugWarningsSummary, + PharmacogenomicsSummary, + AdverseEventsSummary, BibliographySummary, ]; @@ -55,22 +55,22 @@ function Profile({ chemblId, name }) { - {/* + - */} + - {/* + - */} + diff --git a/apps/platform/src/pages/TargetPage/Profile.jsx b/apps/platform/src/pages/TargetPage/Profile.jsx index a85cc03e4..433591206 100644 --- a/apps/platform/src/pages/TargetPage/Profile.jsx +++ b/apps/platform/src/pages/TargetPage/Profile.jsx @@ -8,68 +8,68 @@ import { SectionLoader, } from "ui"; -// import KnownDrugsSummary from "sections/src/target/KnownDrugs/Summary"; -// import TractabilitySummary from "sections/src/target/Tractability/Summary"; -// import SafetySummary from "sections/src/target/Safety/Summary"; -// import PharmacogenomicsSummary from "sections/src/target/Pharmacogenomics/Summary"; -// import ChemicalProbesSummary from "sections/src/target/ChemicalProbes/Summary"; -// import BaselineExpressionSummary from "sections/src/target/Expression/Summary"; -// import DepMapSummary from "sections/src/target/DepMap/Summary"; -// import GeneOntologySummary from "sections/src/target/GeneOntology/Summary"; -// import GeneticConstraintSummary from "sections/src/target/GeneticConstraint/Summary"; -// import ProtVistaSummary from "sections/src/target/ProtVista/Summary"; -// import MolecularInteractionsSummary from "sections/src/target/MolecularInteractions/Summary"; -// import PathwaysSummary from "sections/src/target/Pathways/Summary"; -// import CancerHallmarksSummary from "sections/src/target/CancerHallmarks/Summary"; -// import MousePhenotypesSummary from "sections/src/target/MousePhenotypes/Summary"; -// import ComparativeGenomicsSummary from "sections/src/target/ComparativeGenomics/Summary"; -// import SubcellularLocationSummary from "sections/src/target/SubcellularLocation/Summary"; +import KnownDrugsSummary from "sections/src/target/KnownDrugs/Summary"; +import TractabilitySummary from "sections/src/target/Tractability/Summary"; +import SafetySummary from "sections/src/target/Safety/Summary"; +import PharmacogenomicsSummary from "sections/src/target/Pharmacogenomics/Summary"; +import ChemicalProbesSummary from "sections/src/target/ChemicalProbes/Summary"; +import BaselineExpressionSummary from "sections/src/target/Expression/Summary"; +import DepMapSummary from "sections/src/target/DepMap/Summary"; +import GeneOntologySummary from "sections/src/target/GeneOntology/Summary"; +import GeneticConstraintSummary from "sections/src/target/GeneticConstraint/Summary"; +import ProtVistaSummary from "sections/src/target/ProtVista/Summary"; +import MolecularInteractionsSummary from "sections/src/target/MolecularInteractions/Summary"; +import PathwaysSummary from "sections/src/target/Pathways/Summary"; +import CancerHallmarksSummary from "sections/src/target/CancerHallmarks/Summary"; +import MousePhenotypesSummary from "sections/src/target/MousePhenotypes/Summary"; +import ComparativeGenomicsSummary from "sections/src/target/ComparativeGenomics/Summary"; +import SubcellularLocationSummary from "sections/src/target/SubcellularLocation/Summary"; import BibliographySummary from "sections/src/target/Bibliography/Summary"; import ProfileHeader from "./ProfileHeader"; import client from "../../client"; -// const KnownDrugsSection = lazy(() => import("sections/src/target/KnownDrugs/Body")); -// const TractabilitySection = lazy(() => import("sections/src/target/Tractability/Body")); -// const SafetySection = lazy(() => import("sections/src/target/Safety/Body")); -// const PharmacogenomicsSection = lazy(() => import("sections/src/target/Pharmacogenomics/Body")); -// const ChemicalProbesSection = lazy(() => import("sections/src/target/ChemicalProbes/Body")); -// const BaselineExpressionSection = lazy(() => import("sections/src/target/Expression/Body")); -// const DepMapSection = lazy(() => import("sections/src/target/DepMap/Body")); -// const GeneOntologySection = lazy(() => import("sections/src/target/GeneOntology/Body")); -// const GeneticConstraintSection = lazy(() => import("sections/src/target/GeneticConstraint/Body")); -// const ProtVistaSection = lazy(() => import("sections/src/target/ProtVista/Body")); -// const MolecularInteractionsSection = lazy(() => -// import("sections/src/target/MolecularInteractions/Body") -// ); -// const PathwaysSection = lazy(() => import("sections/src/target/Pathways/Body")); -// const CancerHallmarksSection = lazy(() => import("sections/src/target/CancerHallmarks/Body")); -// const MousePhenotypesSection = lazy(() => import("sections/src/target/MousePhenotypes/Body")); -// const ComparativeGenomicsSection = lazy(() => -// import("sections/src/target/ComparativeGenomics/Body") -// ); -// const SubcellularLocationSection = lazy(() => -// import("sections/src/target/SubcellularLocation/Body") -// ); +const KnownDrugsSection = lazy(() => import("sections/src/target/KnownDrugs/Body")); +const TractabilitySection = lazy(() => import("sections/src/target/Tractability/Body")); +const SafetySection = lazy(() => import("sections/src/target/Safety/Body")); +const PharmacogenomicsSection = lazy(() => import("sections/src/target/Pharmacogenomics/Body")); +const ChemicalProbesSection = lazy(() => import("sections/src/target/ChemicalProbes/Body")); +const BaselineExpressionSection = lazy(() => import("sections/src/target/Expression/Body")); +const DepMapSection = lazy(() => import("sections/src/target/DepMap/Body")); +const GeneOntologySection = lazy(() => import("sections/src/target/GeneOntology/Body")); +const GeneticConstraintSection = lazy(() => import("sections/src/target/GeneticConstraint/Body")); +const ProtVistaSection = lazy(() => import("sections/src/target/ProtVista/Body")); +const MolecularInteractionsSection = lazy(() => + import("sections/src/target/MolecularInteractions/Body") +); +const PathwaysSection = lazy(() => import("sections/src/target/Pathways/Body")); +const CancerHallmarksSection = lazy(() => import("sections/src/target/CancerHallmarks/Body")); +const MousePhenotypesSection = lazy(() => import("sections/src/target/MousePhenotypes/Body")); +const ComparativeGenomicsSection = lazy(() => + import("sections/src/target/ComparativeGenomics/Body") +); +const SubcellularLocationSection = lazy(() => + import("sections/src/target/SubcellularLocation/Body") +); const BibliographySection = lazy(() => import("sections/src/target/Bibliography/Body")); const summaries = [ - // KnownDrugsSummary, - // TractabilitySummary, - // SafetySummary, - // PharmacogenomicsSummary, - // ChemicalProbesSummary, - // BaselineExpressionSummary, - // DepMapSummary, - // GeneOntologySummary, - // GeneticConstraintSummary, - // ProtVistaSummary, - // MolecularInteractionsSummary, - // PathwaysSummary, - // CancerHallmarksSummary, - // MousePhenotypesSummary, - // ComparativeGenomicsSummary, - // SubcellularLocationSummary, + KnownDrugsSummary, + TractabilitySummary, + SafetySummary, + PharmacogenomicsSummary, + ChemicalProbesSummary, + BaselineExpressionSummary, + DepMapSummary, + GeneOntologySummary, + GeneticConstraintSummary, + ProtVistaSummary, + MolecularInteractionsSummary, + PathwaysSummary, + CancerHallmarksSummary, + MousePhenotypesSummary, + ComparativeGenomicsSummary, + SubcellularLocationSummary, BibliographySummary, ]; @@ -97,7 +97,7 @@ function Profile({ ensgId, symbol }) { > - {/* + @@ -112,12 +112,12 @@ function Profile({ ensgId, symbol }) { - */} + - {/* }> + }> }> @@ -164,7 +164,7 @@ function Profile({ ensgId, symbol }) { }> - */} + }> From ee30b154b517cada1f1b54479e61857d99dfb143 Mon Sep 17 00:00:00 2001 From: Graham McNeill Date: Fri, 19 Jul 2024 13:54:07 +0100 Subject: [PATCH 08/10] add page to LiteratureStateType --- packages/sections/src/common/Literature/LiteratureContext.tsx | 1 + packages/sections/src/common/Literature/types.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/sections/src/common/Literature/LiteratureContext.tsx b/packages/sections/src/common/Literature/LiteratureContext.tsx index 504cf8cae..ad6bf864a 100644 --- a/packages/sections/src/common/Literature/LiteratureContext.tsx +++ b/packages/sections/src/common/Literature/LiteratureContext.tsx @@ -17,6 +17,7 @@ export const defaultLiteratureState: LiteratureStateType = { endMonth: null, earliestPubYear: 0, litsIds: [], + page: 0, pageSize: 5, litsCount: 0, loadingEntities: false, diff --git a/packages/sections/src/common/Literature/types.ts b/packages/sections/src/common/Literature/types.ts index c8af87483..b956fd80d 100644 --- a/packages/sections/src/common/Literature/types.ts +++ b/packages/sections/src/common/Literature/types.ts @@ -82,6 +82,7 @@ type AuthorListType = { endMonth: number | null; earliestPubYear: number; litsIds: string[]; + page: number; pageSize: number | null; // DefaultValue; litsCount: number; loadingEntities: boolean | null; // DefaultValue; From c6fd9d45fa722c5dd1efdd4af03ab79096b440f0 Mon Sep 17 00:00:00 2001 From: Graham McNeill Date: Fri, 19 Jul 2024 14:08:33 +0100 Subject: [PATCH 09/10] undo whitespace changes --- apps/platform/src/pages/DrugPage/Profile.jsx | 1 - apps/platform/src/pages/TargetPage/Profile.jsx | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/platform/src/pages/DrugPage/Profile.jsx b/apps/platform/src/pages/DrugPage/Profile.jsx index 06f74eaa3..aeca1b853 100644 --- a/apps/platform/src/pages/DrugPage/Profile.jsx +++ b/apps/platform/src/pages/DrugPage/Profile.jsx @@ -44,7 +44,6 @@ const DRUG_PROFILE_QUERY = gql` `; function Profile({ chemblId, name }) { - return ( Date: Fri, 19 Jul 2024 14:10:19 +0100 Subject: [PATCH 10/10] undo whitespace changes --- packages/sections/src/utils/urls.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sections/src/utils/urls.js b/packages/sections/src/utils/urls.js index 6d7031e25..fdbfeffa3 100644 --- a/packages/sections/src/utils/urls.js +++ b/packages/sections/src/utils/urls.js @@ -43,7 +43,7 @@ export function europePmcSearchPOSTQuery(ids) { return { baseUrl, formBody }; } -export function europePmcBiblioSearchPOSTQuery(ids, size = 25) { +export function europePmcBiblioSearchPOSTQuery(ids, size = 25) { const baseUrl = "https://www.ebi.ac.uk/europepmc/webservices/rest/searchPOST"; const query = ids.join(" OR ext_id:"); const bodyOptions = {