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 7 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
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 Favorites tracks',
carolinebridge marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -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,7 +93,7 @@ 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)
}
}
},
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,16 @@ function TrackMenuButton({
data-testid={`htsTrackEntryMenu-${id}`}
menuItems={[
...(getSession(model).getTrackActionMenuItems?.(conf) || []),
{
label: model.isFavorite(conf)
carolinebridge marked this conversation as resolved.
Show resolved Hide resolved
? 'Remove from favorites'
: 'Add to favorites',
onClick: () =>
model.isFavorite(conf)
? model.removeFromFavorites(conf)
: model.addToFavorites(conf),
icon: model.isFavorite(conf) ? FilledStarIcon : StarIcon,
},
{
label: 'Add to selection',
onClick: () => model.addToSelection([conf]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface NodeData {
conf: AnyConfigurationModel
drawerPosition: unknown
id: string
trackId: string
isLeaf: boolean
name: string
onChange: Function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function sortConfs(
export interface TreeNode {
name: string
id: string
trackId?: string
conf?: AnyConfigurationModel
checked?: boolean
isOpenByDefault?: boolean
Expand All @@ -55,6 +56,7 @@ export function generateHierarchy({
model,
trackConfs,
extra,
noCategories,
}: {
model: {
filterText: string
Expand All @@ -65,6 +67,7 @@ export function generateHierarchy({
tracks: { configuration: AnyConfigurationModel }[]
}
}
noCategories?: boolean
trackConfs: AnyConfigurationModel[]
extra?: string
}): TreeNode[] {
Expand Down Expand Up @@ -100,24 +103,26 @@ 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),
}
currLevel.children.push(n)
currLevel = n
} else {
currLevel = ret
}
currLevel.children.push(n)
currLevel = n
} else {
currLevel = ret
}
}

Expand All @@ -127,7 +132,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