Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds "Favorites" and "Recently used" track categories to the track selector #4039

Merged
merged 17 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ const HamburgerMenu = observer(function ({
label: 'Expand all categories',
onClick: () => model.expandAllCategories(),
},
{
label: 'Show favorite tracks',
type: 'checkbox',
checked: model.showFavoritesCategory,
onClick: () => model.toggleFavoritesCategory(),
},
{
label: 'Show recently used tracks',
type: 'checkbox',
checked: model.showRecentlyUsedCategory,
onClick: () => model.toggleRecentlyUsedCategory(),
},
]}
>
<MenuIcon />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function getNodeData(
extra: Record<string, unknown>,
selection: Record<string, unknown>,
) {
const isLeaf = !!node.conf
const isLeaf = 'conf' in node && !!node.conf
const selected = !!selection[node.id]
return {
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function Category({
}) {
const { classes } = useStyles()
const [menuEl, setMenuEl] = useState<HTMLElement | null>(null)
const { name, model, id, tree, toggleCollapse } = data
const { menuItems, name, model, id, tree, toggleCollapse } = data

return (
<div
Expand Down Expand Up @@ -83,7 +83,7 @@ export default function Category({
onClick: () => {
for (const entry of treeToMap(tree).get(id)?.children || []) {
if (!entry.children.length) {
model.view.showTrack(entry.id)
model.view.showTrack(entry.trackId)
}
}
},
Expand All @@ -93,11 +93,12 @@ export default function Category({
onClick: () => {
for (const entry of treeToMap(tree).get(id)?.children || []) {
if (!entry.children.length) {
model.view.hideTrack(entry.id)
model.view.hideTrack(entry.trackId)
}
}
},
},
...menuItems,
]}
onMenuItemClick={(_event, callback) => {
callback()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {

// icons
import MoreHorizIcon from '@mui/icons-material/MoreHoriz'
import StarIcon from '@mui/icons-material/StarBorderOutlined'
import FilledStarIcon from '@mui/icons-material/Star'

// locals
import { isUnsupported, NodeData } from '../util'
Expand Down Expand Up @@ -37,8 +39,17 @@ export interface InfoArgs {

export default function TrackLabel({ data }: { data: NodeData }) {
const { classes } = useStyles()
const { checked, conf, model, drawerPosition, id, name, onChange, selected } =
data
const {
checked,
conf,
model,
drawerPosition,
id,
trackId,
name,
onChange,
selected,
} = data
const description = (conf && readConfObject(conf, ['description'])) || ''
return (
<>
Expand All @@ -52,7 +63,10 @@ export default function TrackLabel({ data }: { data: NodeData }) {
<Checkbox
className={classes.compactCheckbox}
checked={checked}
onChange={() => onChange(id)}
onChange={() => {
onChange(trackId)
model.addToRecentlyUsed(trackId)
}}
disabled={isUnsupported(name)}
inputProps={{
// @ts-expect-error
Expand Down Expand Up @@ -92,6 +106,17 @@ function TrackMenuButton({
data-testid={`htsTrackEntryMenu-${id}`}
menuItems={[
...(getSession(model).getTrackActionMenuItems?.(conf) || []),
model.isFavorite(conf)
? {
label: 'Remove from favorites',
onClick: () => model.removeFromFavorites(conf),
icon: StarIcon,
}
: {
label: 'Add to favorites',
onClick: () => model.addToFavorites(conf),
icon: FilledStarIcon,
},
{
label: 'Add to selection',
onClick: () => model.addToSelection([conf]),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { AnyConfigurationModel } from '@jbrowse/core/configuration'
import { HierarchicalTrackSelectorModel } from '../model'
import { TreeNode } from '../generateHierarchy'
import { MenuItem } from '@jbrowse/core/ui'

export interface NodeData {
nestingLevel: number
checked: boolean
conf: AnyConfigurationModel
drawerPosition: unknown
id: string
trackId: string
isLeaf: boolean
name: string
onChange: Function
toggleCollapse: (arg: string) => void
tree: TreeNode
selected: boolean
menuItems: MenuItem[]
model: HierarchicalTrackSelectorModel
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getTrackName } from '@jbrowse/core/util/tracks'

// locals
import { matches } from './util'
import { MenuItem } from '@jbrowse/core/ui'

function sortConfs(
confs: AnyConfigurationModel[],
Expand Down Expand Up @@ -45,6 +46,7 @@ function sortConfs(
export interface TreeNode {
name: string
id: string
trackId?: string
conf?: AnyConfigurationModel
checked?: boolean
isOpenByDefault?: boolean
Expand All @@ -55,6 +57,8 @@ export function generateHierarchy({
model,
trackConfs,
extra,
noCategories,
menuItems,
}: {
model: {
filterText: string
Expand All @@ -65,6 +69,8 @@ export function generateHierarchy({
tracks: { configuration: AnyConfigurationModel }[]
}
}
noCategories?: boolean
menuItems?: MenuItem[]
trackConfs: AnyConfigurationModel[]
extra?: string
}): TreeNode[] {
Expand Down Expand Up @@ -100,24 +106,27 @@ export function generateHierarchy({

let currLevel = hierarchy

// find existing category to put track into or create it
for (let i = 0; i < categories.length; i++) {
const category = categories[i]
const ret = currLevel.children.find(c => c.name === category)
const id = [extra, categories.slice(0, i + 1).join(',')]
.filter(f => !!f)
.join('-')
if (!ret) {
const n = {
children: [],
name: category,
id,
isOpenByDefault: !collapsed.get(id),
if (!noCategories) {
// find existing category to put track into or create it
for (let i = 0; i < categories.length; i++) {
const category = categories[i]
const ret = currLevel.children.find(c => c.name === category)
const id = [extra, categories.slice(0, i + 1).join(',')]
.filter(f => !!f)
.join('-')
if (!ret) {
const n = {
children: [],
name: category,
id,
isOpenByDefault: !collapsed.get(id),
menuItems,
}
currLevel.children.push(n)
currLevel = n
} else {
currLevel = ret
}
currLevel.children.push(n)
currLevel = n
} else {
currLevel = ret
}
}

Expand All @@ -127,7 +136,8 @@ export function generateHierarchy({
const r = currLevel.children.findIndex(elt => elt.children.length)
const idx = r === -1 ? currLevel.children.length : r
currLevel.children.splice(idx, 0, {
id: conf.trackId,
id: [extra, conf.trackId].filter(f => !!f).join(','),
trackId: conf.trackId,
name: getTrackName(conf, session),
conf,
checked: viewTracks.some(f => f.configuration === conf),
Expand Down
Loading
Loading