Skip to content

A local-first personal finance app

:recycle: removing usages of MenuButton (#4555)

Matiss Janis Aboltins6fd5164987d8
diff --git a/packages/desktop-client/src/components/accounts/Header.tsx b/packages/desktop-client/src/components/accounts/Header.tsx
index f712ddf184..721e0bb528 100644
--- a/packages/desktop-client/src/components/accounts/Header.tsx
+++ b/packages/desktop-client/src/components/accounts/Header.tsx
@@ -5,6 +5,7 @@ import React, {
type ReactNode,
type ComponentProps,
} from 'react';
+import { DialogTrigger } from 'react-aria-components';
import { useHotkeys } from 'react-hotkeys-hook';
import { Trans, useTranslation } from 'react-i18next';
@@ -30,7 +31,7 @@ import { useLocalPref } from '../../hooks/useLocalPref';
import { useSplitsExpanded } from '../../hooks/useSplitsExpanded';
import { useSyncServerStatus } from '../../hooks/useSyncServerStatus';
import { AnimatedLoading } from '../../icons/AnimatedLoading';
-import { SvgAdd } from '../../icons/v1';
+import { SvgAdd, SvgDotsHorizontalTriple } from '../../icons/v1';
import {
SvgArrowsExpand3,
SvgArrowsShrink3,
@@ -41,7 +42,6 @@ import {
import { theme } from '../../style';
import { AnimatedRefresh } from '../AnimatedRefresh';
import { Input } from '../common/Input';
-import { MenuButton } from '../common/MenuButton';
import { Search } from '../common/Search';
import { FilterButton } from '../filters/FiltersMenu';
import { FiltersStack } from '../filters/FiltersStack';
@@ -189,10 +189,8 @@ export function AccountHeader({
}: AccountHeaderProps) {
const { t } = useTranslation();
- const [menuOpen, setMenuOpen] = useState(false);
const [reconcileOpen, setReconcileOpen] = useState(false);
const searchInput = useRef<HTMLInputElement>(null);
- const triggerRef = useRef(null);
const reconcileRef = useRef(null);
const splitsExpanded = useSplitsExpanded();
const syncServerStatus = useSyncServerStatus();
@@ -453,66 +451,59 @@ export function AccountHeader({
</Button>
{account ? (
<View style={{ flex: '0 0 auto' }}>
- <MenuButton
- aria-label={t('Account menu')}
- ref={triggerRef}
- onPress={() => setMenuOpen(true)}
- />
+ <DialogTrigger>
+ <Button variant="bare" aria-label={t('Account menu')}>
+ <SvgDotsHorizontalTriple
+ width={15}
+ height={15}
+ style={{ transform: 'rotateZ(90deg)' }}
+ />
+ </Button>
- <Popover
- triggerRef={triggerRef}
- style={{ width: 275 }}
- isOpen={menuOpen}
- onOpenChange={() => setMenuOpen(false)}
- >
- <AccountMenu
- account={account}
- canSync={canSync}
- canShowBalances={
- canCalculateBalance ? canCalculateBalance() : false
- }
- isSorted={isSorted}
- showBalances={showBalances}
- showCleared={showCleared}
- showReconciled={showReconciled}
- onMenuSelect={item => {
- setMenuOpen(false);
- onMenuSelect(item);
- }}
- />
- </Popover>
+ <Popover style={{ width: 275 }}>
+ <AccountMenu
+ account={account}
+ canSync={canSync}
+ canShowBalances={
+ canCalculateBalance ? canCalculateBalance() : false
+ }
+ isSorted={isSorted}
+ showBalances={showBalances}
+ showCleared={showCleared}
+ showReconciled={showReconciled}
+ onMenuSelect={onMenuSelect}
+ />
+ </Popover>
+ </DialogTrigger>
</View>
) : (
<View style={{ flex: '0 0 auto' }}>
- <MenuButton
- aria-label={t('Account menu')}
- ref={triggerRef}
- onPress={() => setMenuOpen(true)}
- />
+ <DialogTrigger>
+ <Button variant="bare" aria-label={t('Account menu')}>
+ <SvgDotsHorizontalTriple
+ width={15}
+ height={15}
+ style={{ transform: 'rotateZ(90deg)' }}
+ />
+ </Button>
- <Popover
- triggerRef={triggerRef}
- isOpen={menuOpen}
- onOpenChange={() => setMenuOpen(false)}
- >
- <Menu
- onMenuSelect={item => {
- setMenuOpen(false);
- onMenuSelect(item);
- }}
- items={[
- ...(isSorted
- ? [
- {
- name: 'remove-sorting',
- text: t('Remove all sorting'),
- } as const,
- ]
- : []),
- { name: 'export', text: t('Export') },
- ]}
- />
- </Popover>
+ <Popover>
+ <Menu
+ onMenuSelect={onMenuSelect}
+ items={[
+ ...(isSorted
+ ? [
+ {
+ name: 'remove-sorting',
+ text: t('Remove all sorting'),
+ } as const,
+ ]
+ : []),
+ { name: 'export', text: t('Export') },
+ ]}
+ />
+ </Popover>
+ </DialogTrigger>
</View>
)}
</Stack>
diff --git a/packages/desktop-client/src/components/common/MenuButton.tsx b/packages/desktop-client/src/components/common/MenuButton.tsx
deleted file mode 100644
index acb763cab4..0000000000
--- a/packages/desktop-client/src/components/common/MenuButton.tsx
+++ /dev/null
@@ -1,23 +0,0 @@
-import React, { type ComponentPropsWithoutRef, forwardRef } from 'react';
-
-import { Button } from '@actual-app/components/button';
-
-import { SvgDotsHorizontalTriple } from '../../icons/v1';
-
-type MenuButtonProps = ComponentPropsWithoutRef<typeof Button>;
-
-export const MenuButton = forwardRef<HTMLButtonElement, MenuButtonProps>(
- (props, ref) => {
- return (
- <Button ref={ref} variant="bare" aria-label="Menu" {...props}>
- <SvgDotsHorizontalTriple
- width={15}
- height={15}
- style={{ transform: 'rotateZ(90deg)' }}
- />
- </Button>
- );
- },
-);
-
-MenuButton.displayName = 'MenuButton';
diff --git a/packages/desktop-client/src/components/reports/Overview.tsx b/packages/desktop-client/src/components/reports/Overview.tsx
index 5c8bfedfe0..d92a4cabe6 100644
--- a/packages/desktop-client/src/components/reports/Overview.tsx
+++ b/packages/desktop-client/src/components/reports/Overview.tsx
@@ -1,4 +1,5 @@
-import React, { useMemo, useRef, useState } from 'react';
+import React, { useMemo, useState } from 'react';
+import { DialogTrigger } from 'react-aria-components';
import { Responsive, WidthProvider, type Layout } from 'react-grid-layout';
import { useHotkeys } from 'react-hotkeys-hook';
import { Trans, useTranslation } from 'react-i18next';
@@ -24,9 +25,9 @@ import { useAccounts } from '../../hooks/useAccounts';
import { useNavigate } from '../../hooks/useNavigate';
import { useSyncedPref } from '../../hooks/useSyncedPref';
import { useUndo } from '../../hooks/useUndo';
+import { SvgDotsHorizontalTriple } from '../../icons/v1';
import { useDispatch } from '../../redux';
import { breakpoints } from '../../tokens';
-import { MenuButton } from '../common/MenuButton';
import { MOBILE_NAV_HEIGHT } from '../mobile/MobileNavTabs';
import { MobilePageHeader, Page, PageHeader } from '../Page';
import { useResponsive } from '../responsive/ResponsiveProvider';
@@ -54,10 +55,6 @@ export function Overview() {
const [_firstDayOfWeekIdx] = useSyncedPref('firstDayOfWeekIdx');
const firstDayOfWeekIdx = _firstDayOfWeekIdx || '0';
- const triggerRef = useRef(null);
- const extraMenuTriggerRef = useRef(null);
- const [menuOpen, setMenuOpen] = useState(false);
- const [extraMenuOpen, setExtraMenuOpen] = useState(false);
const [isImporting, setIsImporting] = useState(false);
const [isEditing, setIsEditing] = useState(false);
const [currentBreakpoint, setCurrentBreakpoint] = useState<
@@ -171,7 +168,6 @@ export function Overview() {
height: 2,
meta,
});
- setMenuOpen(false);
};
const onRemoveWidget = (widgetId: string) => {
@@ -324,88 +320,81 @@ export function Overview() {
>
{currentBreakpoint === 'desktop' && (
<>
- <Button
- ref={triggerRef}
- variant="primary"
- isDisabled={isImporting}
- onPress={() => setMenuOpen(true)}
- >
- <Trans>Add new widget</Trans>
- </Button>
-
- <Popover
- triggerRef={triggerRef}
- isOpen={menuOpen}
- onOpenChange={() => setMenuOpen(false)}
- >
- <Menu
- onMenuSelect={item => {
- if (item === 'custom-report') {
- navigate('/reports/custom');
- return;
- }
-
- function isExistingCustomReport(
- name: string,
- ): name is `custom-report-${string}` {
- return name.startsWith('custom-report-');
- }
- if (isExistingCustomReport(item)) {
- const [, reportId] = item.split('custom-report-');
- onAddWidget<CustomReportWidget>('custom-report', {
- id: reportId,
- });
- return;
- }
-
- if (item === 'markdown-card') {
- onAddWidget<MarkdownWidget>(item, {
- content: `### ${t('Text Widget')}\n\n${t('Edit this widget to change the **markdown** content.')}`,
- });
- return;
- }
-
- onAddWidget(item);
- }}
- items={[
- {
- name: 'cash-flow-card' as const,
- text: t('Cash flow graph'),
- },
- {
- name: 'net-worth-card' as const,
- text: t('Net worth graph'),
- },
- {
- name: 'spending-card' as const,
- text: t('Spending analysis'),
- },
- {
- name: 'markdown-card' as const,
- text: t('Text widget'),
- },
- {
- name: 'summary-card' as const,
- text: t('Summary card'),
- },
- {
- name: 'calendar-card' as const,
- text: t('Calendar card'),
- },
- {
- name: 'custom-report' as const,
- text: t('New custom report'),
- },
- ...(customReports.length
- ? ([Menu.line] satisfies Array<typeof Menu.line>)
- : []),
- ...customReports.map(report => ({
- name: `custom-report-${report.id}` as const,
- text: report.name,
- })),
- ]}
- />
- </Popover>
+ <DialogTrigger>
+ <Button variant="primary" isDisabled={isImporting}>
+ <Trans>Add new widget</Trans>
+ </Button>
+
+ <Popover>
+ <Menu
+ onMenuSelect={item => {
+ if (item === 'custom-report') {
+ navigate('/reports/custom');
+ return;
+ }
+
+ function isExistingCustomReport(
+ name: string,
+ ): name is `custom-report-${string}` {
+ return name.startsWith('custom-report-');
+ }
+ if (isExistingCustomReport(item)) {
+ const [, reportId] = item.split('custom-report-');
+ onAddWidget<CustomReportWidget>('custom-report', {
+ id: reportId,
+ });
+ return;
+ }
+
+ if (item === 'markdown-card') {
+ onAddWidget<MarkdownWidget>(item, {
+ content: `### ${t('Text Widget')}\n\n${t('Edit this widget to change the **markdown** content.')}`,
+ });
+ return;
+ }
+
+ onAddWidget(item);
+ }}
+ items={[
+ {
+ name: 'cash-flow-card' as const,
+ text: t('Cash flow graph'),
+ },
+ {
+ name: 'net-worth-card' as const,
+ text: t('Net worth graph'),
+ },
+ {
+ name: 'spending-card' as const,
+ text: t('Spending analysis'),
+ },
+ {
+ name: 'markdown-card' as const,
+ text: t('Text widget'),
+ },
+ {
+ name: 'summary-card' as const,
+ text: t('Summary card'),
+ },
+ {
+ name: 'calendar-card' as const,
+ text: t('Calendar card'),
+ },
+ {
+ name: 'custom-report' as const,
+ text: t('New custom report'),
+ },
+ ...(customReports.length
+ ? ([Menu.line] satisfies Array<typeof Menu.line>)
+ : []),
+ ...customReports.map(report => ({
+ name: `custom-report-${report.id}` as const,
+ text: report.name,
+ })),
+ ]}
+ />
+ </Popover>
+ </DialogTrigger>
{isEditing ? (
<Button
@@ -423,50 +412,50 @@ export function Overview() {
</Button>
)}
- <MenuButton
- ref={extraMenuTriggerRef}
- onPress={() => setExtraMenuOpen(true)}
- />
- <Popover
- triggerRef={extraMenuTriggerRef}
- isOpen={extraMenuOpen}
- onOpenChange={() => setExtraMenuOpen(false)}
- >
- <Menu
- onMenuSelect={item => {
- switch (item) {
- case 'reset':
- onResetDashboard();
- break;
- case 'export':
- onExport();
- break;
- case 'import':
- onImport();
- break;
- }
- setExtraMenuOpen(false);
- }}
- items={[
- {
- name: 'reset',
- text: t('Reset to default'),
- disabled: isImporting,
- },
- Menu.line,
- {
- name: 'import',
- text: t('Import'),
- disabled: isImporting,
- },
- {
- name: 'export',
- text: t('Export'),
- disabled: isImporting,
- },
- ]}
- />
- </Popover>
+ <DialogTrigger>
+ <Button variant="bare" aria-label={t('Menu')}>
+ <SvgDotsHorizontalTriple
+ width={15}
+ height={15}
+ style={{ transform: 'rotateZ(90deg)' }}
+ />
+ </Button>
+ <Popover>
+ <Menu
+ onMenuSelect={item => {
+ switch (item) {
+ case 'reset':
+ onResetDashboard();
+ break;
+ case 'export':
+ onExport();
+ break;
+ case 'import':
+ onImport();
+ break;
+ }
+ }}
+ items={[
+ {
+ name: 'reset',
+ text: t('Reset to default'),
+ disabled: isImporting,
+ },
+ Menu.line,
+ {
+ name: 'import',
+ text: t('Import'),
+ disabled: isImporting,
+ },
+ {
+ name: 'export',
+ text: t('Export'),
+ disabled: isImporting,
+ },
+ ]}
+ />
+ </Popover>
+ </DialogTrigger>
</>
)}
</View>
diff --git a/packages/desktop-client/src/components/reports/ReportCard.tsx b/packages/desktop-client/src/components/reports/ReportCard.tsx
index b1270ee243..3afc441360 100644
--- a/packages/desktop-client/src/components/reports/ReportCard.tsx
+++ b/packages/desktop-client/src/components/reports/ReportCard.tsx
@@ -4,16 +4,18 @@ import React, {
type ReactNode,
type CSSProperties,
} from 'react';
+import { useTranslation } from 'react-i18next';
+import { Button } from '@actual-app/components/button';
import { Menu } from '@actual-app/components/menu';
import { Popover } from '@actual-app/components/popover';
+import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { useContextMenu } from '../../hooks/useContextMenu';
import { useIsInViewport } from '../../hooks/useIsInViewport';
import { useNavigate } from '../../hooks/useNavigate';
-import { theme } from '../../style';
-import { MenuButton } from '../common/MenuButton';
+import { SvgDotsHorizontalTriple } from '../../icons/v1';
import { useResponsive } from '../responsive/ResponsiveProvider';
import { NON_DRAGGABLE_AREA_CLASS_NAME } from './constants';
@@ -121,6 +123,8 @@ type LayoutProps = {
} & Pick<ReportCardProps, 'isEditing' | 'menuItems' | 'onMenuSelect'>;
function Layout({ children, isEditing, menuItems, onMenuSelect }: LayoutProps) {
+ const { t } = useTranslation();
+
const triggerRef = useRef(null);
const viewRef = useRef(null);
@@ -164,13 +168,21 @@ function Layout({ children, isEditing, menuItems, onMenuSelect }: LayoutProps) {
zIndex: 1,
}}
>
- <MenuButton
+ <Button
ref={triggerRef}
+ variant="bare"
+ aria-label={t('Menu')}
onPress={() => {
resetPosition();
setMenuOpen(true);
}}
- />
+ >
+ <SvgDotsHorizontalTriple
+ width={15}
+ height={15}
+ style={{ transform: 'rotateZ(90deg)' }}
+ />
+ </Button>
</View>
)}
diff --git a/upcoming-release-notes/4555.md b/upcoming-release-notes/4555.md
new file mode 100644
index 0000000000..b89caf66b0
--- /dev/null
+++ b/upcoming-release-notes/4555.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [MatissJanis]
+---
+
+Removing usages of `MenuButton`.