Skip to content

Commit

Permalink
Bulk delete session tracks (#4736)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin authored Dec 19, 2024
1 parent 1d793a1 commit 5d48ad8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ const ShoppingCart = observer(function ({
}: {
model: HierarchicalTrackSelectorModel
}) {
const session = getSession(model)
const { selection } = model
const { pluginManager } = getEnv(model)
const session = getSession(model)
const { adminMode, sessionTracks } = session
const s = new Set<string>(sessionTracks?.map(t => t.trackId))
const canEdit = (t: string) => adminMode || s.has(t)
const items = pluginManager.evaluateExtensionPoint(
'TrackSelector-multiTrackMenuItems',
[],
Expand All @@ -25,11 +28,23 @@ const ShoppingCart = observer(function ({
<CascadingMenuButton
menuItems={[
{
label: 'Clear',
label: 'Clear selection',
onClick: () => {
model.clearSelection()
},
},
...(selection.every(elt => canEdit(elt.trackId))
? [
{
label: 'Delete tracks',
onClick: () => {
// @ts-expect-error
selection.forEach(s => session.deleteTrackConf?.(s))
},
},
]
: []),

...items.map(item => ({
...item,
...('onClick' in item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export default function TrackLabel({ data }: { data: NodeData }) {
id,
trackId,
name,
onChange,
selected,
onChange,
} = data
const description = readConfObject(conf, 'description')
return (
Expand All @@ -53,6 +53,16 @@ export default function TrackLabel({ data }: { data: NodeData }) {
>
<FormControlLabel
className={classes.checkboxLabel}
onClick={event => {
if (event.ctrlKey || event.metaKey) {
if (selected) {
model.removeFromSelection([conf])
} else {
model.addToSelection([conf])
}
event.preventDefault()
}
}}
control={
<Checkbox
className={classes.compactCheckbox}
Expand All @@ -70,7 +80,7 @@ export default function TrackLabel({ data }: { data: NodeData }) {
label={
<div
data-testid={`htsTrackLabel-${id}`}
style={{ background: selected ? '#cccc' : undefined }}
className={selected ? classes.selected : undefined}
>
<SanitizedHTML html={name} />
</div>
Expand Down

0 comments on commit 5d48ad8

Please sign in to comment.