Skip to content

Commit

Permalink
Fixing deleted gene problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukthiw committed Jan 4, 2025
1 parent 4eb4270 commit c89c1a3
Show file tree
Hide file tree
Showing 34 changed files with 802 additions and 726 deletions.
4 changes: 2 additions & 2 deletions Eplant/Eplant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Box, CircularProgress, CssBaseline, useTheme } from '@mui/material'
import { ThemeProvider } from '@mui/material/styles'

import { dark, light } from './css/theme'
import { URLStateProvider } from './state/URLStateManager'
import { URLStateProvider } from './state/URLStateProvider'
import { ViewContainer } from './UI/Layout/ViewContainer'
import Sidebar, { collapsedSidebarWidth, sidebarWidth } from './UI/Sidebar'
import { useConfig } from './config'
Expand Down Expand Up @@ -42,8 +42,8 @@ const Eplant = () => {
return (
<ThemeProvider theme={darkMode ? dark : light}>
<CssBaseline />
<Sidebar />
<URLStateProvider>
<Sidebar />
<Box
sx={(theme) => ({
height: `calc(100% - ${theme.spacing(1)})`,
Expand Down
17 changes: 17 additions & 0 deletions Eplant/Species/arabidopsis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,21 @@ 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
17 changes: 9 additions & 8 deletions Eplant/UI/Layout/FailedToLoad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ const Illustration = ({
/**
* The view shown when a view is not supported. Shown when the user switches active genes to a gene that does not support this view
*/
export default function FailedToLoad(props: {
geneticElement: GeneticElement | null
view: View
export default function FailedToLoad({
geneticElementId,
viewId,
}: {
geneticElementId: string | undefined
viewId: string
}) {
const theme = useTheme()
return (
Expand All @@ -62,11 +65,9 @@ export default function FailedToLoad(props: {
marginTop: 2,
}}
>
{props.geneticElement
? `There was an error while trying to load ${props.view.name.toLowerCase()} for ${
props.geneticElement.id
}`
: `There was an error while trying to load ${props.view.name.toLowerCase()} without a selected gene.`}
{geneticElementId
? `There was an error while trying to load ${viewId.toLowerCase()} for ${geneticElementId}`
: `There was an error while trying to load ${viewId.toLowerCase()} without a selected gene.`}
</Typography>
<Typography
variant='body1'
Expand Down
11 changes: 9 additions & 2 deletions Eplant/UI/Layout/ViewContainer/LoadingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ export default function LoadingPage(props: {
}) {
const theme = useTheme()
if (props.error == ViewDataError.UNSUPPORTED_GENE)
return <NotSupported geneticElement={props.gene} view={props.view} />
return (
<NotSupported geneticElement={props.gene} viewName={props.view.name} />
)
if (props.error == ViewDataError.FAILED_TO_LOAD)
return <FailedToLoad geneticElement={props.gene} view={props.view} />
return (
<FailedToLoad
geneticElementId={props.gene?.id}
viewId={props.view.name}
/>
)
return (
<Stack gap={4}>
<LinearProgress variant='determinate' value={props.loadingAmount * 100} />
Expand Down
196 changes: 196 additions & 0 deletions Eplant/UI/Layout/ViewContainer/Topbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
import { useId } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'

import { useConfig } from '@eplant/config'
import { useActiveViewId } from '@eplant/state'
import { useURLState } from '@eplant/state/URLStateProvider'
import { ActionsPanel } from '@eplant/util/stateUtils/ActionsPanel'
import { View } from '@eplant/View'
import {
AppBar,
Box,
Button,
FormControl,
ListItemText,
MenuItem,
Select,
Stack,
Toolbar,
} from '@mui/material'

interface TopBarProps {
activeView: View<any, any, any>
setViewingCitations: (value: boolean) => void
loading: boolean
activeActions: any[]
}
export const TopBar = ({
activeView,
setViewingCitations,
loading,
activeActions,
}: TopBarProps) => {
const { userViews, views } = useConfig()
const [activeViewId, setActiveViewId] = useActiveViewId()
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) {
setState(null)
setActiveViewId(view.id)
}
}

return (
<AppBar
variant='elevation'
sx={(theme) => ({
background: theme.palette.background.active,
})}
position='sticky'
elevation={0}
>
<Toolbar
sx={(theme) => ({
gap: '8px',
paddingRight: 16,
borderStyle: 'solid',
borderWidth: '1px 0px 1px 1px',
borderColor: theme.palette.background.edge,
borderLeftColor: theme.palette.background.edgeLight,
})}
>
<Stack
direction='row'
gap={2}
sx={{
flexGrow: 1,
height: '100%',
alignItems: 'center',
}}
>
{/* View selector dropdown */}
<FormControl variant='standard'>
<Select
value={activeView.id}
renderValue={() => {
if (activeView.id === 'get-started') {
return <span style={{ paddingLeft: 8 }}>View selector</span>
}
return (
<span
style={{
display: 'flex',
alignItems: 'center',
}}
>
<Box sx={{ paddingRight: 1.5, marginTop: 0.5 }}>
{activeView.icon && <activeView.icon />}
</Box>
{activeView.name}
</span>
)
}}
labelId={idLabel}
label={'View'}
id={selectId}
onChange={handleChangeView}
sx={{
'& .MuiSelect-select': {
paddingRight: '36px !important',
},
}}
inputProps={{
sx: (theme: any) => ({
display: 'flex',
alignItems: 'center',
backgroundColor: theme.palette.background.paperOverlay,
paddingTop: 0.75,
paddingLeft: 1,
paddingBottom: 0.5,
borderTopLeftRadius: theme.shape.borderRadius,
borderTopRightRadius: theme.shape.borderRadius,
borderStyle: 'solid',
borderWidth: 1,
borderColor: theme.palette.background.edgeLight,
':focus': {
backgroundColor: theme.palette.background.paperOverlay,
borderRadius: 1,
},
'& legend': { display: 'none' },
'& fieldset': { top: 0 },
}),
}}
>
<MenuItem disabled value=''>
Select a view
</MenuItem>
{userViews.map((view) => (
<MenuItem
key={view.id}
value={view.id}
style={{
display: userViews.some((u) => u.id === view.id)
? 'flex'
: 'none',
paddingTop: 8,
paddingBottom: 8,
marginBottom: 0,
}}
>
<Box sx={{ paddingRight: 2, marginTop: 0.5 }}>
{view.icon && <view.icon />}
</Box>
<ListItemText
sx={{
textAlign: 'left',
color: 'secondary.contrastText',
textTransform: 'none',
fontWeight: 'regular',
}}
key={view.name}
onClick={() => setActiveViewId(view.id)}
>
{view.name}
</ListItemText>
</MenuItem>
))}
</Select>
</FormControl>
</Stack>
<ActionsPanel actions={activeActions} />
<Button
variant='text'
sx={{
color: 'secondary.contrastText',
}}
disabled={loading}
color='secondary'
onClick={() => setViewingCitations(true)}
>
Data sources
</Button>
<Button
variant='text'
sx={{
color: 'secondary.contrastText',
}}
disabled={loading}
color='secondary'
onClick={() => {
// downloadFile(
// `${activeView.id}${gene ? '-' + gene.id : ''}.json`,
// JSON.stringify(activeData, null, 2)
// )
}}
>
Download data
</Button>
</Toolbar>
</AppBar>
)
}
Loading

0 comments on commit c89c1a3

Please sign in to comment.