Skip to content

A local-first personal finance app

feat: expandable budget categories (#4807)

Michael Süssemilch4b5833578077
diff --git a/packages/component-library/src/icons/v2/ArrowButtonSingleLeft1.tsx b/packages/component-library/src/icons/v2/ArrowButtonSingleLeft1.tsx
new file mode 100644
index 0000000000..bbb8da325d
--- /dev/null
+++ b/packages/component-library/src/icons/v2/ArrowButtonSingleLeft1.tsx
@@ -0,0 +1,18 @@
+import * as React from 'react';
+import type { SVGProps } from 'react';
+export const SvgArrowButtonSingleLeft1 = (props: SVGProps<SVGSVGElement>) => (
+ <svg
+ {...props}
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 24 24"
+ style={{
+ color: 'inherit',
+ ...props.style,
+ }}
+ >
+ <path
+ d="M.25 12a2.643 2.643 0 0 1 .775-1.875L10.566.584a1.768 1.768 0 0 1 2.5 2.5l-8.739 8.739a.25.25 0 0 0 0 .354l8.739 8.739a1.768 1.768 0 0 1-2.5 2.5l-9.541-9.541A2.643 2.643 0 0 1 .25 12Z"
+ fill="currentColor"
+ />
+ </svg>
+);
diff --git a/packages/component-library/src/icons/v2/arrow-button-single-left-1.svg b/packages/component-library/src/icons/v2/arrow-button-single-left-1.svg
new file mode 100644
index 0000000000..978b07925d
--- /dev/null
+++ b/packages/component-library/src/icons/v2/arrow-button-single-left-1.svg
@@ -0,0 +1 @@
+<svg id="Bold" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><title>arrow-button-single-left-1</title><path d="M.25,12a2.643,2.643,0,0,1,.775-1.875L10.566.584a1.768,1.768,0,0,1,2.5,2.5L4.327,11.823a.25.25,0,0,0,0,.354l8.739,8.739a1.768,1.768,0,0,1-2.5,2.5L1.025,13.875A2.643,2.643,0,0,1,.25,12Z"/></svg>
\ No newline at end of file
diff --git a/packages/component-library/src/icons/v2/index.ts b/packages/component-library/src/icons/v2/index.ts
index 49fcdece75..a9bb12120a 100644
--- a/packages/component-library/src/icons/v2/index.ts
+++ b/packages/component-library/src/icons/v2/index.ts
@@ -2,6 +2,7 @@ export { SvgAlertTriangle } from './AlertTriangle';
export { SvgArrowButtonDown1 } from './ArrowButtonDown1';
export { SvgArrowButtonLeft1 } from './ArrowButtonLeft1';
export { SvgArrowButtonRight1 } from './ArrowButtonRight1';
+export { SvgArrowButtonSingleLeft1 } from './ArrowButtonSingleLeft1';
export { SvgArrowButtonUp1 } from './ArrowButtonUp1';
export { SvgArrowsExpand3 } from './ArrowsExpand3';
export { SvgArrowsShrink3 } from './ArrowsShrink3';
diff --git a/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-renders-the-summary-information-available-funds-overspent-budgeted-and-for-next-month-1-chromium-linux.png b/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-renders-the-summary-information-available-funds-overspent-budgeted-and-for-next-month-1-chromium-linux.png
index feccc3970c..55f045aa36 100644
Binary files a/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-renders-the-summary-information-available-funds-overspent-budgeted-and-for-next-month-1-chromium-linux.png and b/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-renders-the-summary-information-available-funds-overspent-budgeted-and-for-next-month-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-renders-the-summary-information-available-funds-overspent-budgeted-and-for-next-month-2-chromium-linux.png b/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-renders-the-summary-information-available-funds-overspent-budgeted-and-for-next-month-2-chromium-linux.png
index 2b5fc11e67..0bef751e12 100644
Binary files a/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-renders-the-summary-information-available-funds-overspent-budgeted-and-for-next-month-2-chromium-linux.png and b/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-renders-the-summary-information-available-funds-overspent-budgeted-and-for-next-month-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-renders-the-summary-information-available-funds-overspent-budgeted-and-for-next-month-3-chromium-linux.png b/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-renders-the-summary-information-available-funds-overspent-budgeted-and-for-next-month-3-chromium-linux.png
index bad7b89da5..fd0e3ff942 100644
Binary files a/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-renders-the-summary-information-available-funds-overspent-budgeted-and-for-next-month-3-chromium-linux.png and b/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-renders-the-summary-information-available-funds-overspent-budgeted-and-for-next-month-3-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-transfer-funds-to-another-category-1-chromium-linux.png b/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-transfer-funds-to-another-category-1-chromium-linux.png
index 22427b2890..ddd660d6ca 100644
Binary files a/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-transfer-funds-to-another-category-1-chromium-linux.png and b/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-transfer-funds-to-another-category-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-transfer-funds-to-another-category-2-chromium-linux.png b/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-transfer-funds-to-another-category-2-chromium-linux.png
index b230234eb6..f25f48d2b1 100644
Binary files a/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-transfer-funds-to-another-category-2-chromium-linux.png and b/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-transfer-funds-to-another-category-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-transfer-funds-to-another-category-3-chromium-linux.png b/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-transfer-funds-to-another-category-3-chromium-linux.png
index cb5e58757b..22c6415a87 100644
Binary files a/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-transfer-funds-to-another-category-3-chromium-linux.png and b/packages/desktop-client/e2e/budget.test.ts-snapshots/Budget-transfer-funds-to-another-category-3-chromium-linux.png differ
diff --git a/packages/desktop-client/src/components/budget/BudgetPageHeader.tsx b/packages/desktop-client/src/components/budget/BudgetPageHeader.tsx
index ef61f4c040..a586517be8 100644
--- a/packages/desktop-client/src/components/budget/BudgetPageHeader.tsx
+++ b/packages/desktop-client/src/components/budget/BudgetPageHeader.tsx
@@ -3,6 +3,8 @@ import React, { type ComponentProps, memo } from 'react';
import { View } from '@actual-app/components/view';
+import { useGlobalPref } from '../../hooks/useGlobalPref';
+
import { MonthPicker } from './MonthPicker';
import { getScrollbarWidth } from './util';
@@ -15,10 +17,17 @@ type BudgetPageHeaderProps = {
export const BudgetPageHeader = memo<BudgetPageHeaderProps>(
({ startMonth, onMonthSelect, numMonths, monthBounds }) => {
+ const [categoryExpandedStatePref] = useGlobalPref('categoryExpandedState');
+ const categoryExpandedState = categoryExpandedStatePref ?? 0;
const offsetMultipleMonths = numMonths === 1 ? 4 : 0;
+
return (
<View
- style={{ marginLeft: 200 + 5 - offsetMultipleMonths, flexShrink: 0 }}
+ style={{
+ marginLeft:
+ 200 + 100 * categoryExpandedState + 5 - offsetMultipleMonths,
+ flexShrink: 0,
+ }}
>
<View
style={{
diff --git a/packages/desktop-client/src/components/budget/BudgetTable.tsx b/packages/desktop-client/src/components/budget/BudgetTable.tsx
index 283dbd6537..1ecd45fc80 100644
--- a/packages/desktop-client/src/components/budget/BudgetTable.tsx
+++ b/packages/desktop-client/src/components/budget/BudgetTable.tsx
@@ -14,6 +14,7 @@ import {
} from 'loot-core/types/models';
import { useCategories } from '../../hooks/useCategories';
+import { useGlobalPref } from '../../hooks/useGlobalPref';
import { useLocalPref } from '../../hooks/useLocalPref';
import { type DropPosition } from '../sort';
@@ -85,6 +86,8 @@ export function BudgetTable(props: BudgetTableProps) {
const [showHiddenCategories, setShowHiddenCategoriesPef] = useLocalPref(
'budget.showHiddenCategories',
);
+ const [categoryExpandedStatePref] = useGlobalPref('categoryExpandedState');
+ const categoryExpandedState = categoryExpandedStatePref ?? 0;
const [editing, setEditing] = useState<{ id: string; cell: string } | null>(
null,
);
@@ -249,7 +252,7 @@ export function BudgetTable(props: BudgetTableProps) {
paddingRight: 5 + getScrollbarWidth(),
}}
>
- <View style={{ width: 200 }} />
+ <View style={{ width: 200 + 100 * categoryExpandedState }} />
<MonthsProvider
startMonth={prewarmStartMonth}
numMonths={numMonths}
diff --git a/packages/desktop-client/src/components/budget/BudgetTotals.tsx b/packages/desktop-client/src/components/budget/BudgetTotals.tsx
index a5722480e8..3002e5930b 100644
--- a/packages/desktop-client/src/components/budget/BudgetTotals.tsx
+++ b/packages/desktop-client/src/components/budget/BudgetTotals.tsx
@@ -3,12 +3,19 @@ import { useTranslation, Trans } from 'react-i18next';
import { Button } from '@actual-app/components/button';
import { SvgDotsHorizontalTriple } from '@actual-app/components/icons/v1';
+import {
+ SvgArrowButtonLeft1,
+ SvgArrowButtonRight1,
+ SvgArrowButtonSingleLeft1,
+} from '@actual-app/components/icons/v2';
import { Menu } from '@actual-app/components/menu';
import { Popover } from '@actual-app/components/popover';
import { styles } from '@actual-app/components/styles';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
+import { useGlobalPref } from '../../hooks/useGlobalPref';
+
import { RenderMonths } from './RenderMonths';
import { getScrollbarWidth } from './util';
@@ -26,9 +33,30 @@ export const BudgetTotals = memo(function BudgetTotals({
collapseAllCategories,
}: BudgetTotalsProps) {
const { t } = useTranslation();
+ const [categoryExpandedStatePref, setCategoryExpandedStatePref] =
+ useGlobalPref('categoryExpandedState');
+ const categoryExpandedState = categoryExpandedStatePref ?? 0;
const [menuOpen, setMenuOpen] = useState(false);
const triggerRef = useRef(null);
+ const cycleExpandedState = () => {
+ const nextState = (categoryExpandedState + 1) % 3;
+ setCategoryExpandedStatePref(nextState);
+ };
+
+ const getExpandStateLabel = () => {
+ switch (categoryExpandedState) {
+ case 0:
+ return t('Expand');
+ case 1:
+ return t('Fully Expand');
+ case 2:
+ return t('Collapse');
+ default:
+ return t('Expand');
+ }
+ };
+
return (
<View
data-testid="budget-totals"
@@ -41,14 +69,21 @@ export const BudgetTotals = memo(function BudgetTotals({
marginRight: 5 + getScrollbarWidth(),
borderRadius: '4px 4px 0 0',
borderBottom: '1px solid ' + theme.tableBorder,
+ '& .hover-visible': {
+ opacity: 0,
+ transition: 'opacity .25s',
+ },
+ '&:hover .hover-visible': {
+ opacity: 1,
+ },
}}
>
<View
style={{
- width: 200,
+ width: 200 + 100 * categoryExpandedState,
color: theme.pageTextLight,
justifyContent: 'center',
- paddingLeft: 15,
+ paddingLeft: 5,
paddingRight: 5,
display: 'flex',
flexDirection: 'row',
@@ -57,6 +92,40 @@ export const BudgetTotals = memo(function BudgetTotals({
WebkitUserSelect: 'none',
}}
>
+ <Button
+ variant="bare"
+ aria-label={getExpandStateLabel()}
+ onPress={cycleExpandedState}
+ className="hover-visible"
+ style={{
+ color: 'currentColor',
+ padding: 3,
+ marginRight: 10,
+ }}
+ >
+ {categoryExpandedState === 0 ? (
+ <SvgArrowButtonSingleLeft1
+ style={{
+ width: 12,
+ height: 12,
+ }}
+ />
+ ) : categoryExpandedState === 1 ? (
+ <SvgArrowButtonLeft1
+ style={{
+ width: 12,
+ height: 12,
+ }}
+ />
+ ) : (
+ <SvgArrowButtonRight1
+ style={{
+ width: 12,
+ height: 12,
+ }}
+ />
+ )}
+ </Button>
<View style={{ flexGrow: '1' }}>
<Trans>Category</Trans>
</View>
diff --git a/packages/desktop-client/src/components/budget/DynamicBudgetTable.tsx b/packages/desktop-client/src/components/budget/DynamicBudgetTable.tsx
index 0875fda55d..27a58eaf8f 100644
--- a/packages/desktop-client/src/components/budget/DynamicBudgetTable.tsx
+++ b/packages/desktop-client/src/components/budget/DynamicBudgetTable.tsx
@@ -7,12 +7,14 @@ import { View } from '@actual-app/components/view';
import * as monthUtils from 'loot-core/shared/months';
+import { useGlobalPref } from '../../hooks/useGlobalPref';
+
import { useBudgetMonthCount } from './BudgetMonthCountContext';
import { BudgetPageHeader } from './BudgetPageHeader';
import { BudgetTable } from './BudgetTable';
-function getNumPossibleMonths(width: number) {
- const estimatedTableWidth = width - 200;
+function getNumPossibleMonths(width: number, categoryWidth: number) {
+ const estimatedTableWidth = width - categoryWidth;
if (estimatedTableWidth < 500) {
return 1;
@@ -46,10 +48,15 @@ const DynamicBudgetTableInner = ({
...props
}: DynamicBudgetTableInnerProps) => {
const { setDisplayMax } = useBudgetMonthCount();
+ const [categoryExpandedStatePref] = useGlobalPref('categoryExpandedState');
+ const categoryExpandedState = categoryExpandedStatePref ?? 0;
- const numPossible = getNumPossibleMonths(width);
+ const numPossible = getNumPossibleMonths(
+ width,
+ 200 + 100 * categoryExpandedState,
+ );
const numMonths = Math.min(numPossible, maxMonths);
- const maxWidth = 200 + 500 * numMonths;
+ const maxWidth = 200 + 100 * categoryExpandedState + 500 * numMonths;
useEffect(() => {
setDisplayMax(numPossible);
diff --git a/packages/desktop-client/src/components/budget/IncomeHeader.tsx b/packages/desktop-client/src/components/budget/IncomeHeader.tsx
index f44c0cbe6b..103461ce44 100644
--- a/packages/desktop-client/src/components/budget/IncomeHeader.tsx
+++ b/packages/desktop-client/src/components/budget/IncomeHeader.tsx
@@ -4,6 +4,8 @@ import { Trans } from 'react-i18next';
import { Button } from '@actual-app/components/button';
import { View } from '@actual-app/components/view';
+import { useGlobalPref } from '../../hooks/useGlobalPref';
+
import { RenderMonths } from './RenderMonths';
type IncomeHeaderProps = {
@@ -15,11 +17,13 @@ export function IncomeHeader({
MonthComponent,
onShowNewGroup,
}: IncomeHeaderProps) {
+ const [categoryExpandedStatePref] = useGlobalPref('categoryExpandedState');
+ const categoryExpandedState = categoryExpandedStatePref ?? 0;
return (
<View style={{ flexDirection: 'row', flex: 1 }}>
<View
style={{
- width: 200,
+ width: 200 + 100 * categoryExpandedState,
alignItems: 'flex-start',
justifyContent: 'flex-start',
}}
diff --git a/packages/desktop-client/src/components/budget/SidebarCategory.tsx b/packages/desktop-client/src/components/budget/SidebarCategory.tsx
index b2ba4ff1e7..37ec911d52 100644
--- a/packages/desktop-client/src/components/budget/SidebarCategory.tsx
+++ b/packages/desktop-client/src/components/budget/SidebarCategory.tsx
@@ -16,6 +16,7 @@ import {
import { useContextMenu } from '../../hooks/useContextMenu';
import { useFeatureFlag } from '../../hooks/useFeatureFlag';
+import { useGlobalPref } from '../../hooks/useGlobalPref';
import { NotesButton } from '../NotesButton';
import { InputCell } from '../table';
@@ -55,6 +56,8 @@ export function SidebarCategory({
}: SidebarCategoryProps) {
const { t } = useTranslation();
const goalTemplatesUIEnabled = useFeatureFlag('goalTemplatesUIEnabled');
+ const [categoryExpandedStatePref] = useGlobalPref('categoryExpandedState');
+ const categoryExpandedState = categoryExpandedStatePref ?? 0;
const temporary = category.id === 'new';
const { setMenuOpen, menuOpen, handleContextMenu, resetPosition, position } =
@@ -157,7 +160,7 @@ export function SidebarCategory({
<View
innerRef={innerRef}
style={{
- width: 200,
+ width: 200 + 100 * categoryExpandedState,
overflow: 'hidden',
'& .hover-visible': {
display: 'none',
diff --git a/packages/desktop-client/src/components/budget/SidebarGroup.tsx b/packages/desktop-client/src/components/budget/SidebarGroup.tsx
index 4567c8d95f..f9a973514c 100644
--- a/packages/desktop-client/src/components/budget/SidebarGroup.tsx
+++ b/packages/desktop-client/src/components/budget/SidebarGroup.tsx
@@ -18,6 +18,7 @@ import {
import { useContextMenu } from '../../hooks/useContextMenu';
import { useFeatureFlag } from '../../hooks/useFeatureFlag';
+import { useGlobalPref } from '../../hooks/useGlobalPref';
import { NotesButton } from '../NotesButton';
import { InputCell } from '../table';
@@ -56,6 +57,8 @@ export function SidebarGroup({
}: SidebarGroupProps) {
const { t } = useTranslation();
const isGoalTemplatesEnabled = useFeatureFlag('goalTemplatesEnabled');
+ const [categoryExpandedStatePref] = useGlobalPref('categoryExpandedState');
+ const categoryExpandedState = categoryExpandedStatePref ?? 0;
const temporary = group.id === 'new';
const { setMenuOpen, menuOpen, handleContextMenu, resetPosition, position } =
@@ -180,7 +183,7 @@ export function SidebarGroup({
innerRef={innerRef}
style={{
...style,
- width: 200,
+ width: 200 + 100 * categoryExpandedState,
backgroundColor: theme.tableRowHeaderBackground,
overflow: 'hidden',
'& .hover-visible': {
diff --git a/packages/loot-core/src/server/preferences/app.ts b/packages/loot-core/src/server/preferences/app.ts
index 4df984e80e..01554a96b3 100644
--- a/packages/loot-core/src/server/preferences/app.ts
+++ b/packages/loot-core/src/server/preferences/app.ts
@@ -69,6 +69,12 @@ async function saveGlobalPrefs(prefs: GlobalPrefs) {
if (prefs.maxMonths !== undefined) {
await asyncStorage.setItem('max-months', '' + prefs.maxMonths);
}
+ if (prefs.categoryExpandedState) {
+ await asyncStorage.setItem(
+ 'category-expanded-state',
+ '' + prefs.categoryExpandedState,
+ );
+ }
if (prefs.documentDir !== undefined && (await fs.exists(prefs.documentDir))) {
await asyncStorage.setItem('document-dir', prefs.documentDir);
}
@@ -99,6 +105,7 @@ async function saveGlobalPrefs(prefs: GlobalPrefs) {
async function loadGlobalPrefs(): Promise<GlobalPrefs> {
const [
[, floatingSidebar],
+ [, categoryExpandedState],
[, maxMonths],
[, documentDir],
[, encryptKey],
@@ -108,6 +115,7 @@ async function loadGlobalPrefs(): Promise<GlobalPrefs> {
[, serverSelfSignedCert],
] = await asyncStorage.multiGet([
'floating-sidebar',
+ 'category-expanded-state',
'max-months',
'document-dir',
'encrypt-key',
@@ -118,6 +126,7 @@ async function loadGlobalPrefs(): Promise<GlobalPrefs> {
] as const);
return {
floatingSidebar: floatingSidebar === 'true',
+ categoryExpandedState: stringToInteger(categoryExpandedState || '') || 0,
maxMonths: stringToInteger(maxMonths || '') || 1,
documentDir: documentDir || getDefaultDocumentDir(),
keyId: encryptKey && JSON.parse(encryptKey).id,
diff --git a/packages/loot-core/src/types/prefs.d.ts b/packages/loot-core/src/types/prefs.d.ts
index afdbbb1d94..0ab7ab57e4 100644
--- a/packages/loot-core/src/types/prefs.d.ts
+++ b/packages/loot-core/src/types/prefs.d.ts
@@ -84,6 +84,7 @@ export type DarkTheme = 'dark' | 'midnight';
export type GlobalPrefs = Partial<{
floatingSidebar: boolean;
maxMonths: number;
+ categoryExpandedState: number;
keyId?: string;
language: string;
theme: Theme;
@@ -109,6 +110,7 @@ export type GlobalPrefsJson = Partial<{
'user-token'?: string;
'floating-sidebar'?: string; // "true" or "false"
'max-months'?: string; // e.g. "2" or "3"
+ 'category-expanded-state'?: string; // "0" or "1" or "2"
'document-dir'?: GlobalPrefs['documentDir'];
'encrypt-key'?: string;
language?: GlobalPrefs['language'];
diff --git a/upcoming-release-notes/4807.md b/upcoming-release-notes/4807.md
new file mode 100644
index 0000000000..476c5237b2
--- /dev/null
+++ b/upcoming-release-notes/4807.md
@@ -0,0 +1,6 @@
+---
+category: Features
+authors: [misu-dev]
+---
+
+Adds a feature to resize the category names in the budget table.