Cleaned up column settings

This commit is contained in:
patben8 committed 2026-09-25 11:05:14 +02:00
1 parent 73694fe532
commit 76bf142fb4
10 files changed
+125 -103

No files matched your search

+4 -2
View File
@@ -336,7 +336,7 @@ Two independent apps that talk over HTTP:
library meant restarting; switching confirms first when there are unsaved
edits, since the adapter holds them in a native model that opening another
library replaces — plus the playlist tree +
create/rename/delete), `SaveBar`, `Toolbar` (search/filters + `ColumnsMenu`),
create/rename/delete), `SaveBar` (+ the settings gear beside it), `Toolbar` (search/filters; columns are chosen by right-clicking the table header),
`TrackTable` (**the one track list** — All Tracks, playlists, exports and
devices. TanStack Table + **virtualized** grid; per-row play button,
configurable columns, header sorting, inline double-click editing, and
@@ -359,7 +359,9 @@ Two independent apps that talk over HTTP:
slot, a per-slot Replace tick for occupied slots — never remembered, since
overwriting is a decision about THIS track — and the template itself
persisted as `autoCueTemplate` in userprefs),
`ContextMenu` (supports `▸` submenus and section headings; "Add to" lists
`ContextMenu` (supports `▸` submenus, section headings, separators and
checkbox items that toggle without closing — the header row's right-click
column chooser uses those; "Add to" lists
playlists + exports and acts on the whole selection) + `EditTagsDialog`
(right-click → multi-field metadata + album-art edit), `StatusBar`,
`RatingStars` (read-only, or click-to-set when given `onChange`), `Toast`,
+29 -5
View File
@@ -5,6 +5,7 @@ import { CapabilitiesContext } from './lib/capabilities'
import { writeHint } from './lib/platformCopy'
import { api, type GridBatchResult, type PlaylistNode, type Track } from './api'
import {
COLUMN_MENU,
DEFAULT_COLUMN_ORDER,
DEFAULT_COLUMN_VISIBILITY,
} from './lib/trackColumns'
@@ -53,6 +54,8 @@ export default function App() {
// `ids` is what the menu acts on: the whole selection when the clicked row is
// part of it, otherwise just that row.
const [menu, setMenu] = useState<{ track: Track; ids: string[]; x: number; y: number } | null>(null)
// Right-click on the table header: the column chooser.
const [headerMenu, setHeaderMenu] = useState<{ x: number; y: number } | null>(null)
const [editing, setEditing] = useState<Track | null>(null)
const [showPaths, setShowPaths] = useState(false)
const [showHistory, setShowHistory] = useState(false)
@@ -624,6 +627,26 @@ export default function App() {
onClose={() => setMenu(null)}
/>
)}
{headerMenu && (
<ContextMenu
key={`${headerMenu.x}:${headerMenu.y}`}
x={headerMenu.x}
y={headerMenu.y}
items={[
{ heading: 'Columns' },
// Default-visible unless explicitly hidden, as in the Columns menu.
...COLUMN_MENU.map((c) => ({
label: c.label,
checked: columnVisibility[c.id] !== false,
onToggle: () =>
setColumnVisibility((v) => ({ ...v, [c.id]: v[c.id] === false })),
})),
{ separator: true as const },
{ label: 'Reset to defaults', onClick: resetColumns },
]}
onClose={() => setHeaderMenu(null)}
/>
)}
{editing && (
<EditTagsDialog
track={editing}
@@ -690,18 +713,15 @@ export default function App() {
onImport={() => setImporting(true)}
onSwitchLibrary={() => setForcePicker(true)}
onDone={(msg) => notify('success', msg)}
onOpenPathMapping={() => setShowPaths(true)}
/>
<CapabilitiesContext.Provider value={viewCaps}>
<main className="relative flex min-w-0 flex-1 flex-col">
{/* Search / filters / column settings — always visible. */}
{/* Search / filters — always visible. Columns are chosen by right-clicking the header. */}
<Toolbar
filters={filters}
onChange={setFilters}
columnVisibility={columnVisibility}
onColumnVisibilityChange={setColumnVisibility}
onResetColumns={resetColumns}
onOpenPathMapping={() => setShowPaths(true)}
/>
{(!isAll || viewingDevice) && (
<div className="flex items-center gap-3 border-b border-line bg-ink-900 px-4 py-2">
@@ -791,6 +811,7 @@ export default function App() {
onSortingChange={setSorting}
selection={{ selected, onChange: setSelected }}
onRowContextMenu={(track, x, y) => openMenu(track, x, y, true)}
onHeaderContextMenu={(x, y) => setHeaderMenu({ x, y })}
onPlay={playTrack}
onEditField={canEdit ? editField : undefined}
activeTrackId={prepTrack?.id ?? null}
@@ -824,6 +845,7 @@ export default function App() {
sorting={sorting}
onSortingChange={setSorting}
onRowContextMenu={(track, x, y) => openMenu(track, x, y, false)}
onHeaderContextMenu={(x, y) => setHeaderMenu({ x, y })}
onPlay={playTrack}
activeTrackId={prepTrack?.id ?? null}
columnVisibility={columnVisibility}
@@ -846,6 +868,7 @@ export default function App() {
onSortingChange={setSorting}
selection={{ selected, onChange: setSelected }}
onRowContextMenu={(track, x, y) => openMenu(track, x, y, true)}
onHeaderContextMenu={(x, y) => setHeaderMenu({ x, y })}
onPlay={playTrack}
onEditField={canEdit ? editField : undefined}
activeTrackId={prepTrack?.id ?? null}
@@ -882,6 +905,7 @@ export default function App() {
}
onRemove={playlistEditable ? removeFromPlaylist : undefined}
onRowContextMenu={(track, x, y) => openMenu(track, x, y, true)}
onHeaderContextMenu={(x, y) => setHeaderMenu({ x, y })}
onPlay={playTrack}
onEditField={canEdit ? editField : undefined}
activeTrackId={prepTrack?.id ?? null}
-67
View File
@@ -1,67 +0,0 @@
import { useEffect, useRef, useState } from 'react'
import type { VisibilityState } from '@tanstack/react-table'
import { COLUMN_MENU } from '../lib/trackColumns'
interface Props {
visibility: VisibilityState
onChange: (v: VisibilityState) => void
onReset: () => void
}
/** Dropdown of checkboxes to show/hide library columns, plus a layout reset. */
export function ColumnsMenu({ visibility, onChange, onReset }: Props) {
const [open, setOpen] = useState(false)
const ref = useRef<HTMLDivElement>(null)
useEffect(() => {
if (!open) return
const onDoc = (e: MouseEvent) => {
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false)
}
document.addEventListener('mousedown', onDoc)
return () => document.removeEventListener('mousedown', onDoc)
}, [open])
const isVisible = (id: string) => visibility[id] !== false // default-visible unless explicitly false
return (
<div ref={ref} className="relative">
<button
onClick={() => setOpen((o) => !o)}
className="flex items-center gap-1.5 rounded-md border border-line bg-ink-850 px-2.5 py-1.5 text-sm text-text transition-colors hover:border-ink-600"
title="Choose columns"
>
<span className="text-faint">▦</span> Columns
</button>
{open && (
<div className="absolute right-0 z-30 mt-1 w-52 rounded-md border border-line bg-ink-850 p-1 shadow-2xl">
<div className="max-h-80 overflow-y-auto p-1">
{COLUMN_MENU.map((c) => (
<label
key={c.id}
className="flex cursor-pointer items-center gap-2 rounded px-2 py-1.5 text-sm text-text hover:bg-ink-800"
>
<input
type="checkbox"
checked={isVisible(c.id)}
onChange={(e) => onChange({ ...visibility, [c.id]: e.target.checked })}
className="accent-accent"
/>
{c.label}
</label>
))}
</div>
<button
onClick={() => {
onReset()
setOpen(false)
}}
className="mt-1 w-full rounded px-2 py-1.5 text-left text-xs text-muted hover:bg-ink-800 hover:text-text"
>
Reset to defaults
</button>
</div>
)}
</div>
)
}
+31 -1
View File
@@ -4,7 +4,10 @@ import { useEffect, useRef, useState } from 'react'
export type MenuItem =
| { label: string; onClick: () => void; danger?: boolean; hint?: string; icon?: string; disabled?: boolean }
| { label: string; submenu: MenuItem[] }
// Toggles in place and leaves the menu open, so several can be flipped in one go.
| { label: string; checked: boolean; onToggle: () => void }
| { heading: string; empty?: string }
| { separator: true }
interface Props {
x: number
@@ -56,7 +59,10 @@ export function ContextMenu({ x, y, items, onClose }: Props) {
items={items}
onClose={onClose}
className="min-w-[160px]"
style={{ top: Math.min(y, window.innerHeight - 100), left: Math.min(x, window.innerWidth - 180) }}
style={(() => {
const top = Math.min(y, window.innerHeight - 100)
return { top, left: Math.min(x, window.innerWidth - 180), maxHeight: window.innerHeight - top - 8 }
})()}
/>
</div>
)
@@ -94,6 +100,30 @@ function MenuPanel({
style={style}
>
{items.map((item, i) => {
if ('separator' in item) {
return <div key={i} className="my-1 border-t border-line" />
}
if ('checked' in item) {
return (
<button
key={i}
role="menuitemcheckbox"
aria-checked={item.checked}
onMouseEnter={() => setOpen(null)}
onClick={item.onToggle}
className="flex w-full items-center gap-2 px-3 py-1.5 text-left text-sm text-muted hover:bg-ink-800 hover:text-text"
>
<span
className={`flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-sm border text-[10px] leading-none ${
item.checked ? 'border-accent bg-accent text-ink-950' : 'border-ink-600'
}`}
>
{item.checked ? '✓' : ''}
</span>
<span className="min-w-0 flex-1 truncate">{item.label}</span>
</button>
)
}
if ('heading' in item) {
return (
<div key={i}>
+11 -5
View File
@@ -1,4 +1,4 @@
import { useState } from 'react'
import { useState, type ReactNode } from 'react'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { api } from '../api'
import { useCaps } from '../lib/capabilities'
@@ -6,11 +6,13 @@ import { overwriteWarning, readOnlyNotice, saveLabel } from '../lib/platformCopy
interface Props {
onError: (msg: string) => void
/** Rendered to the right of the save button (the settings gear). */
trailing?: ReactNode
}
// Bottom-of-sidebar save control. Shows unsaved-changes state and writes to the
// NML; every save is recorded in the collection's version history.
export function SaveBar({ onError }: Props) {
export function SaveBar({ onError, trailing }: Props) {
const qc = useQueryClient()
const [justSaved, setJustSaved] = useState<string | null>(null)
const { data: state } = useQuery({ queryKey: ['state'], queryFn: api.state })
@@ -37,11 +39,12 @@ export function SaveBar({ onError }: Props) {
// point: a greyed-out button with no explanation reads as a bug.
if (readOnly) {
return (
<div className="border-t border-line bg-ink-900 px-3 py-3">
<div className="rounded-md bg-ink-800 px-2 py-2 text-[11px] leading-snug text-faint">
<div className="flex items-stretch gap-2 border-t border-line bg-ink-900 px-3 py-3">
<div className="min-w-0 flex-1 rounded-md bg-ink-800 px-2 py-2 text-[11px] leading-snug text-faint">
<span className="font-medium text-ink-200">Read-only</span>
<div className="mt-1">{readOnly}</div>
</div>
{trailing}
</div>
)
}
@@ -53,10 +56,11 @@ export function SaveBar({ onError }: Props) {
⚠ {warning}
</div>
)}
<div className="flex items-stretch gap-2">
<button
disabled={!dirty || save.isPending}
onClick={() => save.mutate()}
className={`flex w-full items-center justify-center gap-2 rounded-md px-3 py-2 text-sm font-medium transition-colors ${
className={`flex min-w-0 flex-1 items-center justify-center gap-2 rounded-md px-3 py-2 text-sm font-medium transition-colors ${
dirty
? 'bg-accent text-ink-950 hover:brightness-110'
: 'cursor-not-allowed bg-ink-800 text-faint'
@@ -73,6 +77,8 @@ export function SaveBar({ onError }: Props) {
'No unsaved changes'
)}
</button>
{trailing}
</div>
{justSaved && (
<div className="mt-2 text-center text-[11px] text-mint">{justSaved}</div>
)}
+9 -3
View File
@@ -2,11 +2,13 @@ import { useEffect, useRef, useState } from 'react'
interface Props {
onOpenPathMapping: () => void
/** Open the menu above the button — for a button at the bottom of the window. */
up?: boolean
}
/** Overflow menu for low-frequency, collection-level settings. Currently holds
* path remapping; the natural home for future advanced settings. */
export function SettingsMenu({ onOpenPathMapping }: Props) {
export function SettingsMenu({ onOpenPathMapping, up = false }: Props) {
const [open, setOpen] = useState(false)
const ref = useRef<HTMLDivElement>(null)
@@ -26,7 +28,7 @@ export function SettingsMenu({ onOpenPathMapping }: Props) {
<div ref={ref} className="relative">
<button
onClick={() => setOpen((o) => !o)}
className="flex items-center justify-center rounded-md border border-line bg-ink-850 px-2 py-1.5 text-muted transition-colors hover:border-ink-600 hover:text-text"
className="flex h-full items-center justify-center rounded-md border border-line bg-ink-850 px-2 py-1.5 text-muted transition-colors hover:border-ink-600 hover:text-text"
title="Settings"
aria-label="Settings"
>
@@ -44,7 +46,11 @@ export function SettingsMenu({ onOpenPathMapping }: Props) {
</svg>
</button>
{open && (
<div className="absolute right-0 z-30 mt-1 w-56 rounded-md border border-line bg-ink-850 p-1 shadow-2xl">
<div
className={`absolute right-0 z-30 w-56 rounded-md border border-line bg-ink-850 p-1 shadow-2xl ${
up ? 'bottom-full mb-1' : 'mt-1'
}`}
>
<button
onClick={() => {
onOpenPathMapping()
+4 -1
View File
@@ -3,6 +3,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { api, type PlaylistKind, type PlaylistNode } from '../api'
import { useCaps } from '../lib/capabilities'
import { SaveBar } from './SaveBar'
import { SettingsMenu } from './SettingsMenu'
import { DevicesSection } from './DevicesSection'
import { ExportsSection } from './ExportsSection'
@@ -39,6 +40,7 @@ interface Props {
onImport: () => void
onSwitchLibrary: () => void
onDone: (msg: string) => void
onOpenPathMapping: () => void
}
// Kind picks the icon; every behavioural question is answered by the node's own
@@ -259,6 +261,7 @@ export function Sidebar({
onImport,
onSwitchLibrary,
onDone,
onOpenPathMapping,
}: Props) {
const qc = useQueryClient()
// Both share a cache entry with App and SaveBar, so the header never
@@ -408,7 +411,7 @@ export function Sidebar({
Collection Version History
</button>
<SaveBar onError={onError} />
<SaveBar onError={onError} trailing={<SettingsMenu up onOpenPathMapping={onOpenPathMapping} />} />
</aside>
)
}
-17
View File
@@ -1,9 +1,6 @@
import { useQuery } from '@tanstack/react-query'
import type { VisibilityState } from '@tanstack/react-table'
import { api } from '../api'
import { useCaps } from '../lib/capabilities'
import { ColumnsMenu } from './ColumnsMenu'
import { SettingsMenu } from './SettingsMenu'
export interface Filters {
search: string
@@ -28,10 +25,6 @@ export const emptyFilters: Filters = {
interface Props {
filters: Filters
onChange: (f: Filters) => void
columnVisibility: VisibilityState
onColumnVisibilityChange: (v: VisibilityState) => void
onResetColumns: () => void
onOpenPathMapping: () => void
}
const selectCls =
@@ -40,10 +33,6 @@ const selectCls =
export function Toolbar({
filters,
onChange,
columnVisibility,
onColumnVisibilityChange,
onResetColumns,
onOpenPathMapping,
}: Props) {
const caps = useCaps()
const { data: facets } = useQuery({ queryKey: ['facets'], queryFn: api.facets })
@@ -145,12 +134,6 @@ export function Toolbar({
Clear filters
</button>
)}
<ColumnsMenu
visibility={columnVisibility}
onChange={onColumnVisibilityChange}
onReset={onResetColumns}
/>
<SettingsMenu onOpenPathMapping={onOpenPathMapping} />
</div>
</div>
)
+14 -1
View File
@@ -70,6 +70,8 @@ interface Props {
/** Delete/Backspace removes the selected tracks from this view. */
onRemove?: (ids: string[]) => void
onRowContextMenu?: (track: Track, x: number, y: number) => void
/** Right-click on the header row (the column chooser). */
onHeaderContextMenu?: (x: number, y: number) => void
onPlay?: (track: Track) => void
onEditField?: (track: Track, field: keyof Track, value: string | number) => void
activeTrackId?: string | null
@@ -184,11 +186,13 @@ function HeaderRow({
sensors,
onColumnDragEnd,
hasPlay,
onContextMenu,
}: {
headers: Header<Track, unknown>[]
sensors: ReturnType<typeof useSensors>
onColumnDragEnd: (e: DragEndEvent) => void
hasPlay: boolean
onContextMenu?: (x: number, y: number) => void
}) {
// True while (and just after) a column is being reordered, so the trailing
// click a drag emits is swallowed instead of toggling the sort.
@@ -209,7 +213,14 @@ function HeaderRow({
}, 0)
}}
>
<div className="sticky top-0 z-10 flex border-b border-line bg-ink-850">
<div
className="sticky top-0 z-10 flex border-b border-line bg-ink-850"
onContextMenu={(e) => {
if (!onContextMenu) return
e.preventDefault()
onContextMenu(e.clientX, e.clientY)
}}
>
<span className="w-10 shrink-0" />
{hasPlay && <span className="w-9 shrink-0" />}
<SortableContext
@@ -247,6 +258,7 @@ export function TrackTable({
reorder,
onRemove,
onRowContextMenu,
onHeaderContextMenu,
onPlay,
onEditField,
activeTrackId,
@@ -500,6 +512,7 @@ export function TrackTable({
sensors={sensors}
onColumnDragEnd={onColumnDragEnd}
hasPlay={hasPlay}
onContextMenu={onHeaderContextMenu}
/>
<div ref={bodyRef} style={{ height: virtualizer.getTotalSize(), position: 'relative' }}>
{virtualRows.map((vr) => {
+23 -1
View File
@@ -294,6 +294,28 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
/>
),
}),
col.accessor('filepath', {
id: 'path',
header: 'Path',
size: 320,
// Read-only: the path is the track's identity. Truncated from the LEFT
// (rtl box, ltr text) so the filename — the part you are looking for —
// stays visible; the full path is the tooltip.
cell: (c) => {
const v = c.getValue()
return v ? (
<div
className="w-full truncate text-xs text-muted"
style={{ direction: 'rtl', textAlign: 'left' }}
title={v}
>
<bdi>{v}</bdi>
</div>
) : (
<span className="text-faint">—</span>
)
},
}),
]
// Traktor dates arrive as "YYYY/M/D" strings; show them compactly (or raw).
@@ -304,7 +326,7 @@ function formatDate(v: string | null): string {
return `${m[1]}-${m[2].padStart(2, '0')}-${m[3].padStart(2, '0')}`
}
/** (id, label) pairs for the Columns menu, in the canonical definition order. */
/** (id, label) pairs for the header's column chooser, in definition order. */
export const COLUMN_MENU: { id: string; label: string }[] = TRACK_COLUMNS.map((c) => ({
id: c.id as string,
label: typeof c.header === 'string' ? c.header : (c.id as string),