Skip to content

Commit 02cc945

Browse files
Add navigation to parent/child features in feature details widget (#483)
* feature details navigation * fix * Fix feature filter default * A few stylistic updates * Lint fix --------- Co-authored-by: Garrett Stevens <stevens.garrett.j@gmail.com>
1 parent e32b415 commit 02cc945

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/ApolloFeatureDetailsWidget.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Attributes } from './Attributes'
88
import { BasicInformation } from './BasicInformation'
99
import { ApolloFeatureDetailsWidget as ApolloFeatureDetails } from './model'
1010
import { Sequence } from './Sequence'
11+
import { FeatureDetailsNavigation } from './FeatureDetailsNavigation'
1112

1213
const useStyles = makeStyles()((theme) => ({
1314
root: {
@@ -59,6 +60,8 @@ export const ApolloFeatureDetailsWidget = observer(
5960
assembly={currentAssembly._id}
6061
refName={refName}
6162
/>
63+
<hr />
64+
<FeatureDetailsNavigation model={model} feature={feature} />
6265
</div>
6366
)
6467
},
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import React from 'react'
2+
3+
import { Button, Typography } from '@mui/material'
4+
import { observer } from 'mobx-react'
5+
6+
import { AnnotationFeature } from '@apollo-annotation/mst'
7+
import { ApolloFeatureDetailsWidget as ApolloFeatureDetails } from './model'
8+
9+
export const FeatureDetailsNavigation = observer(
10+
function FeatureDetailsNavigation(props: {
11+
model: ApolloFeatureDetails
12+
feature: AnnotationFeature
13+
}) {
14+
const { feature, model } = props
15+
const { children, parent } = feature
16+
const childFeatures = []
17+
if (children) {
18+
for (const [, child] of children) {
19+
childFeatures.push(child)
20+
}
21+
}
22+
23+
if (!(parent ?? childFeatures.length > 0)) {
24+
return null
25+
}
26+
27+
return (
28+
<div>
29+
<Typography variant="h5">Go to related feature</Typography>
30+
{parent && (
31+
<div>
32+
<Typography variant="h6">Parent:</Typography>
33+
<Button
34+
variant="contained"
35+
onClick={() => {
36+
model.setFeature(parent)
37+
}}
38+
>
39+
{parent.type} ({parent.min}..{parent.max})
40+
</Button>
41+
</div>
42+
)}
43+
{childFeatures.length > 0 && (
44+
<div>
45+
<Typography variant="h6">
46+
{childFeatures.length === 1 ? 'Child' : 'Children'}:
47+
</Typography>
48+
{childFeatures.map((child) => (
49+
<div key={child._id} style={{ marginBottom: 5 }}>
50+
<Button
51+
variant="contained"
52+
onClick={() => {
53+
model.setFeature(child)
54+
}}
55+
>
56+
{child.type} ({child.min}..{child.max})
57+
</Button>
58+
</div>
59+
))}
60+
</div>
61+
)}
62+
</div>
63+
)
64+
},
65+
)

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function baseModelFactory(
4343
(n) => n >= minDisplayHeight,
4444
),
4545
),
46-
filteredFeatureTypes: types.optional(types.array(types.string), ['gene']),
46+
filteredFeatureTypes: types.array(types.string),
4747
})
4848
.views((self) => {
4949
const { configuration, renderProps: superRenderProps } = self

packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/layouts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function layoutsModelFactory(
3838
refName !== assembly?.getCanonicalRefName(feature.refSeq) ||
3939
!doesIntersect2(start, end, feature.min, feature.max) ||
4040
feature.length > self.featuresMinMaxLimit ||
41-
(self.filteredFeatureTypes &&
41+
(self.filteredFeatureTypes.length > 0 &&
4242
!self.filteredFeatureTypes.includes(feature.type))
4343
) {
4444
continue
@@ -135,7 +135,7 @@ export function layoutsModelFactory(
135135
if (
136136
refName !== assembly?.getCanonicalRefName(feature.refSeq) ||
137137
!doesIntersect2(start, end, feature.min, feature.max) ||
138-
(self.filteredFeatureTypes &&
138+
(self.filteredFeatureTypes.length > 0 &&
139139
!self.filteredFeatureTypes.includes(feature.type))
140140
) {
141141
continue

0 commit comments

Comments
 (0)