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

-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) => {