Skip to content

A local-first personal finance app

sidebar pt. 2: UI to manage groups and assign accounts (#8832)

Matt Fiddaman6c73bbb1d460
diff --git a/packages/desktop-client/package.json b/packages/desktop-client/package.json
index e98fc929eb..28c83440d6 100644
--- a/packages/desktop-client/package.json
+++ b/packages/desktop-client/package.json
@@ -15,6 +15,7 @@
"electron-renderer": "./src/browser-preload.electron.ts",
"default": "./src/browser-preload.js"
},
+ "#account-groups": "./src/account-groups/index.ts",
"#accounts": "./src/accounts/index.ts",
"#budget": "./src/budget/index.ts",
"#payees": "./src/payees/index.ts",
diff --git a/packages/desktop-client/src/account-groups/index.ts b/packages/desktop-client/src/account-groups/index.ts
new file mode 100644
index 0000000000..d0720956a0
--- /dev/null
+++ b/packages/desktop-client/src/account-groups/index.ts
@@ -0,0 +1,2 @@
+export * from './queries';
+export * from './mutations';
diff --git a/packages/desktop-client/src/account-groups/mutations.ts b/packages/desktop-client/src/account-groups/mutations.ts
new file mode 100644
index 0000000000..2efe89a698
--- /dev/null
+++ b/packages/desktop-client/src/account-groups/mutations.ts
@@ -0,0 +1,142 @@
+import { useTranslation } from 'react-i18next';
+
+import { send } from '@actual-app/core/platform/client/connection';
+import type { AccountGroupEntity } from '@actual-app/core/types/models';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
+import type { QueryClient, QueryKey } from '@tanstack/react-query';
+import { v4 as uuidv4 } from 'uuid';
+
+import { accountQueries } from '#accounts';
+import { addNotification } from '#notifications/notificationsSlice';
+import { useDispatch } from '#redux';
+import type { AppDispatch } from '#redux/store';
+
+import { accountGroupQueries } from './queries';
+
+function invalidateQueries(queryClient: QueryClient, queryKey?: QueryKey) {
+ void queryClient.invalidateQueries({
+ queryKey: queryKey ?? accountGroupQueries.lists(),
+ });
+}
+
+function dispatchErrorNotification(
+ dispatch: AppDispatch,
+ message: string,
+ error?: Error,
+) {
+ dispatch(
+ addNotification({
+ notification: {
+ id: uuidv4(),
+ type: 'error',
+ message,
+ pre: error ? error.message : undefined,
+ },
+ }),
+ );
+}
+
+type CreateAccountGroupPayload = {
+ name: AccountGroupEntity['name'];
+};
+
+export function useCreateAccountGroupMutation() {
+ const queryClient = useQueryClient();
+ const dispatch = useDispatch();
+ const { t } = useTranslation();
+
+ return useMutation({
+ mutationFn: async ({ name }: CreateAccountGroupPayload) => {
+ return await send('account-group-create', { name });
+ },
+ onSuccess: () => invalidateQueries(queryClient),
+ onError: error => {
+ console.error('Error creating account group:', error);
+ dispatchErrorNotification(
+ dispatch,
+ t('There was an error creating the account group. Please try again.'),
+ error,
+ );
+ },
+ });
+}
+
+type UpdateAccountGroupPayload = {
+ id: AccountGroupEntity['id'];
+ name: AccountGroupEntity['name'];
+};
+
+export function useUpdateAccountGroupMutation() {
+ const queryClient = useQueryClient();
+ const dispatch = useDispatch();
+ const { t } = useTranslation();
+
+ return useMutation({
+ mutationFn: async ({ id, name }: UpdateAccountGroupPayload) => {
+ return await send('account-group-update', { id, name });
+ },
+ onSuccess: () => invalidateQueries(queryClient),
+ onError: error => {
+ console.error('Error updating account group:', error);
+ dispatchErrorNotification(
+ dispatch,
+ t('There was an error updating the account group. Please try again.'),
+ error,
+ );
+ },
+ });
+}
+
+type DeleteAccountGroupPayload = {
+ id: AccountGroupEntity['id'];
+};
+
+export function useDeleteAccountGroupMutation() {
+ const queryClient = useQueryClient();
+ const dispatch = useDispatch();
+ const { t } = useTranslation();
+
+ return useMutation({
+ mutationFn: async ({ id }: DeleteAccountGroupPayload) => {
+ return await send('account-group-delete', { id });
+ },
+ onSuccess: () => {
+ invalidateQueries(queryClient);
+ invalidateQueries(queryClient, accountQueries.lists());
+ },
+ onError: error => {
+ console.error('Error deleting account group:', error);
+ dispatchErrorNotification(
+ dispatch,
+ t('There was an error deleting the account group. Please try again.'),
+ error,
+ );
+ },
+ });
+}
+
+type MoveAccountGroupPayload = {
+ id: AccountGroupEntity['id'];
+ targetId: AccountGroupEntity['id'] | null;
+};
+
+export function useMoveAccountGroupMutation() {
+ const queryClient = useQueryClient();
+ const dispatch = useDispatch();
+ const { t } = useTranslation();
+
+ return useMutation({
+ mutationFn: async ({ id, targetId }: MoveAccountGroupPayload) => {
+ return await send('account-group-move', { id, targetId });
+ },
+ onSuccess: () => invalidateQueries(queryClient),
+ onError: error => {
+ console.error('Error moving account group:', error);
+ dispatchErrorNotification(
+ dispatch,
+ t('There was an error moving the account group. Please try again.'),
+ error,
+ );
+ },
+ });
+}
diff --git a/packages/desktop-client/src/account-groups/queries.ts b/packages/desktop-client/src/account-groups/queries.ts
new file mode 100644
index 0000000000..60a0733371
--- /dev/null
+++ b/packages/desktop-client/src/account-groups/queries.ts
@@ -0,0 +1,15 @@
+import { send } from '@actual-app/core/platform/client/connection';
+import type { AccountGroupEntity } from '@actual-app/core/types/models';
+import { queryOptions } from '@tanstack/react-query';
+
+export const accountGroupQueries = {
+ all: () => ['account-groups'],
+ lists: () => [...accountGroupQueries.all(), 'lists'],
+ list: () =>
+ queryOptions<AccountGroupEntity[]>({
+ queryKey: [...accountGroupQueries.lists()],
+ queryFn: () => send('account-groups-get'),
+ placeholderData: [],
+ staleTime: Infinity,
+ }),
+};
diff --git a/packages/desktop-client/src/accounts/mutations.ts b/packages/desktop-client/src/accounts/mutations.ts
index 5448a3dac9..86f4a5ed3f 100644
--- a/packages/desktop-client/src/accounts/mutations.ts
+++ b/packages/desktop-client/src/accounts/mutations.ts
@@ -151,7 +151,7 @@ export function useReopenAccountMutation() {
}
type UpdateAccountPayload = {
- account: AccountEntity;
+ account: Pick<AccountEntity, 'id'> & Partial<AccountEntity>;
};
export function useUpdateAccountMutation() {
diff --git a/packages/desktop-client/src/components/Modals.tsx b/packages/desktop-client/src/components/Modals.tsx
index 540d2bad15..6dd517a164 100644
--- a/packages/desktop-client/src/components/Modals.tsx
+++ b/packages/desktop-client/src/components/Modals.tsx
@@ -13,6 +13,7 @@ import { useDispatch } from '#redux';
import { EditSyncAccount } from './banksync/EditSyncAccount';
import { AccountAutocompleteModal } from './modals/AccountAutocompleteModal';
+import { AccountGroupsModal } from './modals/AccountGroupsModal';
import { AccountMenuModal } from './modals/AccountMenuModal';
import { AccountReconcileModal } from './modals/AccountReconcileModal';
import { AkahuInitialiseModal } from './modals/AkahuInitialiseModal';
@@ -137,6 +138,9 @@ export function Modals() {
case 'add-local-account':
return <CreateLocalAccountModal key={key} />;
+ case 'account-groups':
+ return <AccountGroupsModal key={key} {...modal.options} />;
+
case 'close-account':
return <CloseAccountModal key={key} {...modal.options} />;
diff --git a/packages/desktop-client/src/components/accounts/Account.tsx b/packages/desktop-client/src/components/accounts/Account.tsx
index ce43733761..8cc8dcb875 100644
--- a/packages/desktop-client/src/components/accounts/Account.tsx
+++ b/packages/desktop-client/src/components/accounts/Account.tsx
@@ -819,7 +819,8 @@ class AccountInternal extends PureComponent<
| 'remove-sorting'
| 'toggle-reconciled'
| 'toggle-net-worth-chart'
- | 'manage-columns',
+ | 'manage-columns'
+ | 'account-group',
) => {
const accountId = this.props.accountId!;
const account = this.props.accounts.find(
@@ -858,6 +859,18 @@ class AccountInternal extends PureComponent<
case 'close':
void this.props.dispatch(openAccountCloseModal({ accountId }));
break;
+ case 'account-group':
+ this.props.dispatch(
+ pushModal({
+ modal: {
+ name: 'account-groups',
+ options: {
+ accountId,
+ },
+ },
+ }),
+ );
+ break;
case 'reopen':
this.props.onReopenAccount(accountId);
break;
diff --git a/packages/desktop-client/src/components/accounts/Header.tsx b/packages/desktop-client/src/components/accounts/Header.tsx
index 228b1ab7c6..3b9468d6a7 100644
--- a/packages/desktop-client/src/components/accounts/Header.tsx
+++ b/packages/desktop-client/src/components/accounts/Header.tsx
@@ -44,6 +44,7 @@ import type { SavedFilter } from '#components/filters/SavedFilterMenuButton';
import { NotesButton } from '#components/NotesButton';
import { SelectedTransactionsButton } from '#components/transactions/SelectedTransactionsButton';
import { useDateFormat } from '#hooks/useDateFormat';
+import { useFeatureFlag } from '#hooks/useFeatureFlag';
import { useLocale } from '#hooks/useLocale';
import { useLocalPref } from '#hooks/useLocalPref';
import { useSplitsExpanded } from '#hooks/useSplitsExpanded';
@@ -732,7 +733,8 @@ type AccountMenuProps = {
| 'remove-sorting'
| 'toggle-reconciled'
| 'toggle-net-worth-chart'
- | 'manage-columns',
+ | 'manage-columns'
+ | 'account-group',
) => void;
};
@@ -746,6 +748,7 @@ function AccountMenu({
}: AccountMenuProps) {
const { t } = useTranslation();
const syncServerStatus = useSyncServerStatus();
+ const newSidebarUIEnabled = useFeatureFlag('newSidebarUI');
return (
<Menu
@@ -772,6 +775,14 @@ function AccountMenu({
name: 'manage-columns',
text: t('Manage table columns'),
},
+ ...(newSidebarUIEnabled
+ ? [
+ {
+ name: 'account-group',
+ text: t('Set account group'),
+ } as const,
+ ]
+ : []),
{
name: 'toggle-reconciled',
text: showReconciled
diff --git a/packages/desktop-client/src/components/autocomplete/AccountGroupAutocomplete.tsx b/packages/desktop-client/src/components/autocomplete/AccountGroupAutocomplete.tsx
new file mode 100644
index 0000000000..19282bb60b
--- /dev/null
+++ b/packages/desktop-client/src/components/autocomplete/AccountGroupAutocomplete.tsx
@@ -0,0 +1,195 @@
+import React, { Fragment } from 'react';
+import type {
+ ComponentProps,
+ ComponentPropsWithoutRef,
+ CSSProperties,
+ ReactElement,
+} from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { useResponsive } from '@actual-app/components/hooks/useResponsive';
+import { styles } from '@actual-app/components/styles';
+import { TextOneLine } from '@actual-app/components/text-one-line';
+import { theme } from '@actual-app/components/theme';
+import { View } from '@actual-app/components/view';
+import type { AccountGroupEntity } from '@actual-app/core/types/models';
+import { css, cx } from '@emotion/css';
+
+import { Autocomplete } from './Autocomplete';
+
+export const NEW_ACCOUNT_GROUP_ID = 'new';
+
+type AccountGroupAutocompleteItem = Pick<AccountGroupEntity, 'id' | 'name'>;
+
+function filterGroupSuggestions(
+ suggestions: AccountGroupAutocompleteItem[],
+ value: string,
+): AccountGroupAutocompleteItem[] {
+ const trimmed = value.trim().toLowerCase();
+ const matches = suggestions.filter(suggestion =>
+ suggestion.name.toLowerCase().includes(trimmed),
+ );
+ const hasExactMatch = matches.some(
+ suggestion => suggestion.name.toLowerCase() === trimmed,
+ );
+ if (trimmed === '' || hasExactMatch) {
+ return matches;
+ }
+ return [...matches, { id: NEW_ACCOUNT_GROUP_ID, name: value.trim() }];
+}
+
+type AccountGroupListProps = {
+ items: AccountGroupAutocompleteItem[];
+ getItemProps?: (arg: {
+ item: AccountGroupAutocompleteItem;
+ }) => Partial<ComponentProps<typeof View>>;
+ highlightedIndex: number;
+ embedded?: boolean;
+ renderAccountGroupItem?: (
+ props: ComponentPropsWithoutRef<typeof AccountGroupItem>,
+ ) => ReactElement<typeof AccountGroupItem>;
+};
+
+function AccountGroupList({
+ items,
+ getItemProps,
+ highlightedIndex,
+ embedded,
+ renderAccountGroupItem = defaultRenderAccountGroupItem,
+}: AccountGroupListProps) {
+ return (
+ <View>
+ <View
+ style={{
+ overflowY: 'auto',
+ willChange: 'transform',
+ padding: '5px 0',
+ ...(!embedded && { maxHeight: 175 }),
+ }}
+ >
+ {items.map((item, index) => (
+ <Fragment key={item.id}>
+ {renderAccountGroupItem({
+ ...(getItemProps ? getItemProps({ item }) : {}),
+ item,
+ highlighted: highlightedIndex === index,
+ embedded,
+ })}
+ </Fragment>
+ ))}
+ </View>
+ </View>
+ );
+}
+
+type AccountGroupAutocompleteProps = Omit<
+ Extract<
+ ComponentProps<typeof Autocomplete<AccountGroupAutocompleteItem>>,
+ { type?: 'single' | never }
+ >,
+ 'suggestions' | 'renderItems'
+> & {
+ groups: AccountGroupAutocompleteItem[];
+ renderAccountGroupItem?: (
+ props: ComponentPropsWithoutRef<typeof AccountGroupItem>,
+ ) => ReactElement<typeof AccountGroupItem>;
+};
+
+export function AccountGroupAutocomplete({
+ groups,
+ embedded,
+ renderAccountGroupItem,
+ ...props
+}: AccountGroupAutocompleteProps) {
+ return (
+ <Autocomplete
+ strict
+ highlightFirst
+ embedded={embedded}
+ suggestions={groups}
+ filterSuggestions={filterGroupSuggestions}
+ renderItems={(items, getItemProps, highlightedIndex) => (
+ <AccountGroupList
+ items={items}
+ getItemProps={getItemProps}
+ highlightedIndex={highlightedIndex}
+ embedded={embedded}
+ renderAccountGroupItem={renderAccountGroupItem}
+ />
+ )}
+ {...props}
+ />
+ );
+}
+
+type AccountGroupItemProps = {
+ item: AccountGroupAutocompleteItem;
+ className?: string;
+ style?: CSSProperties;
+ highlighted?: boolean;
+ embedded?: boolean;
+};
+
+function AccountGroupItem({
+ item,
+ className,
+ style,
+ highlighted,
+ embedded,
+ ...props
+}: AccountGroupItemProps) {
+ const { t } = useTranslation();
+ const { isNarrowWidth } = useResponsive();
+ const narrowStyle = isNarrowWidth
+ ? {
+ ...styles.mobileMenuItem,
+ borderRadius: 0,
+ borderTop: `1px solid ${theme.pillBorder}`,
+ }
+ : {};
+ const isCreateRow = item.id === NEW_ACCOUNT_GROUP_ID;
+
+ return (
+ <button
+ type="button"
+ style={style}
+ className={cx(
+ className,
+ css({
+ backgroundColor: highlighted
+ ? theme.menuAutoCompleteBackgroundHover
+ : 'transparent',
+ color: highlighted
+ ? theme.menuAutoCompleteItemTextHover
+ : isCreateRow
+ ? theme.noticeTextMenu
+ : theme.menuAutoCompleteItemText,
+ fontWeight: isCreateRow ? 500 : undefined,
+ padding: 4,
+ paddingLeft: 20,
+ borderRadius: embedded ? 4 : 0,
+ border: 'none',
+ font: 'inherit',
+ ...narrowStyle,
+ }),
+ )}
+ data-testid={`${item.name}-account-group-item`}
+ data-highlighted={highlighted || undefined}
+ {...props}
+ >
+ <View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
+ <TextOneLine>
+ {isCreateRow
+ ? `+ ${t('Create "{{name}}"', { name: item.name })}`
+ : item.name}
+ </TextOneLine>
+ </View>
+ </button>
+ );
+}
+
+function defaultRenderAccountGroupItem(
+ props: ComponentPropsWithoutRef<typeof AccountGroupItem>,
+): ReactElement<typeof AccountGroupItem> {
+ return <AccountGroupItem {...props} />;
+}
diff --git a/packages/desktop-client/src/components/modals/AccountGroupsModal/AccountGroupRow.tsx b/packages/desktop-client/src/components/modals/AccountGroupsModal/AccountGroupRow.tsx
new file mode 100644
index 0000000000..4c93745471
--- /dev/null
+++ b/packages/desktop-client/src/components/modals/AccountGroupsModal/AccountGroupRow.tsx
@@ -0,0 +1,141 @@
+import { useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { Button } from '@actual-app/components/button';
+import { SvgDelete } from '@actual-app/components/icons/v0';
+import {
+ SvgArrowThinDown,
+ SvgArrowThinUp,
+} from '@actual-app/components/icons/v1';
+import { SvgPencil1 } from '@actual-app/components/icons/v2';
+import { InitialFocus } from '@actual-app/components/initial-focus';
+import { Input } from '@actual-app/components/input';
+import { Text } from '@actual-app/components/text';
+import { View } from '@actual-app/components/view';
+import type { AccountGroupEntity } from '@actual-app/core/types/models';
+
+import {
+ useDeleteAccountGroupMutation,
+ useUpdateAccountGroupMutation,
+} from '#account-groups';
+import { pushModal } from '#modals/modalsSlice';
+import { useDispatch } from '#redux';
+
+import { SelectedIndicator } from './SelectedIndicator';
+
+type AccountGroupRowProps = {
+ group: AccountGroupEntity;
+ selected: boolean;
+ onSelect: () => void;
+ onMoveUp?: () => void;
+ onMoveDown?: () => void;
+};
+
+export function AccountGroupRow({
+ group,
+ selected,
+ onSelect,
+ onMoveUp,
+ onMoveDown,
+}: AccountGroupRowProps) {
+ const { t } = useTranslation();
+ const dispatch = useDispatch();
+ const updateGroup = useUpdateAccountGroupMutation();
+ const deleteGroup = useDeleteAccountGroupMutation();
+ const [isEditing, setIsEditing] = useState(false);
+
+ const onRename = (name: string) => {
+ const trimmed = name.trim();
+ if (!trimmed || trimmed === group.name) {
+ setIsEditing(false);
+ return;
+ }
+ updateGroup.mutate(
+ { id: group.id, name: trimmed },
+ { onSuccess: () => setIsEditing(false) },
+ );
+ };
+
+ const onDelete = () => {
+ dispatch(
+ pushModal({
+ modal: {
+ name: 'confirm-delete',
+ options: {
+ message: t(
+ 'Are you sure you want to delete the group "{{name}}"? Any accounts in it will be kept but left ungrouped.',
+ { name: group.name },
+ ),
+ onConfirm: () => deleteGroup.mutate({ id: group.id }),
+ },
+ },
+ }),
+ );
+ };
+
+ return (
+ <View style={{ flexDirection: 'row', alignItems: 'center', gap: 5 }}>
+ <SelectedIndicator selected={selected} />
+ {isEditing ? (
+ <InitialFocus>
+ <Input
+ defaultValue={group.name}
+ onEnter={onRename}
+ onKeyDown={event => {
+ if (event.key === 'Escape') {
+ event.stopPropagation();
+ setIsEditing(false);
+ }
+ }}
+ onBlur={() => setIsEditing(false)}
+ style={{ flex: 1 }}
+ />
+ </InitialFocus>
+ ) : (
+ <Button
+ variant="bare"
+ onPress={onSelect}
+ style={{ flex: 1, justifyContent: 'flex-start' }}
+ >
+ <Text style={{ fontWeight: selected ? 600 : 'normal' }}>
+ {group.name}
+ </Text>
+ </Button>
+ )}
+ {!isEditing && (
+ <>
+ <Button
+ variant="bare"
+ aria-label={t('Rename group')}
+ onPress={() => setIsEditing(true)}
+ >
+ <SvgPencil1 style={{ width: 11, height: 11 }} />
+ </Button>
+ <Button
+ variant="bare"
+ aria-label={t('Move group up')}
+ isDisabled={!onMoveUp}
+ onPress={() => onMoveUp?.()}
+ >
+ <SvgArrowThinUp style={{ width: 11, height: 11 }} />
+ </Button>
+ <Button
+ variant="bare"
+ aria-label={t('Move group down')}
+ isDisabled={!onMoveDown}
+ onPress={() => onMoveDown?.()}
+ >
+ <SvgArrowThinDown style={{ width: 11, height: 11 }} />
+ </Button>
+ <Button
+ variant="bare"
+ aria-label={t('Delete group')}
+ onPress={onDelete}
+ >
+ <SvgDelete style={{ width: 11, height: 11 }} />
+ </Button>
+ </>
+ )}
+ </View>
+ );
+}
diff --git a/packages/desktop-client/src/components/modals/AccountGroupsModal/AccountGroupsModal.tsx b/packages/desktop-client/src/components/modals/AccountGroupsModal/AccountGroupsModal.tsx
new file mode 100644
index 0000000000..3df178b225
--- /dev/null
+++ b/packages/desktop-client/src/components/modals/AccountGroupsModal/AccountGroupsModal.tsx
@@ -0,0 +1,153 @@
+import { Trans, useTranslation } from 'react-i18next';
+
+import { Button } from '@actual-app/components/button';
+import { AnimatedLoading } from '@actual-app/components/icons/AnimatedLoading';
+import { Text } from '@actual-app/components/text';
+import { theme } from '@actual-app/components/theme';
+import { View } from '@actual-app/components/view';
+import type {
+ AccountEntity,
+ AccountGroupEntity,
+} from '@actual-app/core/types/models';
+
+import {
+ useCreateAccountGroupMutation,
+ useMoveAccountGroupMutation,
+} from '#account-groups';
+import { useUpdateAccountMutation } from '#accounts';
+import {
+ AccountGroupAutocomplete,
+ NEW_ACCOUNT_GROUP_ID,
+} from '#components/autocomplete/AccountGroupAutocomplete';
+import {
+ Modal,
+ ModalCloseButton,
+ ModalHeader,
+ ModalTitle,
+} from '#components/common/Modal';
+import { useAccount } from '#hooks/useAccount';
+import { useAccountGroups } from '#hooks/useAccountGroups';
+
+import { AccountGroupRow } from './AccountGroupRow';
+import { SelectedIndicator } from './SelectedIndicator';
+
+type AccountGroupsModalProps = {
+ accountId: AccountEntity['id'];
+};
+
+export function AccountGroupsModal({ accountId }: AccountGroupsModalProps) {
+ const { t } = useTranslation();
+ const account = useAccount(accountId);
+ const { data: groups = [], isPlaceholderData } = useAccountGroups();
+
+ const createGroup = useCreateAccountGroupMutation();
+ const moveGroup = useMoveAccountGroupMutation();
+ const updateAccount = useUpdateAccountMutation();
+
+ const selectedGroupId =
+ account != null &&
+ groups.some(group => group.id === account.account_group_id)
+ ? account.account_group_id
+ : null;
+
+ const onSelect = (groupId: AccountGroupEntity['id'] | null) => {
+ updateAccount.mutate({
+ account: { id: accountId, account_group_id: groupId },
+ });
+ };
+
+ return (
+ <Modal name="account-groups">
+ {({ state }) => (
+ <>
+ <ModalHeader
+ title={<ModalTitle title={t('Account group')} shrinkOnOverflow />}
+ rightContent={<ModalCloseButton onPress={() => state.close()} />}
+ />
+ {isPlaceholderData ? (
+ <View style={{ alignItems: 'center', padding: 20 }}>
+ <AnimatedLoading width={20} height={20} />
+ </View>
+ ) : (
+ <View style={{ gap: 2 }}>
+ <View
+ style={{ flexDirection: 'row', alignItems: 'center', gap: 5 }}
+ >
+ <SelectedIndicator selected={selectedGroupId == null} />
+ <Button
+ variant="bare"
+ onPress={() => onSelect(null)}
+ style={{ flex: 1, justifyContent: 'flex-start' }}
+ >
+ <Text style={{ fontStyle: 'italic' }}>
+ <Trans>None</Trans>
+ </Text>
+ </Button>
+ </View>
+ {groups.map((group, index) => (
+ <AccountGroupRow
+ key={group.id}
+ group={group}
+ selected={selectedGroupId === group.id}
+ onSelect={() => onSelect(group.id)}
+ onMoveUp={
+ index > 0 && !moveGroup.isPending
+ ? () =>
+ moveGroup.mutate({
+ id: group.id,
+ targetId: groups[index - 1].id,
+ })
+ : undefined
+ }
+ onMoveDown={
+ index < groups.length - 1 && !moveGroup.isPending
+ ? () =>
+ moveGroup.mutate({
+ id: group.id,
+ targetId: groups[index + 2]?.id ?? null,
+ })
+ : undefined
+ }
+ />
+ ))}
+ {groups.length === 0 && (
+ <Text
+ style={{ color: theme.pageTextSubdued, padding: '5px 0' }}
+ >
+ <Trans>
+ No account groups yet. Add one below to start grouping your
+ accounts.
+ </Trans>
+ </Text>
+ )}
+ <View style={{ marginTop: 10 }}>
+ <AccountGroupAutocomplete
+ key={selectedGroupId ?? 'none'}
+ groups={groups}
+ value={null}
+ inputProps={{
+ placeholder: t('Find or create a group…'),
+ }}
+ onSelect={async (groupId, rawValue) => {
+ if (groupId === NEW_ACCOUNT_GROUP_ID) {
+ try {
+ const newId = await createGroup.mutateAsync({
+ name: rawValue.trim(),
+ });
+ onSelect(newId);
+ } catch {
+ // Creation failures surface as a notification
+ }
+ } else if (groupId) {
+ onSelect(groupId);
+ }
+ }}
+ />
+ </View>
+ </View>
+ )}
+ </>
+ )}
+ </Modal>
+ );
+}
diff --git a/packages/desktop-client/src/components/modals/AccountGroupsModal/SelectedIndicator.tsx b/packages/desktop-client/src/components/modals/AccountGroupsModal/SelectedIndicator.tsx
new file mode 100644
index 0000000000..360188c54d
--- /dev/null
+++ b/packages/desktop-client/src/components/modals/AccountGroupsModal/SelectedIndicator.tsx
@@ -0,0 +1,19 @@
+import { SvgCheck } from '@actual-app/components/icons/v2';
+import { theme } from '@actual-app/components/theme';
+
+type SelectedIndicatorProps = {
+ selected: boolean;
+};
+
+export function SelectedIndicator({ selected }: SelectedIndicatorProps) {
+ return (
+ <SvgCheck
+ style={{
+ width: 13,
+ height: 13,
+ flexShrink: 0,
+ color: selected ? theme.noticeText : 'transparent',
+ }}
+ />
+ );
+}
diff --git a/packages/desktop-client/src/components/modals/AccountGroupsModal/index.ts b/packages/desktop-client/src/components/modals/AccountGroupsModal/index.ts
new file mode 100644
index 0000000000..4b973c9b69
--- /dev/null
+++ b/packages/desktop-client/src/components/modals/AccountGroupsModal/index.ts
@@ -0,0 +1 @@
+export { AccountGroupsModal } from './AccountGroupsModal';
diff --git a/packages/desktop-client/src/components/settings/Experimental.tsx b/packages/desktop-client/src/components/settings/Experimental.tsx
index 4964e9f084..368691fb89 100644
--- a/packages/desktop-client/src/components/settings/Experimental.tsx
+++ b/packages/desktop-client/src/components/settings/Experimental.tsx
@@ -208,6 +208,9 @@ export function ExperimentalFeatures() {
>
<Trans>Mobile calculator</Trans>
</FeatureToggle>
+ <FeatureToggle flag="newSidebarUI">
+ <Trans>New sidebar UI</Trans>
+ </FeatureToggle>
<FeatureToggle
flag="sankeyReport"
feedbackLink="https://github.com/actualbudget/actual/issues/1919"
diff --git a/packages/desktop-client/src/hooks/useAccountGroups.ts b/packages/desktop-client/src/hooks/useAccountGroups.ts
new file mode 100644
index 0000000000..4f4b2fbf0e
--- /dev/null
+++ b/packages/desktop-client/src/hooks/useAccountGroups.ts
@@ -0,0 +1,7 @@
+import { useQuery } from '@tanstack/react-query';
+
+import { accountGroupQueries } from '#account-groups';
+
+export function useAccountGroups() {
+ return useQuery(accountGroupQueries.list());
+}
diff --git a/packages/desktop-client/src/hooks/useFeatureFlag.ts b/packages/desktop-client/src/hooks/useFeatureFlag.ts
index 976b5243d7..6e50fd8c7d 100644
--- a/packages/desktop-client/src/hooks/useFeatureFlag.ts
+++ b/packages/desktop-client/src/hooks/useFeatureFlag.ts
@@ -3,6 +3,7 @@ import type { FeatureFlag } from '@actual-app/core/types/prefs';
import { useSyncedPref } from './useSyncedPref';
const DEFAULT_FEATURE_FLAG_STATE: Record<FeatureFlag, boolean> = {
+ newSidebarUI: false,
goalTemplatesEnabled: false,
goalTemplatesUIEnabled: false,
actionTemplating: false,
diff --git a/packages/desktop-client/src/modals/modalsSlice.ts b/packages/desktop-client/src/modals/modalsSlice.ts
index a4a3a9e346..2833e36c32 100644
--- a/packages/desktop-client/src/modals/modalsSlice.ts
+++ b/packages/desktop-client/src/modals/modalsSlice.ts
@@ -59,6 +59,12 @@ export type Modal =
| {
name: 'add-local-account';
}
+ | {
+ name: 'account-groups';
+ options: {
+ accountId: AccountEntity['id'];
+ };
+ }
| {
name: 'close-account';
options: {
diff --git a/packages/desktop-client/src/sync-events.ts b/packages/desktop-client/src/sync-events.ts
index ad99481a68..595687e3b9 100644
--- a/packages/desktop-client/src/sync-events.ts
+++ b/packages/desktop-client/src/sync-events.ts
@@ -2,6 +2,7 @@ import { listen, send } from '@actual-app/core/platform/client/connection';
import type { QueryClient } from '@tanstack/react-query';
import { t } from 'i18next';
+import { accountGroupQueries } from './account-groups';
import { accountQueries } from './accounts';
import { resetSync, sync } from './app/appSlice';
import { categoryQueries } from './budget';
@@ -90,6 +91,12 @@ export function listenForSyncEvent(store: AppStore, queryClient: QueryClient) {
queryKey: accountQueries.lists(),
});
}
+
+ if (tables.includes('account_groups')) {
+ void queryClient.invalidateQueries({
+ queryKey: accountGroupQueries.lists(),
+ });
+ }
} else if (event.type === 'error') {
let notif: Notification | null = null;
const learnMore = `[${t('Learn more')}](https://actualbudget.org/docs/getting-started/sync/#debugging-sync-issues)`;
diff --git a/packages/loot-core/src/server/account-groups/app.test.ts b/packages/loot-core/src/server/account-groups/app.test.ts
index 5065ee8a5c..3216f450e6 100644
--- a/packages/loot-core/src/server/account-groups/app.test.ts
+++ b/packages/loot-core/src/server/account-groups/app.test.ts
@@ -140,11 +140,11 @@ describe('account groups app', () => {
await accountsApp.handlers['account-update']({
id: 'acct1',
- name: 'Marcus',
account_group_id: groupId,
});
let accounts = await accountsApp.handlers['accounts-get']();
expect(accounts[0].account_group_id).toBe(groupId);
+ expect(accounts[0].name).toBe('Marcus');
await accountsApp.handlers['account-update']({
id: 'acct1',
diff --git a/packages/loot-core/src/server/accounts/app.ts b/packages/loot-core/src/server/accounts/app.ts
index c8922134cc..3bb87cc451 100644
--- a/packages/loot-core/src/server/accounts/app.ts
+++ b/packages/loot-core/src/server/accounts/app.ts
@@ -96,11 +96,13 @@ async function updateAccount({
name,
last_reconciled,
account_group_id,
-}: Pick<AccountEntity, 'id' | 'name'> &
- Partial<Pick<AccountEntity, 'last_reconciled' | 'account_group_id'>>) {
+}: Pick<AccountEntity, 'id'> &
+ Partial<
+ Pick<AccountEntity, 'name' | 'last_reconciled' | 'account_group_id'>
+ >) {
await db.update('accounts', {
id,
- name,
+ ...(name !== undefined && { name }),
...(last_reconciled && { last_reconciled }),
...(account_group_id !== undefined && { account_group_id }),
});
diff --git a/packages/loot-core/src/types/prefs.ts b/packages/loot-core/src/types/prefs.ts
index 61edb7a4b7..f44bc00a57 100644
--- a/packages/loot-core/src/types/prefs.ts
+++ b/packages/loot-core/src/types/prefs.ts
@@ -1,4 +1,5 @@
export type FeatureFlag =
+ | 'newSidebarUI'
| 'goalTemplatesEnabled'
| 'goalTemplatesUIEnabled'
| 'actionTemplating'
diff --git a/upcoming-release-notes/add-account-groups-management-ui.md b/upcoming-release-notes/add-account-groups-management-ui.md
new file mode 100644
index 0000000000..98ccba6599
--- /dev/null
+++ b/upcoming-release-notes/add-account-groups-management-ui.md
@@ -0,0 +1,6 @@
+---
+category: Features
+authors: [matt-fidd]
+---
+
+Experimental: Add the ability to organise accounts into custom groups