forked from GMOD/Apollo3
-
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.
Add ability to go to related features from feature editor widget (GMO…
…D#360) * added Related Features -section * ready for review * ready for PR * Make all parent/child selectors buttons --------- Co-authored-by: Garrett Stevens <stevens.garrett.j@gmail.com>
- Loading branch information
1 parent
81b8ff3
commit 16c2107
Showing
2 changed files
with
92 additions
and
0 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
84 changes: 84 additions & 0 deletions
84
packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/RelatedFeature.tsx
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,84 @@ | ||
import { SessionWithWidgets } from '@jbrowse/core/util' | ||
import { Button, Paper, Typography } from '@mui/material' | ||
import { AnnotationFeature, AnnotationFeatureI } from 'apollo-mst' | ||
import { observer } from 'mobx-react' | ||
import { IMSTMap } from 'mobx-state-tree' | ||
import React from 'react' | ||
import { makeStyles } from 'tss-react/mui' | ||
|
||
import { ApolloSessionModel } from '../session' | ||
|
||
const useStyles = makeStyles()((theme) => ({ | ||
paper: { | ||
margin: theme.spacing(2), | ||
padding: theme.spacing(2), | ||
display: 'flex', | ||
flexDirection: 'column', | ||
}, | ||
})) | ||
|
||
export const RelatedFeatures = observer(function RelatedFeatures({ | ||
assembly, | ||
feature, | ||
refName, | ||
session, | ||
}: { | ||
feature: AnnotationFeatureI | ||
refName: string | ||
session: ApolloSessionModel | ||
assembly: string | ||
}) { | ||
const { classes } = useStyles() | ||
const { parent } = feature | ||
const { children } = feature as { | ||
children?: IMSTMap<typeof AnnotationFeature> | ||
} | ||
|
||
const onButtonClick = (newFeature: AnnotationFeatureI) => { | ||
if (parent) { | ||
const apolloFeatureWidget = ( | ||
session as unknown as SessionWithWidgets | ||
).addWidget('ApolloFeatureDetailsWidget', 'apolloFeatureDetailsWidget', { | ||
feature: newFeature, | ||
assembly, | ||
refName, | ||
}) | ||
;(session as unknown as SessionWithWidgets).showWidget?.( | ||
apolloFeatureWidget, | ||
) | ||
} | ||
} | ||
|
||
if (!(parent || (children && children.size > 0))) { | ||
return null | ||
} | ||
return ( | ||
<> | ||
<Typography variant="h4">Related features</Typography> | ||
{parent && ( | ||
<> | ||
<Typography variant="h5">Parent</Typography> | ||
<Paper elevation={6} className={classes.paper}> | ||
{`Start: ${parent.start}, End: ${parent.end}, Type: ${parent.type}`} | ||
<Button variant="contained" onClick={() => onButtonClick(parent)}> | ||
Go to parent | ||
</Button> | ||
</Paper> | ||
</> | ||
)} | ||
{children && children.size > 0 && ( | ||
<> | ||
<Typography variant="h5">Children</Typography> | ||
{[...children.values()].map((child) => ( | ||
<Paper elevation={6} className={classes.paper} key={child._id}> | ||
{`Start: ${child.start}, End: ${child.end}, Type: ${child.type}`} | ||
<Button variant="contained" onClick={() => onButtonClick(child)}> | ||
Go to child | ||
</Button> | ||
</Paper> | ||
))} | ||
</> | ||
)} | ||
</> | ||
) | ||
}) |