Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions src/viewer/app/derive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
19 changes: 18 additions & 1 deletion src/viewer/app/derive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -32,6 +32,23 @@ const numbersOf = (tree: ScopeNode, leaves: ReadonlySet<string>): 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<string> => 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<string>): 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
Expand Down
113 changes: 0 additions & 113 deletions src/viewer/ui/AccountTabs.tsx

This file was deleted.

22 changes: 6 additions & 16 deletions src/viewer/ui/AdpSourceChips.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/// <reference lib="esnext" />
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<AdpSourceChip, string> => ({ roth: t('Roth'), pretax: t('Pre-tax'), employer: t('Employer'), other: t('Earnings and other') });
const HINT = (): Record<AdpSourceChip, string> => ({
Expand All @@ -15,7 +13,6 @@ const HINT = (): Record<AdpSourceChip, string> => ({
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 }) {
Expand All @@ -25,21 +22,14 @@ export function AdpSourceChips({ hidden, className, onChange }: { hidden: readon
const hint = HINT();
return (
<div className={`flex min-w-0 items-center justify-center gap-1.5 overflow-x-auto ${className ?? ''}`} data-adp-sources>
<div role="button" tabIndex={0} className={chipClass('all', hidden.length === 0)} title={t('Show every source')}
onClick={() => onChange([])} onKeyDown={press(() => 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))} />
<span>{t('All sources')}</span>
</div>
<Chip kind="all" active={hidden.length === 0} label={t('All sources')} title={t('Show every source')} press={() => 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 (
<div key={s} role="button" tabIndex={0} className={chipClass('account', isOnly)} title={hint[s]}
onClick={() => onChange(only)} onKeyDown={press(() => onChange(only))} data-source={s}>
<Check checked={hidden.indexOf(s) < 0} label={t('Show {name}', { name: name[s] })} onChange={() => onChange(toggleSource(hidden, s))} />
<span>{name[s]}</span>
</div>
<Chip key={s} kind="account" active={isOnly} label={name[s]} title={hint[s]} press={() => onChange(only)} data-source={s}
check={{ checked: hidden.indexOf(s) < 0, label: t('Show {name}', { name: name[s] }), onChange: () => onChange(toggleSource(hidden, s)) }} />
);
})}
</div>
Expand Down
Loading