-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,635 additions
and
1,397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { Divider, Stack, styled, Tooltip, TooltipProps, Typography, tooltipClasses, CircularProgress, IconOwnProps, TypographyProps, Grid2 } from '@mui/material' | ||
import { gql } from '../../graphql/__generated__'; | ||
import { useLazyQuery } from '@apollo/client'; | ||
import { useMemo, Fragment, useState } from 'react'; | ||
import NextLink from 'next/link'; | ||
import { UrlObject } from 'url'; | ||
import { ArrowOutward, Tab } from '@mui/icons-material'; | ||
|
||
export interface GeneLinkProps { | ||
geneName: string, | ||
assembly: "GRCh38" | "mm10", | ||
typographyProps?: TypographyProps | ||
} | ||
|
||
const GET_GENE_COORDS = gql(` | ||
query getGeneLocation($name: String!, $assembly: String!) { | ||
gene(name: [$name], assembly: $assembly, version: 40) { | ||
coordinates { | ||
chromosome | ||
start | ||
end | ||
} | ||
} | ||
} | ||
`) | ||
|
||
const GeneLink = ({ geneName, assembly, typographyProps }: GeneLinkProps): React.JSX.Element => { | ||
const [open, setOpen] = useState<boolean>(false) | ||
|
||
const handleClose = () => { | ||
setOpen(false); | ||
}; | ||
|
||
const handleOpen = () => { | ||
getGeneCoords() | ||
setOpen(true); | ||
}; | ||
|
||
const [getGeneCoords, { data: dataCoords, loading: loadingCoords, error: errorCoords, called: coordsWereFetched }] = useLazyQuery( | ||
GET_GENE_COORDS, | ||
{ variables: { name: geneName, assembly: assembly } } | ||
) | ||
|
||
const coordinates = dataCoords && dataCoords.gene.length > 0 && dataCoords.gene[0].coordinates | ||
|
||
const geneExpressionLink = `/applets/gene-expression?assembly=${assembly}&gene=${geneName}` | ||
|
||
const searchLink: UrlObject = useMemo(() => { | ||
return coordinates ? ( | ||
{ | ||
pathname: '/search', | ||
query: { | ||
assembly, | ||
chromosome: coordinates.chromosome, | ||
start: coordinates.start, | ||
end: coordinates.end, | ||
gene: geneName | ||
} | ||
}) : null | ||
}, [coordinates]) | ||
|
||
const StyledTypography = styled((props: TypographyProps) => | ||
<Typography variant='body2' display={"inline"} textAlign={"center"} color="white" {...props} /> | ||
)(() => ({ | ||
'&:hover': { | ||
textDecoration: "underline" | ||
} | ||
})); | ||
|
||
const iconProps: IconOwnProps = { | ||
fontSize: 'small', | ||
sx: { display: "inline-flex", verticalAlign: "middle", p: 0 } | ||
} | ||
|
||
const linkStyles = { | ||
flexGrow: 1, | ||
minWidth: '130px', | ||
display: 'flex', | ||
justifyContent: 'center' | ||
} | ||
|
||
return ( | ||
<Tooltip | ||
open={open} | ||
onOpen={handleOpen} | ||
onClose={handleClose} | ||
title={ | ||
<Fragment> | ||
<Stack | ||
direction={"row"} | ||
gap={1} | ||
justifyContent={"space-between"} | ||
divider={<Divider orientation='vertical' flexItem sx={{ backgroundColor: 'white' }} />} | ||
> | ||
<NextLink href={geneExpressionLink} target='_blank' style={linkStyles}> | ||
<StyledTypography> | ||
View <i>{geneName}</i> Gene Expression | ||
<ArrowOutward {...iconProps} /> | ||
</StyledTypography> | ||
</NextLink> | ||
{searchLink ? | ||
<NextLink href={searchLink} target='_blank' style={linkStyles}> | ||
<StyledTypography> | ||
Search <i>{geneName}</i> on SCREEN | ||
<ArrowOutward {...iconProps} /> | ||
</StyledTypography> | ||
</NextLink> | ||
: | ||
<CircularProgress size={"2rem"} /> | ||
} | ||
</Stack> | ||
</Fragment> | ||
} | ||
> | ||
<Typography variant='inherit' color='primary' {...typographyProps}><i>{geneName}</i></Typography> | ||
</Tooltip> | ||
) | ||
} | ||
|
||
export default GeneLink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.