A local-first personal finance app
sidebar pt. 4: accounts list (#8892)
Matt Fiddaman993a35c4ed72
diff --git a/packages/component-library/src/icons/v1/CheveronDownUp.tsx b/packages/component-library/src/icons/v1/CheveronDownUp.tsxnew file mode 100644index 0000000000..25a8413b5b--- /dev/null+++ b/packages/component-library/src/icons/v1/CheveronDownUp.tsx@@ -0,0 +1,18 @@+import * as React from 'react';+import type { SVGProps } from 'react';+export const SvgCheveronDownUp = (props: SVGProps<SVGSVGElement>) => (+ <svg+ {...props}+ xmlns="http://www.w3.org/2000/svg"+ viewBox="0 0 20 20"+ style={{+ color: 'inherit',+ ...props.style,+ }}+ >+ <path+ d="M10 8.24 4.99 3.23 6.42 1.8 10 5.38l3.58-3.58 1.43 1.43zm0 3.52 5.01 5.01-1.43 1.43L10 14.62 6.42 18.2l-1.43-1.43z"+ fill="currentColor"+ />+ </svg>+);diff --git a/packages/component-library/src/icons/v1/CheveronUpDown.tsx b/packages/component-library/src/icons/v1/CheveronUpDown.tsxnew file mode 100644index 0000000000..818053e362--- /dev/null+++ b/packages/component-library/src/icons/v1/CheveronUpDown.tsx@@ -0,0 +1,18 @@+import * as React from 'react';+import type { SVGProps } from 'react';+export const SvgCheveronUpDown = (props: SVGProps<SVGSVGElement>) => (+ <svg+ {...props}+ xmlns="http://www.w3.org/2000/svg"+ viewBox="0 0 20 20"+ style={{+ color: 'inherit',+ ...props.style,+ }}+ >+ <path+ d="m10 1.8 5.01 5.01-1.43 1.43L10 4.66 6.42 8.24 4.99 6.81zm0 16.4-5.01-5.01 1.43-1.43L10 15.34l3.58-3.58 1.43 1.43z"+ fill="currentColor"+ />+ </svg>+);diff --git a/packages/component-library/src/icons/v1/cheveron-down-up.svg b/packages/component-library/src/icons/v1/cheveron-down-up.svgnew file mode 100644index 0000000000..5dcf5508ac--- /dev/null+++ b/packages/component-library/src/icons/v1/cheveron-down-up.svg@@ -0,0 +1 @@+<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M10 8.24l-5.01-5.01 1.43-1.43L10 5.38l3.58-3.58 1.43 1.43L10 8.24zM10 11.76l5.01 5.01-1.43 1.43L10 14.62 6.42 18.2 4.99 16.77 10 11.76z"/></svg>diff --git a/packages/component-library/src/icons/v1/cheveron-up-down.svg b/packages/component-library/src/icons/v1/cheveron-up-down.svgnew file mode 100644index 0000000000..08a73d1369--- /dev/null+++ b/packages/component-library/src/icons/v1/cheveron-up-down.svg@@ -0,0 +1 @@+<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M10 1.8l5.01 5.01-1.43 1.43L10 4.66 6.42 8.24 4.99 6.81 10 1.8zM10 18.2l-5.01-5.01 1.43-1.43L10 15.34l3.58-3.58 1.43 1.43L10 18.2z"/></svg>diff --git a/packages/component-library/src/icons/v1/index.ts b/packages/component-library/src/icons/v1/index.tsindex 43aecc74cf..51c8b958cd 100644--- a/packages/component-library/src/icons/v1/index.ts+++ b/packages/component-library/src/icons/v1/index.ts@@ -76,6 +76,7 @@ export { SvgChatBubbleDots } from './ChatBubbleDots';export { SvgCheckAlternative } from './CheckAlternative';export { SvgCheckmarkOutline } from './CheckmarkOutline';export { SvgCheckmark } from './Checkmark';+export { SvgCheveronDownUp } from './CheveronDownUp';export { SvgCheveronDown } from './CheveronDown';export { SvgCheveronLeft } from './CheveronLeft';export { SvgCheveronOutlineDown } from './CheveronOutlineDown';@@ -83,6 +84,7 @@ export { SvgCheveronOutlineLeft } from './CheveronOutlineLeft';export { SvgCheveronOutlineRight } from './CheveronOutlineRight';export { SvgCheveronOutlineUp } from './CheveronOutlineUp';export { SvgCheveronRight } from './CheveronRight';+export { SvgCheveronUpDown } from './CheveronUpDown';export { SvgCheveronUp } from './CheveronUp';export { SvgClipboard } from './Clipboard';export { SvgCloseOutline } from './CloseOutline';diff --git a/packages/component-library/src/styles.ts b/packages/component-library/src/styles.tsindex 607da6ec26..0ba2ee833d 100644--- a/packages/component-library/src/styles.ts+++ b/packages/component-library/src/styles.ts@@ -133,6 +133,17 @@ export const styles: CSSProperties = {textOverflow: 'ellipsis',whiteSpace: 'nowrap',},+ visuallyHidden: {+ position: 'absolute',+ width: 1,+ height: 1,+ margin: -1,+ padding: 0,+ overflow: 'hidden',+ clip: 'rect(0 0 0 0)',+ whiteSpace: 'nowrap',+ border: 0,+ },tooltip: {padding: 5,...shadowLarge,diff --git a/packages/desktop-client/src/components/sidebar/redesign/AccountGroupHeader.tsx b/packages/desktop-client/src/components/sidebar/redesign/AccountGroupHeader.tsxnew file mode 100644index 0000000000..53cb88a9c6--- /dev/null+++ b/packages/desktop-client/src/components/sidebar/redesign/AccountGroupHeader.tsx@@ -0,0 +1,70 @@+import { Button } from '@actual-app/components/button';+import { styles } from '@actual-app/components/styles';+import { Text } from '@actual-app/components/text';+import { theme } from '@actual-app/components/theme';+import { radius, spacing } from '@actual-app/components/tokens';+import { View } from '@actual-app/components/view';+import type { AccountGroupEntity } from '@actual-app/core/types/models';+import { css } from '@emotion/css';++import * as bindings from '#spreadsheet/bindings';++import { CollapseChevron } from './CollapseChevron';+import { CountPill } from './CountPill';+import { SidebarBalance } from './SidebarBalance';+import { groupLabelStyle } from './styles';+import { SyncErrorRollup } from './SyncErrorRollup';++type AccountGroupHeaderProps = {+ group: AccountGroupEntity;+ side: 'on' | 'off';+ accountCount: number;+ failedCount: number;+ isOpen: boolean;+ onToggle: () => void;+};++export function AccountGroupHeader({+ group,+ side,+ accountCount,+ failedCount,+ isOpen,+ onToggle,+}: AccountGroupHeaderProps) {+ return (+ <Button+ variant="bare"+ aria-expanded={isOpen}+ onPress={onToggle}+ className={css({+ '&[data-hovered], &[data-focus-visible]': {+ backgroundColor: theme.sidebarItemBackgroundHover,+ },+ })}+ style={{+ flexDirection: 'row',+ alignItems: 'center',+ justifyContent: 'flex-start',+ gap: spacing.xs,+ paddingBlock: spacing.xs,+ paddingLeft: spacing.xs,+ paddingRight: spacing.sm,+ borderRadius: radius.sm,+ width: '100%',+ }}+ >+ <CollapseChevron isOpen={isOpen} size={11} />+ <Text style={{ ...groupLabelStyle, ...styles.ellipsisText }}>+ {group.name}+ </Text>+ {!isOpen && <CountPill count={accountCount} />}+ <SyncErrorRollup count={failedCount} />+ <View style={{ flex: 1 }} />+ <SidebarBalance+ binding={bindings.accountGroupBalance(group.id, side === 'off')}+ style={{ fontSize: 11, color: groupLabelStyle.color }}+ />+ </Button>+ );+}diff --git a/packages/desktop-client/src/components/sidebar/redesign/AccountRow.tsx b/packages/desktop-client/src/components/sidebar/redesign/AccountRow.tsxnew file mode 100644index 0000000000..ba72fea70f--- /dev/null+++ b/packages/desktop-client/src/components/sidebar/redesign/AccountRow.tsx@@ -0,0 +1,80 @@+import { styles } from '@actual-app/components/styles';+import { Text } from '@actual-app/components/text';+import { theme } from '@actual-app/components/theme';+import { radius, spacing } from '@actual-app/components/tokens';+import type { AccountEntity } from '@actual-app/core/types/models';++import { isAccountFailedSync } from '#accounts/syncStatus';+import { Link } from '#components/common/Link';+import { useUpdatedAccounts } from '#hooks/useUpdatedAccounts';+import { useSelector } from '#redux';+import * as bindings from '#spreadsheet/bindings';++import { SidebarBalance } from './SidebarBalance';+import { SyncDot, useSyncDotLabel } from './SyncDot';+import type { SyncDotStatus } from './SyncDot';++type AccountRowProps = {+ account: AccountEntity;+ isClosed?: boolean;+ showSyncDot?: boolean;+};++export function AccountRow({+ account,+ isClosed,+ showSyncDot,+}: AccountRowProps) {+ const syncingAccountIds = useSelector(state => state.account.accountsSyncing);+ const updatedAccounts = useUpdatedAccounts();+ const isUpdated = !isClosed && updatedAccounts.includes(account.id);++ let status: SyncDotStatus = 'unlinked';+ if (!isClosed && account.bank) {+ if (isAccountFailedSync(account)) {+ status = 'error';+ } else if (syncingAccountIds.includes(account.id)) {+ status = 'pending';+ } else {+ status = 'synced';+ }+ }+ const statusLabel = useSyncDotLabel(status);++ return (+ <Link+ variant="internal"+ to={`/accounts/${account.id}`}+ style={{+ display: 'flex',+ flexDirection: 'row',+ alignItems: 'center',+ gap: spacing.sm,+ paddingBlock: spacing.xs,+ paddingInline: spacing.sm,+ borderRadius: radius.sm,+ fontSize: 13,+ textDecoration: isClosed ? 'line-through' : 'none',+ color: isClosed ? theme.sidebarTextMuted : theme.sidebarItemText,+ ':hover': { backgroundColor: theme.sidebarItemBackgroundHover },+ ...(isUpdated && {+ fontWeight: 700,+ color: theme.sidebarItemTextUpdated,+ }),+ }}+ activeStyle={{+ backgroundColor: theme.sidebarItemBackgroundSelected,+ color: theme.sidebarItemTextSelected,+ fontWeight: 'normal',+ }}+ >+ {showSyncDot ? <SyncDot status={status} /> : null}+ <Text style={{ flex: 1, ...styles.ellipsisText }}>{account.name}</Text>+ <Text style={styles.visuallyHidden}>{statusLabel}</Text>+ <SidebarBalance+ binding={bindings.accountBalance(account.id)}+ style={{ fontSize: 12, color: 'inherit' }}+ />+ </Link>+ );+}diff --git a/packages/desktop-client/src/components/sidebar/redesign/AccountsHeaderRow.tsx b/packages/desktop-client/src/components/sidebar/redesign/AccountsHeaderRow.tsxnew file mode 100644index 0000000000..e85f1332fc--- /dev/null+++ b/packages/desktop-client/src/components/sidebar/redesign/AccountsHeaderRow.tsx@@ -0,0 +1,86 @@+import { Trans, useTranslation } from 'react-i18next';++import {+ SvgAdd,+ SvgCheveronDownUp,+ SvgCheveronUpDown,+} from '@actual-app/components/icons/v1';+import { theme } from '@actual-app/components/theme';+import { spacing } from '@actual-app/components/tokens';+import { View } from '@actual-app/components/view';++import { Link } from '#components/common/Link';+import { replaceModal } from '#modals/modalsSlice';+import { useDispatch } from '#redux';+import * as bindings from '#spreadsheet/bindings';++import { SidebarBalance } from './SidebarBalance';+import { SidebarIconButton } from './SidebarIconButton';++type AccountsHeaderRowProps = {+ allOpen: boolean;+ onToggleAll: () => void;+};++export function AccountsHeaderRow({+ allOpen,+ onToggleAll,+}: AccountsHeaderRowProps) {+ const { t } = useTranslation();+ const dispatch = useDispatch();++ const onAddAccount = () => {+ dispatch(replaceModal({ modal: { name: 'add-account', options: {} } }));+ };++ return (+ <View+ style={{+ flexDirection: 'row',+ alignItems: 'center',+ gap: spacing.xs,+ paddingBlock: spacing.xs,+ paddingInline: spacing.sm,+ }}+ >+ <Link+ variant="internal"+ to="/accounts"+ isExactPathMatch+ style={{+ fontSize: 13,+ fontWeight: 700,+ textDecoration: 'none',+ color: theme.sidebarHeaderText,+ }}+ activeStyle={{ color: theme.sidebarItemTextSelected }}+ >+ <Trans>Accounts</Trans>+ </Link>+ <SidebarIconButton+ Icon={allOpen ? SvgCheveronDownUp : SvgCheveronUpDown}+ label={allOpen ? t('Collapse all groups') : t('Expand all groups')}+ onPress={onToggleAll}+ />+ <SidebarIconButton+ Icon={SvgAdd}+ label={t('Add account')}+ onPress={onAddAccount}+ />+ <View style={{ flex: 1 }} />+ <Link+ variant="internal"+ to="/accounts"+ isExactPathMatch+ style={{ textDecoration: 'none', color: theme.sidebarItemText }}+ activeStyle={{ color: theme.sidebarItemTextSelected }}+ >+ <SidebarBalance+ binding={bindings.allAccountBalance()}+ testId="sidebar-all-accounts-balance"+ style={{ fontSize: 12, fontWeight: 600 }}+ />+ </Link>+ </View>+ );+}diff --git a/packages/desktop-client/src/components/sidebar/redesign/AccountsSection.tsx b/packages/desktop-client/src/components/sidebar/redesign/AccountsSection.tsxnew file mode 100644index 0000000000..63ab329dce--- /dev/null+++ b/packages/desktop-client/src/components/sidebar/redesign/AccountsSection.tsx@@ -0,0 +1,75 @@+import { useTranslation } from 'react-i18next';++import { spacing } from '@actual-app/components/tokens';+import { View } from '@actual-app/components/view';++import * as bindings from '#spreadsheet/bindings';++import { AccountsHeaderRow } from './AccountsHeaderRow';+import { ClosedSection } from './ClosedSection';+import { SideGroup } from './SideGroup';+import { useSidebarAccountTree } from './useSidebarAccountTree';+import { bucketKey, useSidebarCollapseState } from './useSidebarCollapseState';++export function AccountsSection() {+ const { t } = useTranslation();+ const tree = useSidebarAccountTree();+ const collapse = useSidebarCollapseState({ tree, isSearching: false });++ const showSyncDot = [+ ...tree.onBudget.buckets.map(b => b.accounts).flat(),+ ...tree.offBudget.buckets.map(b => b.accounts).flat(),+ ].reduce((seen, account) => seen || account.bank !== null, false);++ return (+ <View+ style={{+ flexGrow: 1,+ minHeight: 0,+ overflowY: 'auto',+ paddingInline: spacing.sm,+ }}+ >+ <View style={{ flexShrink: 0 }}>+ <AccountsHeaderRow+ allOpen={collapse.allOpen}+ onToggleAll={collapse.toggleAll}+ />+ {tree.onBudget.buckets.length > 0 && (+ <SideGroup+ label={t('On budget')}+ side="on"+ showSyncDot={showSyncDot}+ sideData={tree.onBudget}+ totalBinding={bindings.onBudgetAccountBalance()}+ balanceTestId="sidebar-on-budget-balance"+ isOpen={collapse.isOpen('onbudget')}+ onToggle={() => collapse.toggle('onbudget')}+ isBucketOpen={bucket => collapse.isOpen(bucketKey('on', bucket))}+ onToggleBucket={bucket => collapse.toggle(bucketKey('on', bucket))}+ />+ )}+ {tree.offBudget.buckets.length > 0 && (+ <SideGroup+ label={t('Off budget')}+ side="off"+ showSyncDot={showSyncDot}+ sideData={tree.offBudget}+ totalBinding={bindings.offBudgetAccountBalance()}+ balanceTestId="sidebar-off-budget-balance"+ isOpen={collapse.isOpen('offbudget')}+ onToggle={() => collapse.toggle('offbudget')}+ isBucketOpen={bucket => collapse.isOpen(bucketKey('off', bucket))}+ onToggleBucket={bucket => collapse.toggle(bucketKey('off', bucket))}+ />+ )}+ <ClosedSection+ accounts={tree.closed}+ isOpen={collapse.isOpen('closed')}+ onToggle={() => collapse.toggle('closed')}+ />+ <View style={{ height: spacing.md }} />+ </View>+ </View>+ );+}diff --git a/packages/desktop-client/src/components/sidebar/redesign/ClosedSection.tsx b/packages/desktop-client/src/components/sidebar/redesign/ClosedSection.tsxnew file mode 100644index 0000000000..f3d880a9e6--- /dev/null+++ b/packages/desktop-client/src/components/sidebar/redesign/ClosedSection.tsx@@ -0,0 +1,69 @@+import { Trans } from 'react-i18next';++import { Button } from '@actual-app/components/button';+import { Text } from '@actual-app/components/text';+import { theme } from '@actual-app/components/theme';+import { radius, spacing } from '@actual-app/components/tokens';+import { View } from '@actual-app/components/view';+import type { AccountEntity } from '@actual-app/core/types/models';+import { css } from '@emotion/css';++import { AccountRow } from './AccountRow';+import { CollapseChevron } from './CollapseChevron';+import { CountPill } from './CountPill';+import { sectionLabelStyle } from './styles';++type ClosedSectionProps = {+ accounts: AccountEntity[];+ isOpen: boolean;+ onToggle: () => void;+};++export function ClosedSection({+ accounts,+ isOpen,+ onToggle,+}: ClosedSectionProps) {+ if (accounts.length === 0) {+ return null;+ }++ return (+ <View style={{ marginTop: spacing.xxs }}>+ <Button+ variant="bare"+ aria-expanded={isOpen}+ onPress={onToggle}+ className={css({+ '&[data-hovered], &[data-focus-visible]': {+ backgroundColor: theme.sidebarItemBackgroundHover,+ },+ })}+ style={{+ flexDirection: 'row',+ alignItems: 'center',+ justifyContent: 'flex-start',+ gap: spacing.xs,+ paddingBlock: spacing.xs,+ paddingLeft: spacing.xs,+ paddingRight: spacing.sm,+ borderRadius: radius.sm,+ width: '100%',+ }}+ >+ <CollapseChevron isOpen={isOpen} color={theme.sidebarTextMuted} />+ <Text style={{ ...sectionLabelStyle, color: theme.sidebarTextMuted }}>+ <Trans>Closed</Trans>+ </Text>+ {!isOpen && <CountPill count={accounts.length} />}+ </Button>+ {isOpen && (+ <View style={{ paddingLeft: spacing.xs }}>+ {accounts.map(account => (+ <AccountRow key={account.id} account={account} isClosed />+ ))}+ </View>+ )}+ </View>+ );+}diff --git a/packages/desktop-client/src/components/sidebar/redesign/CollapseChevron.tsx b/packages/desktop-client/src/components/sidebar/redesign/CollapseChevron.tsxnew file mode 100644index 0000000000..71d9c3588d--- /dev/null+++ b/packages/desktop-client/src/components/sidebar/redesign/CollapseChevron.tsx@@ -0,0 +1,23 @@+import {+ SvgCheveronDown,+ SvgCheveronRight,+} from '@actual-app/components/icons/v1';+import { theme } from '@actual-app/components/theme';++type CollapseChevronProps = {+ isOpen: boolean;+ size?: number;+ color?: string;+};++export function CollapseChevron({+ isOpen,+ size = 12,+ color = theme.sidebarTextSubdued,+}: CollapseChevronProps) {+ const Chevron = isOpen ? SvgCheveronDown : SvgCheveronRight;++ return (+ <Chevron width={size} height={size} style={{ flexShrink: 0, color }} />+ );+}diff --git a/packages/desktop-client/src/components/sidebar/redesign/CountPill.tsx b/packages/desktop-client/src/components/sidebar/redesign/CountPill.tsxnew file mode 100644index 0000000000..ca8387cc74--- /dev/null+++ b/packages/desktop-client/src/components/sidebar/redesign/CountPill.tsx@@ -0,0 +1,25 @@+import { Text } from '@actual-app/components/text';+import { theme } from '@actual-app/components/theme';+import { radius, spacing } from '@actual-app/components/tokens';++type CountPillProps = {+ count: number;+};++export function CountPill({ count }: CountPillProps) {+ return (+ <Text+ style={{+ fontSize: 10,+ fontWeight: 600,+ paddingInline: spacing.xs,+ borderRadius: radius.pill,+ backgroundColor: theme.sidebarControlBackground,+ color: theme.sidebarTextMuted,+ flexShrink: 0,+ }}+ >+ {count}+ </Text>+ );+}diff --git a/packages/desktop-client/src/components/sidebar/redesign/SideGroup.tsx b/packages/desktop-client/src/components/sidebar/redesign/SideGroup.tsxnew file mode 100644index 0000000000..f5326351ad--- /dev/null+++ b/packages/desktop-client/src/components/sidebar/redesign/SideGroup.tsx@@ -0,0 +1,125 @@+import { useTranslation } from 'react-i18next';++import { Button } from '@actual-app/components/button';+import { Text } from '@actual-app/components/text';+import { theme } from '@actual-app/components/theme';+import { radius, spacing } from '@actual-app/components/tokens';+import { View } from '@actual-app/components/view';+import { css } from '@emotion/css';++import { Link } from '#components/common/Link';+import type { Binding } from '#spreadsheet';++import { CollapseChevron } from './CollapseChevron';+import { CountPill } from './CountPill';+import { SidebarAccountGroup } from './SidebarAccountGroup';+import { SidebarBalance } from './SidebarBalance';+import { sectionLabelStyle } from './styles';+import { SyncErrorRollup } from './SyncErrorRollup';+import type { GroupBucket, SidebarAccountSide } from './useSidebarAccountTree';++type SideGroupProps = {+ label: string;+ side: 'on' | 'off';+ showSyncDot: boolean;+ sideData: SidebarAccountSide;+ totalBinding: Binding<+ 'account',+ 'onbudget-accounts-balance' | 'offbudget-accounts-balance'+ >;+ balanceTestId: string;+ isOpen: boolean;+ onToggle: () => void;+ isBucketOpen: (bucket: GroupBucket) => boolean;+ onToggleBucket: (bucket: GroupBucket) => void;+};++export function SideGroup({+ label,+ side,+ showSyncDot,+ sideData,+ totalBinding,+ balanceTestId,+ isOpen,+ onToggle,+ isBucketOpen,+ onToggleBucket,+}: SideGroupProps) {+ const { t } = useTranslation();++ return (+ <View style={{ marginTop: spacing.xxs }}>+ <View+ style={{+ flexDirection: 'row',+ alignItems: 'center',+ gap: spacing.xs,+ paddingBlock: spacing.xs,+ paddingLeft: spacing.xs,+ paddingRight: spacing.sm,+ }}+ >+ <Button+ variant="bare"+ aria-expanded={isOpen}+ aria-label={+ isOpen+ ? t('Collapse {{section}}', { section: label })+ : t('Expand {{section}}', { section: label })+ }+ onPress={onToggle}+ className={css({+ '&[data-hovered], &[data-focus-visible]': {+ backgroundColor: theme.sidebarItemBackgroundHover,+ },+ })}+ style={{+ padding: spacing.xxs,+ flexShrink: 0,+ borderRadius: radius.sm,+ }}+ >+ <CollapseChevron isOpen={isOpen} />+ </Button>+ <Link+ variant="internal"+ to={side === 'on' ? '/accounts/onbudget' : '/accounts/offbudget'}+ isExactPathMatch+ style={{+ display: 'flex',+ flexDirection: 'row',+ alignItems: 'center',+ gap: spacing.xs,+ flex: 1,+ minWidth: 0,+ textDecoration: 'none',+ color: theme.sidebarItemText,+ }}+ activeStyle={{ color: theme.sidebarItemTextSelected }}+ >+ <Text style={sectionLabelStyle}>{label}</Text>+ {!isOpen && <CountPill count={sideData.accountCount} />}+ <SyncErrorRollup count={sideData.failedCount} />+ <View style={{ flex: 1 }} />+ <SidebarBalance+ binding={totalBinding}+ testId={balanceTestId}+ style={{ fontSize: 12, fontWeight: 600, color: 'inherit' }}+ />+ </Link>+ </View>+ {isOpen &&+ sideData.buckets.map(bucket => (+ <SidebarAccountGroup+ key={bucket.group?.id ?? 'ungrouped'}+ bucket={bucket}+ side={side}+ showSyncDot={showSyncDot}+ isOpen={isBucketOpen(bucket)}+ onToggle={() => onToggleBucket(bucket)}+ />+ ))}+ </View>+ );+}diff --git a/packages/desktop-client/src/components/sidebar/redesign/SidebarAccountGroup.tsx b/packages/desktop-client/src/components/sidebar/redesign/SidebarAccountGroup.tsxnew file mode 100644index 0000000000..05853b4a60--- /dev/null+++ b/packages/desktop-client/src/components/sidebar/redesign/SidebarAccountGroup.tsx@@ -0,0 +1,62 @@+import { spacing } from '@actual-app/components/tokens';+import { View } from '@actual-app/components/view';++import { AccountGroupHeader } from './AccountGroupHeader';+import { AccountRow } from './AccountRow';+import type { GroupBucket } from './useSidebarAccountTree';++type SidebarAccountGroupProps = {+ bucket: GroupBucket;+ side: 'on' | 'off';+ showSyncDot: boolean;+ isOpen: boolean;+ onToggle: () => void;+};++export function SidebarAccountGroup({+ bucket,+ side,+ showSyncDot,+ isOpen,+ onToggle,+}: SidebarAccountGroupProps) {+ const { group, accounts, failedCount } = bucket;++ if (group == null) {+ return (+ <View style={{ paddingLeft: spacing.xs }}>+ {accounts.map(account => (+ <AccountRow+ key={account.id}+ account={account}+ showSyncDot={showSyncDot}+ />+ ))}+ </View>+ );+ }++ return (+ <View style={{ paddingLeft: spacing.xs, marginBottom: spacing.xxs }}>+ <AccountGroupHeader+ group={group}+ side={side}+ accountCount={accounts.length}+ failedCount={failedCount}+ isOpen={isOpen}+ onToggle={onToggle}+ />+ {isOpen && (+ <View style={{ paddingLeft: spacing.sm }}>+ {accounts.map(account => (+ <AccountRow+ key={account.id}+ account={account}+ showSyncDot={showSyncDot}+ />+ ))}+ </View>+ )}+ </View>+ );+}diff --git a/packages/desktop-client/src/components/sidebar/redesign/SidebarBalance.tsx b/packages/desktop-client/src/components/sidebar/redesign/SidebarBalance.tsxnew file mode 100644index 0000000000..3cdbe28ebf--- /dev/null+++ b/packages/desktop-client/src/components/sidebar/redesign/SidebarBalance.tsx@@ -0,0 +1,28 @@+import type { CSSProperties } from '@actual-app/components/styles';++import { CellValue, CellValueText } from '#components/spreadsheet/CellValue';+import type { Binding, SheetFields } from '#spreadsheet';++type SidebarBalanceProps<FieldName extends SheetFields<'account'>> = {+ binding: Binding<'account', FieldName>;+ style?: CSSProperties;+ testId?: string;+};++export function SidebarBalance<FieldName extends SheetFields<'account'>>({+ binding,+ style,+ testId,+}: SidebarBalanceProps<FieldName>) {+ return (+ <CellValue<'account', FieldName> binding={binding} type="financial">+ {props => (+ <CellValueText<'account', FieldName>+ {...props}+ data-testid={testId ?? props.name}+ style={{ textAlign: 'right', ...style }}+ />+ )}+ </CellValue>+ );+}diff --git a/packages/desktop-client/src/components/sidebar/redesign/SidebarIconButton.tsx b/packages/desktop-client/src/components/sidebar/redesign/SidebarIconButton.tsxnew file mode 100644index 0000000000..b7297cc0ea--- /dev/null+++ b/packages/desktop-client/src/components/sidebar/redesign/SidebarIconButton.tsx@@ -0,0 +1,63 @@+import type { ComponentProps, ComponentType, SVGProps } from 'react';++import { Button } from '@actual-app/components/button';+import { styles } from '@actual-app/components/styles';+import { theme } from '@actual-app/components/theme';+import { radius } from '@actual-app/components/tokens';+import { Tooltip } from '@actual-app/components/tooltip';+import { css } from '@emotion/css';++type SidebarIconButtonProps = {+ Icon:+ | ComponentType<SVGProps<SVGElement>>+ | ComponentType<SVGProps<SVGSVGElement>>;+ label: string;+ isToggledOn?: boolean;+ isDisabled?: boolean;+ onPress: ComponentProps<typeof Button>['onPress'];+};++export function SidebarIconButton({+ Icon,+ label,+ isToggledOn,+ isDisabled,+ onPress,+}: SidebarIconButtonProps) {+ return (+ <Tooltip+ content={label}+ placement="bottom"+ style={styles.tooltip}+ triggerProps={{ delay: 500 }}+ >+ <Button+ variant="bare"+ aria-label={label}+ aria-pressed={isToggledOn}+ isDisabled={isDisabled}+ onPress={onPress}+ className={css({+ color: isToggledOn+ ? theme.sidebarItemTextSelected+ : theme.sidebarTextSubdued,+ backgroundColor: isToggledOn+ ? theme.sidebarControlBackground+ : 'transparent',+ '&[data-hovered], &[data-focus-visible]': {+ backgroundColor: theme.sidebarControlBackground,+ color: theme.sidebarItemTextSelected,+ },+ })}+ style={{+ width: 18,+ height: 18,+ padding: 0,+ borderRadius: radius.sm,+ }}+ >+ <Icon width={12} height={12} style={{ flexShrink: 0 }} />+ </Button>+ </Tooltip>+ );+}diff --git a/packages/desktop-client/src/components/sidebar/redesign/SidebarRedesign.tsx b/packages/desktop-client/src/components/sidebar/redesign/SidebarRedesign.tsxindex be10f37e38..f7c4b02913 100644--- a/packages/desktop-client/src/components/sidebar/redesign/SidebarRedesign.tsx+++ b/packages/desktop-client/src/components/sidebar/redesign/SidebarRedesign.tsx@@ -1,19 +1,15 @@import { useTranslation } from 'react-i18next';-import { SvgAdd } from '@actual-app/components/icons/v1';import { theme } from '@actual-app/components/theme';import { spacing } from '@actual-app/components/tokens';import { View } from '@actual-app/components/view';-import { Accounts } from '#components/sidebar/Accounts';-import { SecondaryButtons } from '#components/sidebar/SecondaryButtons';import { useSidebar } from '#components/sidebar/SidebarProvider';import { SidebarShell } from '#components/sidebar/SidebarShell';import { ToggleButton } from '#components/sidebar/ToggleButton';import { useGlobalPref } from '#hooks/useGlobalPref';-import { replaceModal } from '#modals/modalsSlice';-import { useDispatch } from '#redux';+import { AccountsSection } from './AccountsSection';import { PrimaryNav } from './PrimaryNav';import { SidebarFooter } from './SidebarFooter';import { SidebarHeader } from './SidebarHeader';@@ -22,7 +18,6 @@ const DEFAULT_SIDEBAR_WIDTH = 270;export function SidebarRedesign() {const { t } = useTranslation();- const dispatch = useDispatch();const sidebar = useSidebar();const [isFloating = false, setFloatingSidebarPref] =useGlobalPref('floatingSidebar');@@ -31,10 +26,6 @@ export function SidebarRedesign() {setFloatingSidebarPref(!isFloating);};- const onAddAccount = () => {- dispatch(replaceModal({ modal: { name: 'add-account', options: {} } }));- };-return (<SidebarShelldefaultWidth={DEFAULT_SIDEBAR_WIDTH}@@ -62,20 +53,7 @@ export function SidebarRedesign() {}}/>- <View style={{ flexGrow: 1, overflowY: 'auto' }}>- <Accounts />-- <SecondaryButtons- buttons={[- {- title: t('Add account'),- Icon: SvgAdd,- onClick: onAddAccount,- dataTestId: 'sidebar-add-account',- },- ]}- />- </View>+ <AccountsSection /><SidebarFooter /></View>diff --git a/packages/desktop-client/src/components/sidebar/redesign/SyncDot.tsx b/packages/desktop-client/src/components/sidebar/redesign/SyncDot.tsxnew file mode 100644index 0000000000..f9b229ab28--- /dev/null+++ b/packages/desktop-client/src/components/sidebar/redesign/SyncDot.tsx@@ -0,0 +1,53 @@+import { useTranslation } from 'react-i18next';++import { theme } from '@actual-app/components/theme';+import { radius } from '@actual-app/components/tokens';+import { View } from '@actual-app/components/view';++export type SyncDotStatus = 'synced' | 'error' | 'pending' | 'unlinked';++export function useSyncDotLabel(status: SyncDotStatus): string {+ const { t } = useTranslation();++ const labels: Record<SyncDotStatus, string> = {+ synced: t('Synced'),+ error: t('Sync error'),+ pending: t('Syncing'),+ unlinked: t('Not linked'),+ };++ return labels[status];+}++type SyncDotProps = {+ status: SyncDotStatus;+};++export function SyncDot({ status }: SyncDotProps) {+ const label = useSyncDotLabel(status);++ return (+ <View+ aria-hidden+ title={label}+ style={{+ width: 7,+ height: 7,+ borderRadius: radius.pill,+ flexShrink: 0,+ ...(status === 'synced' && {+ backgroundColor: theme.sidebarItemBackgroundPositive,+ }),+ ...(status === 'error' && {+ backgroundColor: theme.sidebarItemBackgroundFailed,+ }),+ ...(status === 'pending' && {+ backgroundColor: theme.sidebarItemBackgroundPending,+ }),+ ...(status === 'unlinked' && {+ border: `1.25px solid ${theme.sidebarTextMuted}`,+ }),+ }}+ />+ );+}diff --git a/packages/desktop-client/src/components/sidebar/redesign/SyncErrorRollup.tsx b/packages/desktop-client/src/components/sidebar/redesign/SyncErrorRollup.tsxnew file mode 100644index 0000000000..909a59fe60--- /dev/null+++ b/packages/desktop-client/src/components/sidebar/redesign/SyncErrorRollup.tsx@@ -0,0 +1,55 @@+import { useTranslation } from 'react-i18next';++import { Text } from '@actual-app/components/text';+import { theme } from '@actual-app/components/theme';+import { radius, spacing } from '@actual-app/components/tokens';+import { View } from '@actual-app/components/view';++type SyncErrorRollupProps = {+ count: number;+};++export function SyncErrorRollup({ count }: SyncErrorRollupProps) {+ const { t } = useTranslation();++ if (count === 0) {+ return null;+ }++ return (+ <View+ title={+ count === 1+ ? t('1 account needs attention')+ : t('{{count}} accounts need attention', { count })+ }+ style={{+ flexDirection: 'row',+ alignItems: 'center',+ gap: spacing.xs,+ paddingInline: spacing.xs,+ borderRadius: radius.pill,+ backgroundColor: theme.sidebarBackgroundFailedSubtle,+ flexShrink: 0,+ }}+ >+ <View+ style={{+ width: 5,+ height: 5,+ borderRadius: radius.pill,+ backgroundColor: theme.sidebarItemBackgroundFailed,+ }}+ />+ <Text+ style={{+ fontSize: 10,+ fontWeight: 700,+ color: theme.sidebarTextFailed,+ }}+ >+ {count}+ </Text>+ </View>+ );+}diff --git a/packages/desktop-client/src/components/sidebar/redesign/styles.ts b/packages/desktop-client/src/components/sidebar/redesign/styles.tsnew file mode 100644index 0000000000..b9d6520064--- /dev/null+++ b/packages/desktop-client/src/components/sidebar/redesign/styles.ts@@ -0,0 +1,13 @@+import type { CSSProperties } from '@actual-app/components/styles';+import { theme } from '@actual-app/components/theme';++export const sectionLabelStyle = {+ fontSize: 13,+ fontWeight: 600,+} satisfies CSSProperties;++export const groupLabelStyle = {+ fontSize: 12,+ fontWeight: 600,+ color: theme.sidebarTextSubdued,+} satisfies CSSProperties;diff --git a/packages/desktop-client/src/components/sidebar/redesign/useSidebarAccountTree.test.ts b/packages/desktop-client/src/components/sidebar/redesign/useSidebarAccountTree.test.tsnew file mode 100644index 0000000000..64d4a30651--- /dev/null+++ b/packages/desktop-client/src/components/sidebar/redesign/useSidebarAccountTree.test.ts@@ -0,0 +1,84 @@+import { generateAccount } from '@actual-app/core/mocks';+import type {+ AccountEntity,+ AccountGroupEntity,+} from '@actual-app/core/types/models';+import { describe, expect, it } from 'vitest';++import { buildAccountSide, getEffectiveGroupId } from './useSidebarAccountTree';++function makeAccount(+ name: string,+ overrides: Partial<AccountEntity> = {},+): AccountEntity {+ return { ...generateAccount(name), ...overrides };+}++function makeGroup(id: string, name: string): AccountGroupEntity {+ return { id, name, sort_order: 0 };+}++describe('getEffectiveGroupId', () => {+ it('returns the group id only when the group is live', () => {+ const liveGroupIds = new Set(['g1']);+ expect(+ getEffectiveGroupId(+ makeAccount('A', { account_group_id: 'g1' }),+ liveGroupIds,+ ),+ ).toBe('g1');+ expect(+ getEffectiveGroupId(+ makeAccount('B', { account_group_id: 'deleted' }),+ liveGroupIds,+ ),+ ).toBeNull();+ expect(+ getEffectiveGroupId(+ makeAccount('C', { account_group_id: null }),+ liveGroupIds,+ ),+ ).toBeNull();+ });+});++describe('buildAccountSide', () => {+ it('buckets ungrouped and dangling-ref accounts first, then groups in order', () => {+ const groups = [makeGroup('g1', 'Savings'), makeGroup('g2', 'Cards')];+ const accounts = [+ makeAccount('Loose'),+ makeAccount('Dangling', { account_group_id: 'deleted' }),+ makeAccount('Saver', { account_group_id: 'g1' }),+ makeAccount('Amex', { account_group_id: 'g2' }),+ ];++ const side = buildAccountSide(accounts, groups);++ expect(side.accountCount).toBe(4);+ expect(side.buckets.map(bucket => bucket.group?.id ?? null)).toEqual([+ null,+ 'g1',+ 'g2',+ ]);+ expect(side.buckets[0].accounts.map(account => account.name)).toEqual([+ 'Loose',+ 'Dangling',+ ]);+ });++ it('omits empty buckets and counts failed syncs per bucket', () => {+ const groups = [makeGroup('g1', 'Savings'), makeGroup('g2', 'Empty')];+ const failed = makeAccount('Broken', {+ account_group_id: 'g1',+ bank_sync_status: 'reauth-required',+ });+ const side = buildAccountSide(+ [makeAccount('Fine', { account_group_id: 'g1' }), failed],+ groups,+ );++ expect(side.buckets.map(bucket => bucket.group?.id)).toEqual(['g1']);+ expect(side.buckets[0].failedCount).toBe(1);+ expect(side.failedCount).toBe(1);+ });+});diff --git a/packages/desktop-client/src/components/sidebar/redesign/useSidebarAccountTree.ts b/packages/desktop-client/src/components/sidebar/redesign/useSidebarAccountTree.tsnew file mode 100644index 0000000000..59e3f6c934--- /dev/null+++ b/packages/desktop-client/src/components/sidebar/redesign/useSidebarAccountTree.ts@@ -0,0 +1,89 @@+import type {+ AccountEntity,+ AccountGroupEntity,+} from '@actual-app/core/types/models';++import { isAccountFailedSync } from '#accounts/syncStatus';+import { useAccountGroups } from '#hooks/useAccountGroups';+import { useClosedAccounts } from '#hooks/useClosedAccounts';+import { useOffBudgetAccounts } from '#hooks/useOffBudgetAccounts';+import { useOnBudgetAccounts } from '#hooks/useOnBudgetAccounts';++export type GroupBucket = {+ group: AccountGroupEntity | null;+ accounts: AccountEntity[];+ failedCount: number;+};++export type SidebarAccountSide = {+ buckets: GroupBucket[];+ accountCount: number;+ failedCount: number;+};++export type SidebarAccountTree = {+ onBudget: SidebarAccountSide;+ offBudget: SidebarAccountSide;+ closed: AccountEntity[];+};++export function getEffectiveGroupId(+ account: AccountEntity,+ liveGroupIds: ReadonlySet<AccountGroupEntity['id']>,+): AccountGroupEntity['id'] | null {+ return account.account_group_id != null &&+ liveGroupIds.has(account.account_group_id)+ ? account.account_group_id+ : null;+}++export function buildAccountSide(+ accounts: AccountEntity[],+ groups: AccountGroupEntity[],+): SidebarAccountSide {+ const liveGroupIds = new Set(groups.map(group => group.id));+ const buckets: GroupBucket[] = [];++ const ungrouped = accounts.filter(+ account => getEffectiveGroupId(account, liveGroupIds) == null,+ );+ if (ungrouped.length > 0) {+ buckets.push({+ group: null,+ accounts: ungrouped,+ failedCount: ungrouped.filter(isAccountFailedSync).length,+ });+ }++ for (const group of groups) {+ const members = accounts.filter(+ account => account.account_group_id === group.id,+ );+ if (members.length > 0) {+ buckets.push({+ group,+ accounts: members,+ failedCount: members.filter(isAccountFailedSync).length,+ });+ }+ }++ return {+ buckets,+ accountCount: accounts.length,+ failedCount: accounts.filter(isAccountFailedSync).length,+ };+}++export function useSidebarAccountTree(): SidebarAccountTree {+ const { data: groups = [] } = useAccountGroups();+ const { data: onBudgetAccounts = [] } = useOnBudgetAccounts();+ const { data: offBudgetAccounts = [] } = useOffBudgetAccounts();+ const { data: closedAccounts = [] } = useClosedAccounts();++ return {+ onBudget: buildAccountSide(onBudgetAccounts, groups),+ offBudget: buildAccountSide(offBudgetAccounts, groups),+ closed: closedAccounts,+ };+}diff --git a/packages/desktop-client/src/components/sidebar/redesign/useSidebarCollapseState.ts b/packages/desktop-client/src/components/sidebar/redesign/useSidebarCollapseState.tsnew file mode 100644index 0000000000..284a31751b--- /dev/null+++ b/packages/desktop-client/src/components/sidebar/redesign/useSidebarCollapseState.ts@@ -0,0 +1,61 @@+import { useLocalPref } from '#hooks/useLocalPref';++import type { GroupBucket, SidebarAccountTree } from './useSidebarAccountTree';++type Side = 'on' | 'off';++export type SidebarSectionKey =+ | 'onbudget'+ | 'offbudget'+ | 'closed'+ | `group-${string}-${Side}`+ | `ungrouped-${Side}`;++export function bucketKey(side: Side, bucket: GroupBucket): SidebarSectionKey {+ return bucket.group+ ? `group-${bucket.group.id}-${side}`+ : `ungrouped-${side}`;+}++type UseSidebarCollapseStateArgs = {+ tree: SidebarAccountTree;+ isSearching: boolean;+};++export function useSidebarCollapseState({+ tree,+ isSearching,+}: UseSidebarCollapseStateArgs): {+ isOpen: (key: SidebarSectionKey) => boolean;+ toggle: (key: SidebarSectionKey) => void;+ allOpen: boolean;+ toggleAll: () => void;+} {+ const [openState = {}, setOpenState] = useLocalPref(+ 'sidebar.accountsOpenState',+ );++ const isOpen = (key: SidebarSectionKey) =>+ isSearching ? true : (openState[key] ?? key !== 'closed');+ const toggle = (key: SidebarSectionKey) =>+ setOpenState({ ...openState, [key]: !isOpen(key) });++ const allKeys: SidebarSectionKey[] = [+ 'onbudget',+ 'offbudget',+ ...tree.onBudget.buckets+ .filter(bucket => bucket.group != null)+ .map(bucket => bucketKey('on', bucket)),+ ...tree.offBudget.buckets+ .filter(bucket => bucket.group != null)+ .map(bucket => bucketKey('off', bucket)),+ ];+ const allOpen = allKeys.every(isOpen);+ const toggleAll = () =>+ setOpenState({+ ...openState,+ ...Object.fromEntries(allKeys.map(key => [key, !allOpen])),+ });++ return { isOpen, toggle, allOpen, toggleAll };+}diff --git a/packages/desktop-client/src/spreadsheet/bindings.ts b/packages/desktop-client/src/spreadsheet/bindings.tsindex 261326224d..f7b34664bd 100644--- a/packages/desktop-client/src/spreadsheet/bindings.ts+++ b/packages/desktop-client/src/spreadsheet/bindings.ts@@ -1,6 +1,7 @@import { q } from '@actual-app/core/shared/query';import type {AccountEntity,+ AccountGroupEntity,CategoryEntity,} from '@actual-app/core/types/models';@@ -85,6 +86,23 @@ export function closedAccountBalance() {} satisfies Binding<'account', 'closed-accounts-balance'>;}+export function accountGroupBalance(+ groupId: AccountGroupEntity['id'],+ offbudget: boolean,+) {+ return {+ name: `account-group-balance-${groupId}-${offbudget ? 'off' : 'on'}`,+ query: q('transactions')+ .filter({+ 'account.account_group_id': groupId,+ 'account.offbudget': offbudget,+ 'account.closed': false,+ })+ .options({ splits: 'none' })+ .calculate({ $sum: '$amount' }),+ } satisfies Binding<'account', `account-group-balance-${string}`>;+}+export function categoryBalance(categoryId: CategoryEntity['id'],month: string,diff --git a/packages/desktop-client/src/spreadsheet/index.ts b/packages/desktop-client/src/spreadsheet/index.tsindex 1c7059390d..a74f0760e1 100644--- a/packages/desktop-client/src/spreadsheet/index.ts+++ b/packages/desktop-client/src/spreadsheet/index.ts@@ -13,6 +13,7 @@ export type Spreadsheets = {'onbudget-accounts-balance': number;'offbudget-accounts-balance': number;'closed-accounts-balance': number;+ [key: `account-group-balance-${string}`]: number;balanceCleared: number;balanceUncleared: number;lastReconciled: string | null;diff --git a/packages/loot-core/src/types/prefs.ts b/packages/loot-core/src/types/prefs.tsindex b67ae84c70..b0e57a605e 100644--- a/packages/loot-core/src/types/prefs.ts+++ b/packages/loot-core/src/types/prefs.ts@@ -93,6 +93,7 @@ export type MetadataPrefs = Partial<{*/export type LocalPrefs = Partial<{'ui.showClosedAccounts': boolean;+ 'sidebar.accountsOpenState': Record<string, boolean>;'expand-splits': boolean;'budget.collapsed': string[];'budget.summaryCollapsed': boolean;diff --git a/upcoming-release-notes/add-new-sidebar-account-list.md b/upcoming-release-notes/add-new-sidebar-account-list.mdnew file mode 100644index 0000000000..b8d57af4f8--- /dev/null+++ b/upcoming-release-notes/add-new-sidebar-account-list.md@@ -0,0 +1,6 @@+---+category: Features+authors: [matt-fidd]+---++Redesign the account list in the experimental new sidebar with collapsible account groups, balances, net worth, and sync status indicators