Skip to content

Commit

Permalink
Cleaned up un-needed code
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukthiw committed Jan 6, 2025
1 parent c89c1a3 commit c4b85b7
Show file tree
Hide file tree
Showing 31 changed files with 92 additions and 1,633 deletions.
6 changes: 0 additions & 6 deletions Eplant/GeneticElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ export default class GeneticElement {
export type SpeciesApi = {
searchGene: (term: string) => Promise<GeneticElement | null>
autocomplete: (term: string) => Promise<string[]>
loaders: {
[key: string]: (
gene: GeneticElement,
loadEvent: (amount: number) => void
) => Promise<any>
}
}

/**
Expand Down
23 changes: 0 additions & 23 deletions Eplant/Species/arabidopsis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@ import axios from 'axios'
import { Species } from '@eplant/GeneticElement'
import GeneticElement from '@eplant/GeneticElement'

import GeneInfoViewLoader from './loaders/GeneInfoView'
import ArabidopsisPublicationViewer from './loaders/PublicationViewer'
const arabidopsis: Species = new Species('Arabidopsis', {
autocomplete,
searchGene,
loaders: {
'gene-info': GeneInfoViewLoader,
'publication-viewer': ArabidopsisPublicationViewer,
},
})
async function autocomplete(s: string) {
return (
Expand Down Expand Up @@ -39,21 +33,4 @@ async function searchGene(s: string) {
return gene
}

async function getGene(s: string) {
const data = (
await axios.get(
'https://bar.utoronto.ca/eplant/cgi-bin/querygene.cgi?species=Arabidopsis_thaliana&term=' +
s
)
).data
if (!data.id || !data.annotation || !data.aliases) return null
const gene = new GeneticElement(
data.id,
data.annotation,
arabidopsis,
data.aliases
)
return gene
}

export default arabidopsis
104 changes: 0 additions & 104 deletions Eplant/Species/arabidopsis/loaders/GeneInfoView/index.ts

This file was deleted.

51 changes: 0 additions & 51 deletions Eplant/Species/arabidopsis/loaders/PublicationViewer/index.ts

This file was deleted.

3 changes: 1 addition & 2 deletions Eplant/UI/Layout/ViewContainer/LoadingPage.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { SVGProps } from 'react'

import GeneticElement from '@eplant/GeneticElement'
import { View } from '@eplant/View'
import { ViewDataError } from '@eplant/View/viewData'
import { View, ViewDataError } from '@eplant/View'
import { Player } from '@lottiefiles/react-lottie-player'
import { Box, LinearProgress, Stack, Typography, useTheme } from '@mui/material'

Expand Down
29 changes: 20 additions & 9 deletions Eplant/UI/Layout/ViewContainer/Topbar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useId } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'

import { useConfig } from '@eplant/config'
import { useActiveViewId } from '@eplant/state'
import { queryClient } from '@eplant/main'
import { useActiveGeneId, useActiveViewId } from '@eplant/state'
import { useURLState } from '@eplant/state/URLStateProvider'
import downloadFile from '@eplant/util/downloadFile'
import { ActionsPanel } from '@eplant/util/stateUtils/ActionsPanel'
import { View } from '@eplant/View'
import {
Expand All @@ -19,7 +20,7 @@ import {
} from '@mui/material'

interface TopBarProps {
activeView: View<any, any, any>
activeView: View<any, any>
setViewingCitations: (value: boolean) => void
loading: boolean
activeActions: any[]
Expand All @@ -32,11 +33,10 @@ export const TopBar = ({
}: TopBarProps) => {
const { userViews, views } = useConfig()
const [activeViewId, setActiveViewId] = useActiveViewId()
const [activeGeneId, setActiveGeneId] = useActiveGeneId()
const { setState } = useURLState<any>()
const location = useLocation()
const idLabel = useId()
const selectId = useId()

const handleChangeView = (e: any) => {
const view = views.find((view) => view.id === e.target.value)
if (view) {
Expand Down Expand Up @@ -182,10 +182,21 @@ export const TopBar = ({
disabled={loading}
color='secondary'
onClick={() => {
// downloadFile(
// `${activeView.id}${gene ? '-' + gene.id : ''}.json`,
// JSON.stringify(activeData, null, 2)
// )
let data = queryClient.getQueryData([
`${activeView.id}-${activeGeneId}`,
])

if (!data) {
// Some views don't cache based on geneId
data = queryClient.getQueryData([activeView.id])
}
console.log(`${activeView.id}-${activeGeneId}`)
console.log(data)
console.log(JSON.stringify(data, null, 2))
downloadFile(
`${activeView.id}${activeGeneId ? '-' + activeGeneId : ''}.json`,
JSON.stringify(data, null, 2)
)
}}
>
Download data
Expand Down
25 changes: 10 additions & 15 deletions Eplant/UI/Layout/ViewContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import {
} from '@eplant/state'
import Modal from '@eplant/UI/Modal'
import ErrorBoundary from '@eplant/util/ErrorBoundary'
import { StateAction } from '@eplant/util/stateUtils'
import { ViewDataError } from '@eplant/View/viewData'
import CellEFP from '@eplant/views/CellEFP'
import { StateAction, ViewDataError } from '@eplant/View'
import GeneInfoView from '@eplant/views/GeneInfoView'
import {
Box,
Expand Down Expand Up @@ -63,8 +61,6 @@ export function ViewContainer<T, S, A>({
const activeView =
views.find((view) => view.id === activeViewId) ?? GeneInfoView

console.log('activeView', activeView)
console.log('activeGene', activeGeneId)
// On app url change, make sure loaded gene and view aligns with URL
useEffect(() => {
const loadGene = async (geneid: string) => {
Expand All @@ -81,7 +77,6 @@ export function ViewContainer<T, S, A>({
}
if (params.geneid) {
if (params.geneid !== activeGeneId) {
console.log('loading gene', params.geneid)
if (!genes.find((g) => g.id === params.geneid)) {
loadGene(params.geneid)
}
Expand All @@ -104,26 +99,27 @@ export function ViewContainer<T, S, A>({

// On active gene change update the gene path segment
useEffect(() => {
console.log('updating path', activeGeneId, location.pathname)
if (location.pathname !== import.meta.env.BASE_URL) {
// Only run this after initial redirect
const pathSegments = location.pathname
.split('/')
.filter((segment) => segment !== '')
if (pathSegments.length == 2 && activeGeneId) {
if (pathSegments.length == 2 && gene) {
pathSegments[pathSegments.length - 1] = activeGeneId
} else if (pathSegments.length == 1 && activeGeneId) {
} else if (pathSegments.length == 1 && gene) {
pathSegments.push(activeGeneId)
// Will never get here as of now, but if we decide to persist activeGene need
// to do this.
} else {
// No gene selected, remove gene path segment
pathSegments.pop()
}

const newPath = '/' + pathSegments.join('/') + '/' + location.search
if (newPath !== location.pathname + '/' + location.search) {
navigate(newPath)
}
}
}, [activeGeneId])
}, [activeGeneId, gene])

useEffect(() => {
const pathSegments = location.pathname.split('/')
Expand All @@ -143,8 +139,7 @@ export function ViewContainer<T, S, A>({
</DialogTitle>
<DialogContent>
{activeView.citation ? (
// <view.citation state={state} activeData={activeData} gene={gene} />
<div></div>
<activeView.citation />
) : (
<Box>No information provided for this view</Box>
)}
Expand Down Expand Up @@ -190,14 +185,14 @@ export function ViewContainer<T, S, A>({
<ErrorBoundary>
{/* Only show the gene header if a gene is selected and this view belongs to the gene */}

{activeGeneId === '' ? (
{!gene ? (
<LoadingPage
loadingAmount={loadAmount}
gene={gene}
view={activeView}
error={ViewDataError.UNSUPPORTED_GENE}
/>
) : (loading && loadAmount < 100) || !gene ? (
) : loading && loadAmount < 100 ? (
<LoadingPage
loadingAmount={loadAmount}
gene={gene}
Expand Down
Loading

0 comments on commit c4b85b7

Please sign in to comment.