diff --git a/src/viewer/app/derive.test.ts b/src/viewer/app/derive.test.ts index 021338a..88f0f58 100644 --- a/src/viewer/app/derive.test.ts +++ b/src/viewer/app/derive.test.ts @@ -602,3 +602,18 @@ test('median of a month, quarter or year: the periods from the one of the first expect(incomeMedian({ ...s, synced: {} }, [acct], [], 'all', '2026-12-02', 'Y')).toBeNull(); expect([median([3, 1, 2]), median([1, 4]), median([1.005, 2])]).toEqual([2, 2.5, 1.5]); }); + +test('the strip on the scope tree, kept in today\'s words: ticked leaves, folds, moves', async () => { + const { leavesOfScope, scopeOfLeaves, foldKey, moveChip } = await import('./derive'); + const acc = (number: string, group: string) => ({ number, name: number, group, asOf: 't' }); + const d = { ...ds, accounts: [acc('A', 'Investment'), acc('B', 'Investment'), acc('R1', 'Retirement')] }; + expect(Array.from(leavesOfScope(d, 'group:Investment'))).toEqual(['fidelity:A', 'fidelity:B']); + expect(Array.from(leavesOfScope(d, 'none'))).toEqual([]); + expect(scopeOfLeaves(d, new Set(['fidelity:R1']))).toBe('account:R1'); + expect(scopeOfLeaves(d, new Set(['fidelity:A', 'fidelity:B', 'fidelity:R1']))).toBe('all'); + expect(scopeOfLeaves(d, new Set(['fidelity:gone']))).toBe('none'); + expect([foldKey('all'), foldKey('group:fidelity/Retirement')]).toEqual([ALL_FOLD, 'Retirement']); + expect(moveChip(d, 'fidelity:B', 'fidelity:A')).toEqual({ accountOrder: ['B', 'A', 'R1'] }); + expect(moveChip(d, 'group:fidelity/Retirement', 'group:fidelity/Investment')).toEqual({ groupOrder: ['Retirement', 'Investment'] }); + expect(moveChip(d, 'fidelity:A', 'group:fidelity/Retirement')).toBeNull(); +}); diff --git a/src/viewer/app/derive.ts b/src/viewer/app/derive.ts index 9283330..26f606e 100644 --- a/src/viewer/app/derive.ts +++ b/src/viewer/app/derive.ts @@ -5,7 +5,7 @@ import type { Account, Dataset, Position } from '../../shared/model'; import { incomeReceived, isIncome, type TxnStore } from '../../shared/transactions'; import { incomeTax, type IncomeTax } from './income-tax'; import type { Scope } from './prefs'; -import { FIDELITY, buildTree, fidelityLeaf, framedNodes, groupAccounts, groupId, scopeOf as leavesShown, toggleLeaf, toggleNode, type ScopeNode } from './scope-tree'; +import { FIDELITY, ROOT, buildTree, fidelityLeaf, framedNodes, groupAccounts, groupId, scopeOf as leavesShown, toggleLeaf, toggleNode, type ScopeNode } from './scope-tree'; import { addDays, addMonths } from '../../shared/dates'; import { perYear } from '../../shared/typed-columns'; @@ -32,6 +32,23 @@ const numbersOf = (tree: ScopeNode, leaves: ReadonlySet): string[] => le const GROUP_KEY = groupId(FIDELITY, ''); const chipKey = (id: string): string => (id.startsWith(GROUP_KEY) ? `group:${id.slice(GROUP_KEY.length)}` : id.startsWith(fidelityLeaf('')) ? `account:${id.slice(fidelityLeaf('').length)}` : id); +/** the scope kept in today's words as the ticked leaves of the tree ('none': nothing ticked, 'all': every leaf) */ +export const leavesOfScope = (ds: Dataset, scope: Scope): Set => leafSet(accountsIn(ds, scope).map((a) => a.number)); +/** the ticked leaves of the strip as the scope kept in today's words */ +export const scopeOfLeaves = (ds: Dataset, leaves: ReadonlySet): Scope => scopeOf(ds, numbersOf(fidelityTree(ds), leaves)); +/** a chip of the strip as its mark in `Prefs.collapsed`: ALL_FOLD for the root, the name of a group */ +export const foldKey = (id: string): string => (id === ROOT ? ALL_FOLD : id.startsWith(GROUP_KEY) ? id.slice(GROUP_KEY.length) : id); +/** + * A chip dropped before another of its parent (a drag or Alt+arrows on the strip) as the owner's order to keep: accounts + * within their group (`accountOrder`), groups as a whole (`groupOrder`); null for chips that do not move together + */ +export function moveChip(ds: Dataset, moved: string, target: string): { accountOrder: string[] } | { groupOrder: string[] } | null { + const leaf = fidelityLeaf(''); + if (moved.startsWith(leaf) && target.startsWith(leaf)) return { accountOrder: moveAccount(ds.accounts, moved.slice(leaf.length), target.slice(leaf.length)) }; + if (moved.startsWith(GROUP_KEY) && target.startsWith(GROUP_KEY)) return { groupOrder: moveGroup(groupsOf(ds).map((g) => g.name), moved.slice(GROUP_KEY.length), target.slice(GROUP_KEY.length)) }; + return null; +} + /** * The owner's own order (owner 2026-11-24): groups move as a whole with their accounts, accounts move inside their * group; accounts in `order` come by its index, the rest keep the site's order after them diff --git a/src/viewer/ui/AccountTabs.tsx b/src/viewer/ui/AccountTabs.tsx deleted file mode 100644 index 9586d25..0000000 --- a/src/viewer/ui/AccountTabs.tsx +++ /dev/null @@ -1,113 +0,0 @@ -import { useRef, useState } from 'react'; -import type { Account, Dataset } from '../../shared/model'; -import { ALL_FOLD, accountsIn, framedChips, groupsOf, stepMove, toggleAccount, toggleGroup } from '../app/derive'; -import { chipActivates, chipStep } from '../app/focus'; -import { t } from '../app/i18n'; -import type { Scope } from '../app/prefs'; -import { Check } from './Check'; -import { chipClass } from './chip'; -import { EdgeScrollRow } from './EdgeScrollRow'; -import { useKeepFocus } from './useKeepFocus'; - -// The accounts strip (owner 2026-11-23): one line per chip. No view-transition names here (owner 2026-11-24 glitch): a -// named chip leaves the strip's clip during a card transition and flashes past its right edge. It lives in the navbar between the logo and the buttons and -// scrolls sideways with fading edges and ‹ › (owner 2026-11-24: like the gex Expirations panel). The chips share one background and -// differ by their line (CHIP_LINE below), so a section never looks like an account. A click on All accounts or a group folds or unfolds it (All -// accounts unfolds every group); a click on an account shows only it. Checkboxes alone choose: All accounts ticks or -// clears every account, a group its accounts, an account itself, so any set can be shown (Elena + Elena ROTH IRA). -// Names only, no balances, changes or account numbers (owner 2026-11-24: the Balance card shows the numbers; the -// number stays in the chip's tooltip) - -// Enter or Space on a chip presses it like a button (Space without scrolling the page); keys of the checkbox inside it -// bubble up and are not the chip's (Enter on the All accounts box folded the strip). Alt+Left and Alt+Right move a group -// or an account chip one place (`move`), the keyboard path of the drag; on such a chip the key is always taken, even at the -// end of its row, so it is not also the browser's Alt+Left (back) -const chipKey = (press: () => void, move?: (step: -1 | 1) => void) => (e: React.KeyboardEvent) => { - const self = e.target === e.currentTarget; - if (chipActivates(e.key, self)) { e.preventDefault(); press(); return; } - if (!move) return; - const step = chipStep(e.key, e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey, self); - if (step) { e.preventDefault(); move(step); } -}; -// the same keys for a screen reader (aria-keyshortcuts), no new words on the chips -const MOVE_KEYS = 'Alt+ArrowLeft Alt+ArrowRight'; - -export function AccountTabs({ ds, scope, collapsed, className, onScope, onFold, onMove, onMoveGroup }: { ds: Dataset; scope: Scope; collapsed: string[]; className?: string; onScope: (s: Scope) => void; onFold: (name: string) => void; onMove: (moved: string, target: string) => void; onMoveGroup: (moved: string, target: string) => void }) { - // drag an account chip onto another account of its group to put it there (owner 2026-11-24: my own order) - const [dragged, setDragged] = useState<{ number: string; group: string } | null>(null); - // a group chip is dragged as a whole (with its accounts) onto another group; All accounts stays first - const [draggedGroup, setDraggedGroup] = useState(null); - const [overGroup, setOverGroup] = useState(null); - const [over, setOver] = useState(null); - const shown = new Set(accountsIn(ds, scope).map((a) => a.number)); - // the frame of the chosen look on the highest chip chosen whole (app/derive.ts framedChips) - const framed = framedChips(ds, shown); - // a chip moved by the keys keeps the focus (its node may move), so the next Alt+arrow moves it again - const bar = useRef(null); - const keep = useKeepFocus(bar, 'data-scope', ds); - // one step of `id` among `order` through the drop-before rule of the drag (`drop`: onMove or onMoveGroup) - const stepper = (order: string[], id: string, scopeKey: string, drop: (moved: string, target: string) => void) => (step: -1 | 1) => { - const pair = stepMove(order, id, step); - if (!pair) return; - keep(scopeKey); - drop(pair[0], pair[1]); - }; - const groups = groupsOf(ds); - const chip = chipClass; - const allFolded = collapsed.includes(ALL_FOLD); - const chev = (open: boolean) => ▶; - const accountChip = (a: Account, siblings: Account[]) => ( -
{ setDragged({ number: a.number, group: a.group }); e.dataTransfer.effectAllowed = 'move'; e.dataTransfer.setData('text/plain', a.number); }} - onDragEnd={() => { setDragged(null); setOver(null); }} - onDragOver={(e) => { if (dragged && dragged.group === a.group && dragged.number !== a.number) { e.preventDefault(); setOver(a.number); } }} - onDragLeave={() => setOver((o) => (o === a.number ? null : o))} - onDrop={(e) => { e.preventDefault(); if (dragged && dragged.group === a.group && dragged.number !== a.number) onMove(dragged.number, a.number); setDragged(null); setOver(null); }} - onClick={() => onScope(`account:${a.number}`)} onBlur={() => keep(null)} aria-keyshortcuts={MOVE_KEYS} - onKeyDown={chipKey(() => onScope(`account:${a.number}`), stepper(siblings.map((x) => x.number), a.number, `account:${a.number}`, onMove))} data-scope={`account:${a.number}`}> - onScope(toggleAccount(ds, scope, a.number))} /> - {a.name} -
- ); - return ( - // All accounts stays on the very left, the groups and accounts after it scroll (owner 2026-11-24); the strip is as - // wide as its chips and sits in the middle between the logo and the buttons when they all fit (owner 2026-11-24) -
-
onFold(ALL_FOLD)} onKeyDown={chipKey(() => onFold(ALL_FOLD))} data-scope="all"> - {chev(!allFolded)} - {/* like the groups (owner 2026-11-24): ticked = every account, partly = some; a click ticks all or clears all */} - 0} label={t('Show {name}', { name: t('All accounts') })} - onChange={() => onScope(shown.size === ds.accounts.length ? 'none' : 'all')} /> - {t('All accounts')} -
-
- - {groups.map((g) => { - const open = !collapsed.includes(g.name); - const inGroup = g.accounts.filter((a) => shown.has(a.number)).length; - return ( -
{ if (draggedGroup && draggedGroup !== g.name) { e.preventDefault(); setOverGroup(g.name); } }} - onDragLeave={(e) => { if (!e.currentTarget.contains(e.relatedTarget as Node)) setOverGroup((o) => (o === g.name ? null : o)); }} - onDrop={(e) => { if (draggedGroup && draggedGroup !== g.name) { e.preventDefault(); onMoveGroup(draggedGroup, g.name); } setDraggedGroup(null); setOverGroup(null); }}> -
onFold(g.name)} - title={t('{name}: click to fold or unfold, drag to move the group', { name: g.name })} draggable - onDragStart={(e) => { e.stopPropagation(); setDraggedGroup(g.name); e.dataTransfer.effectAllowed = 'move'; e.dataTransfer.setData('text/plain', g.name); }} - onDragEnd={() => { setDraggedGroup(null); setOverGroup(null); }} - onBlur={() => keep(null)} aria-keyshortcuts={MOVE_KEYS} - onKeyDown={chipKey(() => onFold(g.name), stepper(groups.map((x) => x.name), g.name, `group:${g.name}`, onMoveGroup))} data-scope={`group:${g.name}`}> - {chev(open)} - 0} label={t('Show {name}', { name: g.name })} onChange={() => onScope(toggleGroup(ds, shown, g.name))} /> - {g.name} -
-
{g.accounts.map((a) => accountChip(a, g.accounts))}
-
- ); - })} -
-
-
- ); -} diff --git a/src/viewer/ui/AdpSourceChips.tsx b/src/viewer/ui/AdpSourceChips.tsx index be8522f..4c3d7d4 100644 --- a/src/viewer/ui/AdpSourceChips.tsx +++ b/src/viewer/ui/AdpSourceChips.tsx @@ -1,12 +1,10 @@ /// import { ADP_SOURCES, allSources, onlySource, toggleSource, type AdpSourceChip } from '../app/adp-sources'; -import { chipActivates } from '../app/focus'; import { t } from '../app/i18n'; -import { Check } from './Check'; -import { chipClass } from './chip'; +import { Chip } from './Chip'; // The navbar strip of the ADP pages (owner 2026-11-30): the money sources of the 401k in place of the Fidelity accounts, -// with the look of the accounts strip (chip.ts). A click on a source shows only it, its checkbox adds or removes it, All +// with the look and the keys of the accounts strip (ui/Chip.tsx). A click on a source shows only it, its checkbox adds or removes it, All // sources shows every one or none (rules in app/adp-sources.ts) const NAME = (): Record => ({ roth: t('Roth'), pretax: t('Pre-tax'), employer: t('Employer'), other: t('Earnings and other') }); const HINT = (): Record => ({ @@ -15,7 +13,6 @@ const HINT = (): Record => ({ employer: t('The employer match and other employer money'), other: t('Dividends and earnings, transfers and fees: the rows with no source'), }); -const press = (go: () => void) => (e: React.KeyboardEvent) => { if (chipActivates(e.key, e.target === e.currentTarget)) { e.preventDefault(); go(); } }; // every chip always, rows or not (owner 2026-11-30: controls always shown, so the strip never jumps) export function AdpSourceChips({ hidden, className, onChange }: { hidden: readonly AdpSourceChip[]; className?: string; onChange: (hidden: AdpSourceChip[]) => void }) { @@ -25,21 +22,14 @@ export function AdpSourceChips({ hidden, className, onChange }: { hidden: readon const hint = HINT(); return (
-
onChange([])} onKeyDown={press(() => onChange([]))} data-source="all"> - 0} label={t('Show {name}', { name: t('All sources') })} - onChange={() => onChange(allSources(hidden))} /> - {t('All sources')} -
+ onChange([])} data-source="all" + check={{ checked: shown.length === present.length, mixed: shown.length > 0, label: t('Show {name}', { name: t('All sources') }), onChange: () => onChange(allSources(hidden)) }} /> {present.map((s) => { const only = onlySource(s); const isOnly = only.every((x) => hidden.indexOf(x) >= 0) && hidden.indexOf(s) < 0; return ( -
onChange(only)} onKeyDown={press(() => onChange(only))} data-source={s}> - onChange(toggleSource(hidden, s))} /> - {name[s]} -
+ onChange(only)} data-source={s} + check={{ checked: hidden.indexOf(s) < 0, label: t('Show {name}', { name: name[s] }), onChange: () => onChange(toggleSource(hidden, s)) }} /> ); })}
diff --git a/src/viewer/ui/App.tsx b/src/viewer/ui/App.tsx index a0e29d6..464888b 100644 --- a/src/viewer/ui/App.tsx +++ b/src/viewer/ui/App.tsx @@ -1,7 +1,8 @@ /// import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import type { Account } from '../../shared/model'; -import { accountsIn, groupsOf, localToday, moveAccount, moveGroup, orderAccounts, scopeTitle, toggleFold, validScope } from '../app/derive'; +import { accountsIn, foldKey, leavesOfScope, localToday, moveChip, orderAccounts, scopeOfLeaves, scopeTitle, toggleFold, validScope } from '../app/derive'; +import { TREE_WORDS, buildTree } from '../app/scope-tree'; import { adpHistory, autoWatch, dataset, loginSaved, sheetPin, transactions, watchChosen, watching } from '../app/data'; import { connectGoogle, sheets } from '../app/google'; import { lang, t } from '../app/i18n'; @@ -13,7 +14,6 @@ import { squashed } from '../app/squash'; import { taxYears } from '../app/taxes-page'; import { APP_VERSION, isOlder } from '../app/version'; import { loadConfig } from '../../shared/sheets/gis'; -import { AccountTabs } from './AccountTabs'; import { Activity } from './Activity'; import { AdpActivity } from './AdpActivity'; import { AdpSourceChips } from './AdpSourceChips'; @@ -27,6 +27,7 @@ import { Logo } from './Logo'; import { MenuToggle, Slot, Traveler } from './MobileMenu'; import { Notices } from './Notices'; import { Positions } from './Positions'; +import { ScopeStrip } from './ScopeStrip'; import { EdgeScrollRow } from './EdgeScrollRow'; import { SettingsPanel, SettingsTools } from './SettingsPanel'; import { SlidePanel } from './SlidePanel'; @@ -168,6 +169,9 @@ export function App() { // list made Summary and Positions work every number out again const accounts = useMemo(() => (ds ? (scope === 'none' ? ds.accounts : accountsIn(ds, scope)) : NO_ACCOUNTS), [ds, scope]); const one = accounts.length === 1 ? accounts[0] : null; + // the strip draws the scope tree of the Fidelity accounts (app/scope-tree.ts); the scope is kept in today's words + const tree = useMemo(() => (ds ? buildTree({ fidelity: ds.accounts }, { ...TREE_WORDS, all: t('All accounts') }) : null), [ds, language]); + const ticked = useMemo(() => (ds ? leavesOfScope(ds, scope) : new Set()), [ds, scope]); // the name of what is shown titles the Balance card (owner 2026-11-24), the right of the tabs keeps only the time const title = !ds ? '' : scopeTitle(scope, accounts, { all: t('All accounts'), count: (n) => t('{n} accounts', { n }) }); const year = new Date().getFullYear(); @@ -214,10 +218,9 @@ export function App() { {/* the ADP pages show the 401k's money sources there instead of the Fidelity accounts (owner 2026-11-30) */} {ds && adpPage && adp &&