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
22 changes: 21 additions & 1 deletion src/viewer/app/derive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ROWS, SIDEBAR } from '../../shared/fixtures/grid';
import type { Account, Position } from '../../shared/model';
import { buildDataset } from '../../shared/parse';
import { sortPositions } from './position-columns';
import { median, incomeMedian, dripMin, asKind, ALL_FOLD, toggleFold, moveAccount, moveGroup, stepMove, orderAccounts, sortAccounts, scopeOf, toggleAccount, accountsIn, allocation, groupsOf, movers, near52, positionsIn, rangeRows, payoutParts, payDatesIn, securitiesBySymbol, incomeFacts, kindOf, ofKind, toggleKind, kindOn, addMonths, localToday, incomeIn, periodBounds, rangePos, totalsOf, upcomingDividends, payoutTotal, weightedRate, adjustedDrip, rowDripAdj, rowDripAdjUsd, yieldNote, sortDividends, toggleDivSort, asDivSorts, divChips, divSizeOf, toggleDivChip, setDivSize, asDivSize, validScope, dripGap, perPayment, windowEnd, asDivWindow, symbolDrip, dripToBuy, scopeTitle, dripMinAdj, dripMinAdjUsd, framedChips } from './derive';
import { median, incomeMedian, dripMin, asKind, ALL_FOLD, toggleFold, moveAccount, moveGroup, stepMove, orderAccounts, sortAccounts, scopeOf, toggleAccount, accountsIn, allocation, groupsOf, movers, near52, positionsIn, rangeRows, payoutParts, payDatesIn, securitiesBySymbol, incomeFacts, kindOf, ofKind, toggleKind, kindOn, addMonths, localToday, incomeIn, periodBounds, rangePos, totalsOf, upcomingDividends, payoutTotal, weightedRate, adjustedDrip, rowDripAdj, rowDripAdjUsd, yieldNote, sortDividends, toggleDivSort, asDivSorts, divChips, divSizeOf, toggleDivChip, setDivSize, asDivSize, validScope, dripGap, perPayment, windowEnd, asDivWindow, symbolDrip, dripToBuy, scopeTitle, dripMinAdj, dripMinAdjUsd, framedChips, toggleGroup } from './derive';

const ds = buildDataset({ rows: ROWS, sidebar: SIDEBAR, asOf: null, builtAt: 't' });

Expand Down Expand Up @@ -114,6 +114,26 @@ test('the frame goes on the highest chip chosen whole: All accounts, a group, el
expect(framed('X')).toEqual([]);
});

test('the group checkbox keeps only its group when every account is chosen, else adds or takes the group', () => {
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'), acc('R2', 'Retirement'), acc('K', 'Other')] };
const pick = (group: string, ...n: string[]) => toggleGroup(d, new Set(n), group);
// all chosen: only Investment, and the frame then goes on the group
const only = pick('Investment', 'A', 'B', 'R1', 'R2', 'K');
expect(accountsIn(d, only).map((a) => a.number)).toEqual(['A', 'B']);
expect(Array.from(framedChips(d, new Set(['A', 'B'])))).toEqual(['group:Investment']);
// some chosen, the group whole: taken away
expect(accountsIn(d, pick('Investment', 'A', 'B', 'K')).map((a) => a.number)).toEqual(['K']);
// some chosen, the group partly or not at all: added
expect(accountsIn(d, pick('Retirement', 'A', 'R1')).map((a) => a.number)).toEqual(['A', 'R1', 'R2']);
expect(accountsIn(d, pick('Other', 'A')).map((a) => a.number)).toEqual(['A', 'K']);
// nothing chosen: the group; the only group taken away: nothing
expect(accountsIn(d, pick('Other')).map((a) => a.number)).toEqual(['K']);
expect(pick('Other', 'K')).toBe('none');
// a group that is not there changes nothing
expect(accountsIn(d, pick('Nope', 'A')).map((a) => a.number)).toEqual(['A']);
});

test('my order of accounts: moved within the bar, groups stay put', () => {
const acc = (number: string, group: string) => ({ number, name: number, group, asOf: 't' });
const d = { ...ds, accounts: [acc('A', 'Investment'), acc('B', 'Investment'), acc('C', 'Investment'), acc('R1', 'Retirement'), acc('R2', 'Retirement')] };
Expand Down
13 changes: 13 additions & 0 deletions src/viewer/app/derive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ export function framedChips(ds: Dataset, shown: ReadonlySet<string>): Set<string
return out;
}

/**
* The group checkbox: with every account chosen it keeps only that group (owner 2026-12-03: "I selected Investments group
* but its not highlights", asked: only this group), so the frame goes on it (framedChips); otherwise it adds the group's
* accounts, or takes them away when the whole group is chosen
*/
export function toggleGroup(ds: Dataset, shown: ReadonlySet<string>, group: string): Scope {
const mine = groupsOf(ds).find((g) => g.name === group)?.accounts.map((a) => a.number) ?? [];
if (!mine.length) return scopeOf(ds, Array.from(shown));
if (ds.accounts.every((a) => shown.has(a.number))) return scopeOf(ds, mine);
const others = Array.from(shown).filter((n) => mine.indexOf(n) < 0);
return scopeOf(ds, mine.every((n) => shown.has(n)) ? others : others.concat(mine));
}

/** the account checkbox (owner 2026-11-23: "only Elena and Elena ROTH IRA"): adds or removes one account */
export function toggleAccount(ds: Dataset, scope: Scope, number: string): Scope {
const now = accountsIn(ds, scope).map((a) => a.number);
Expand Down
8 changes: 2 additions & 6 deletions src/viewer/ui/AccountTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useRef, useState } from 'react';
import type { Account, Dataset } from '../../shared/model';
import { ALL_FOLD, accountsIn, framedChips, groupsOf, scopeOf, stepMove, toggleAccount } from '../app/derive';
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';
Expand Down Expand Up @@ -87,10 +87,6 @@ export function AccountTabs({ ds, scope, collapsed, className, onScope, onFold,
{groups.map((g) => {
const open = !collapsed.includes(g.name);
const inGroup = g.accounts.filter((a) => shown.has(a.number)).length;
const toggleGroup = () => {
const others = Array.from(shown).filter((n) => !g.accounts.some((a) => a.number === n));
onScope(scopeOf(ds, inGroup === g.accounts.length ? others : others.concat(g.accounts.map((a) => a.number))));
};
return (
<div key={g.name} className={`flex flex-none items-center pl-1.5 ${overGroup === g.name ? 'rounded-lg outline-2 outline-dashed outline-[var(--brand)]' : ''} ${draggedGroup === g.name ? 'opacity-50' : ''}`}
onDragOver={(e) => { if (draggedGroup && draggedGroup !== g.name) { e.preventDefault(); setOverGroup(g.name); } }}
Expand All @@ -103,7 +99,7 @@ export function AccountTabs({ ds, scope, collapsed, className, onScope, onFold,
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)}
<Check checked={inGroup === g.accounts.length} mixed={inGroup > 0} label={t('Show {name}', { name: g.name })} onChange={toggleGroup} />
<Check checked={inGroup === g.accounts.length} mixed={inGroup > 0} label={t('Show {name}', { name: g.name })} onChange={() => onScope(toggleGroup(ds, shown, g.name))} />
<span>{g.name}</span>
</div>
<div className={`hslide ${open ? 'open' : ''}`} inert={!open}><div>{g.accounts.map((a) => accountChip(a, g.accounts))}</div></div>
Expand Down