Skip to content

A local-first personal finance app

add account hover card (#8969)

Matt Fiddaman749fa264571c
diff --git a/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx b/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx
index 1dd0fc68b1..eb44d9257e 100644
--- a/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx
@@ -22,6 +22,7 @@ import { useAccounts } from '#hooks/useAccounts';
import { useCategories } from '#hooks/useCategories';
import { useFormat } from '#hooks/useFormat';
import { useNavigate } from '#hooks/useNavigate';
+import { isTouchDevice } from '#util/isTouchDevice';
import { adjustTextSize } from './adjustTextSize';
import { renderCustomLabel } from './renderCustomLabel';
@@ -29,8 +30,6 @@ import { showActivity } from './showActivity';
const RADIAN = Math.PI / 180;
-const canDeviceHover = () => window.matchMedia('(hover: hover)').matches;
-
type ClickablePieItem = PieSectorDataItem &
Partial<Pick<GroupedEntity, 'id' | 'uncategorizedId'>>;
@@ -487,18 +486,18 @@ export function DonutGraph({
}}
onMouseLeave={() => setPointer('')}
onMouseEnter={(_, index) => {
- if (canDeviceHover()) {
+ if (!isTouchDevice()) {
setActiveGroupIndex(index);
setActiveRing('group');
}
}}
onClick={(item: ClickablePieItem, index) => {
- if (!canDeviceHover()) {
+ if (isTouchDevice()) {
setActiveGroupIndex(index);
setActiveRing('group');
}
if (
- (canDeviceHover() || activeGroupIndex === index) &&
+ (!isTouchDevice() || activeGroupIndex === index) &&
((compact && showTooltip) || !compact)
) {
showActivity({
@@ -569,19 +568,19 @@ export function DonutGraph({
}}
onMouseLeave={() => setPointer('')}
onMouseEnter={(_, index) => {
- if (canDeviceHover()) {
+ if (!isTouchDevice()) {
setActiveCategoryIndex(index);
setActiveRing('category');
setPointer('pointer');
}
}}
onClick={(item: ClickablePieItem, index) => {
- if (!canDeviceHover()) {
+ if (isTouchDevice()) {
setActiveCategoryIndex(index);
setActiveRing('category');
}
if (
- (canDeviceHover() || activeCategoryIndex === index) &&
+ (!isTouchDevice() || activeCategoryIndex === index) &&
((compact && showTooltip) || !compact)
) {
showActivity({
@@ -664,7 +663,7 @@ export function DonutGraph({
}}
onMouseLeave={() => setPointer('')}
onMouseEnter={(_, index) => {
- if (canDeviceHover()) {
+ if (!isTouchDevice()) {
setActiveIndex(index);
if (groupBy !== 'Interval') {
setPointer('pointer');
@@ -672,12 +671,12 @@ export function DonutGraph({
}
}}
onClick={(item: ClickablePieItem, index) => {
- if (!canDeviceHover()) {
+ if (isTouchDevice()) {
setActiveIndex(index);
}
if (
groupBy !== 'Interval' &&
- (canDeviceHover() || activeIndex === index) &&
+ (!isTouchDevice() || activeIndex === index) &&
((compact && showTooltip) || !compact)
) {
showActivity({
diff --git a/packages/desktop-client/src/components/sidebar/Account.tsx b/packages/desktop-client/src/components/sidebar/Account.tsx
index 768789f833..2395428452 100644
--- a/packages/desktop-client/src/components/sidebar/Account.tsx
+++ b/packages/desktop-client/src/components/sidebar/Account.tsx
@@ -35,6 +35,7 @@ import { useSyncedPref } from '#hooks/useSyncedPref';
import { openAccountCloseModal } from '#modals/modalsSlice';
import { useDispatch, useSelector } from '#redux';
import type { Binding, SheetFields } from '#spreadsheet';
+import { isTouchDevice } from '#util/isTouchDevice';
export const accountNameStyle: CSSProperties = {
marginTop: -2,
@@ -119,10 +120,7 @@ export function Account<FieldName extends SheetFields<'account'>>({
const [isEditing, setIsEditing] = useState(false);
const accountNote = useNotes(`account-${account?.id}`);
- const isTouchDevice =
- window.matchMedia('(hover: none)').matches ||
- window.matchMedia('(pointer: coarse)').matches;
- const needsTooltip = !!account?.id && !isTouchDevice;
+ const needsTooltip = !!account?.id && !isTouchDevice();
const reopenAccount = useReopenAccountMutation();
const updateAccount = useUpdateAccountMutation();
diff --git a/packages/desktop-client/src/components/sidebar/redesign/AccountGroupHeader.tsx b/packages/desktop-client/src/components/sidebar/redesign/AccountGroupHeader.tsx
index 53cb88a9c6..d99153f366 100644
--- a/packages/desktop-client/src/components/sidebar/redesign/AccountGroupHeader.tsx
+++ b/packages/desktop-client/src/components/sidebar/redesign/AccountGroupHeader.tsx
@@ -1,4 +1,9 @@
+import { useRef, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
import { Button } from '@actual-app/components/button';
+import { InitialFocus } from '@actual-app/components/initial-focus';
+import { Input } from '@actual-app/components/input';
import { styles } from '@actual-app/components/styles';
import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
@@ -7,6 +12,13 @@ import { View } from '@actual-app/components/view';
import type { AccountGroupEntity } from '@actual-app/core/types/models';
import { css } from '@emotion/css';
+import {
+ useDeleteAccountGroupMutation,
+ useUpdateAccountGroupMutation,
+} from '#account-groups';
+import { useContextMenu } from '#hooks/useContextMenu';
+import { pushModal } from '#modals/modalsSlice';
+import { useDispatch } from '#redux';
import * as bindings from '#spreadsheet/bindings';
import { CollapseChevron } from './CollapseChevron';
@@ -32,8 +44,78 @@ export function AccountGroupHeader({
isOpen,
onToggle,
}: AccountGroupHeaderProps) {
+ const { t } = useTranslation();
+ const dispatch = useDispatch();
+ const [isEditing, setIsEditing] = useState(false);
+ const updateGroup = useUpdateAccountGroupMutation();
+ const deleteGroup = useDeleteAccountGroupMutation();
+
+ const triggerRef = useRef<HTMLButtonElement>(null);
+ useContextMenu({
+ triggerRef,
+ items: [
+ {
+ name: 'account-group-rename',
+ text: t('Rename group'),
+ onClick: () => setIsEditing(true),
+ },
+ {
+ name: 'account-group-delete',
+ text: t('Delete group'),
+ onClick: () =>
+ 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 }),
+ },
+ },
+ }),
+ ),
+ },
+ ],
+ });
+
+ if (isEditing) {
+ return (
+ <View
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ gap: spacing.xs,
+ paddingBlock: spacing.xs,
+ paddingLeft: spacing.xs,
+ paddingRight: spacing.sm,
+ }}
+ >
+ <CollapseChevron isOpen={isOpen} size={11} />
+ <InitialFocus>
+ <Input
+ aria-label={t('Group name')}
+ style={{ flex: 1, padding: 0, fontSize: 12 }}
+ defaultValue={group.name}
+ onEnter={newGroupName => {
+ if (newGroupName.trim() !== '') {
+ updateGroup.mutate({ id: group.id, name: newGroupName });
+ }
+ setIsEditing(false);
+ }}
+ onEscape={() => setIsEditing(false)}
+ onBlur={() => setIsEditing(false)}
+ />
+ </InitialFocus>
+ </View>
+ );
+ }
+
return (
<Button
+ ref={triggerRef}
variant="bare"
aria-expanded={isOpen}
onPress={onToggle}
diff --git a/packages/desktop-client/src/components/sidebar/redesign/AccountHoverCard.tsx b/packages/desktop-client/src/components/sidebar/redesign/AccountHoverCard.tsx
new file mode 100644
index 0000000000..932506ce17
--- /dev/null
+++ b/packages/desktop-client/src/components/sidebar/redesign/AccountHoverCard.tsx
@@ -0,0 +1,114 @@
+import type { ReactElement } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { Button } from '@actual-app/components/button';
+import {
+ SvgArrowButtonDown1,
+ SvgArrowButtonUp1,
+} from '@actual-app/components/icons/v2';
+import { SpaceBetween } from '@actual-app/components/space-between';
+import { styles } from '@actual-app/components/styles';
+import { Text } from '@actual-app/components/text';
+import { theme } from '@actual-app/components/theme';
+import { spacing } from '@actual-app/components/tokens';
+import { Tooltip } from '@actual-app/components/tooltip';
+import { View } from '@actual-app/components/view';
+import type { AccountEntity } from '@actual-app/core/types/models';
+
+import { BalanceHistoryGraph } from '#components/accounts/BalanceHistoryGraph';
+import { Notes } from '#components/Notes';
+import { useIsTestEnv } from '#hooks/useIsTestEnv';
+import { useNotes } from '#hooks/useNotes';
+import { useSyncedPref } from '#hooks/useSyncedPref';
+import { isTouchDevice } from '#util/isTouchDevice';
+
+type AccountHoverCardProps = {
+ account: AccountEntity;
+ isDisabled: boolean;
+ children: ReactElement;
+};
+
+export function AccountHoverCard({
+ account,
+ isDisabled,
+ children,
+}: AccountHoverCardProps) {
+ const { t } = useTranslation();
+ const isTestEnv = useIsTestEnv();
+ const [showBalanceHistory, setShowBalanceHistory] = useSyncedPref(
+ `side-nav.show-balance-history-${account.id}`,
+ );
+ const accountNote = useNotes(`account-${account.id}`);
+
+ if (isTouchDevice() || isTestEnv) {
+ return children;
+ }
+
+ return (
+ <Tooltip
+ content={
+ <View style={{ padding: spacing.md }}>
+ <SpaceBetween
+ gap={spacing.xs}
+ style={{
+ justifyContent: 'space-between',
+ '& .hover-visible': {
+ opacity: 0,
+ transition: 'opacity .25s',
+ },
+ '&:hover .hover-visible': {
+ opacity: 1,
+ },
+ }}
+ >
+ <Text style={{ fontWeight: 'bold' }}>{account.name}</Text>
+ <Button
+ aria-label={t('Toggle balance history')}
+ variant="bare"
+ onClick={() =>
+ setShowBalanceHistory(
+ showBalanceHistory === 'true' ? 'false' : 'true',
+ )
+ }
+ className="hover-visible"
+ >
+ <SpaceBetween gap={spacing.xxs}>
+ {showBalanceHistory === 'true' ? (
+ <SvgArrowButtonUp1 width={10} height={10} />
+ ) : (
+ <SvgArrowButtonDown1 width={10} height={10} />
+ )}
+ </SpaceBetween>
+ </Button>
+ </SpaceBetween>
+ {showBalanceHistory === 'true' && (
+ <BalanceHistoryGraph
+ accountId={account.id}
+ style={{ minWidth: 350, minHeight: 70 }}
+ />
+ )}
+ {accountNote && (
+ <Notes
+ getStyle={() => ({
+ borderTop: `1px solid ${theme.tooltipBorder}`,
+ padding: 0,
+ paddingTop: spacing.sm,
+ marginTop: spacing.sm,
+ })}
+ notes={accountNote}
+ />
+ )}
+ </View>
+ }
+ style={{ ...styles.tooltip, borderRadius: '0px 5px 5px 0px' }}
+ placement="right top"
+ triggerProps={{
+ delay: 1000,
+ closeDelay: 250,
+ isDisabled,
+ }}
+ >
+ {children}
+ </Tooltip>
+ );
+}
diff --git a/packages/desktop-client/src/components/sidebar/redesign/AccountRow.tsx b/packages/desktop-client/src/components/sidebar/redesign/AccountRow.tsx
index ba72fea70f..7ec72996b1 100644
--- a/packages/desktop-client/src/components/sidebar/redesign/AccountRow.tsx
+++ b/packages/desktop-client/src/components/sidebar/redesign/AccountRow.tsx
@@ -1,15 +1,26 @@
+import { useRef, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { InitialFocus } from '@actual-app/components/initial-focus';
+import { Input } from '@actual-app/components/input';
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 { AccountEntity } from '@actual-app/core/types/models';
+import { useReopenAccountMutation, useUpdateAccountMutation } from '#accounts';
import { isAccountFailedSync } from '#accounts/syncStatus';
import { Link } from '#components/common/Link';
+import { useContextMenu } from '#hooks/useContextMenu';
import { useUpdatedAccounts } from '#hooks/useUpdatedAccounts';
-import { useSelector } from '#redux';
+import { openAccountCloseModal, pushModal } from '#modals/modalsSlice';
+import { useDispatch, useSelector } from '#redux';
import * as bindings from '#spreadsheet/bindings';
+import { isTouchDevice } from '#util/isTouchDevice';
+import { AccountHoverCard } from './AccountHoverCard';
import { SidebarBalance } from './SidebarBalance';
import { SyncDot, useSyncDotLabel } from './SyncDot';
import type { SyncDotStatus } from './SyncDot';
@@ -25,9 +36,59 @@ export function AccountRow({
isClosed,
showSyncDot,
}: AccountRowProps) {
+ const { t } = useTranslation();
+ const dispatch = useDispatch();
const syncingAccountIds = useSelector(state => state.account.accountsSyncing);
const updatedAccounts = useUpdatedAccounts();
const isUpdated = !isClosed && updatedAccounts.includes(account.id);
+ const [isEditing, setIsEditing] = useState(false);
+
+ const reopenAccount = useReopenAccountMutation();
+ const updateAccount = useUpdateAccountMutation();
+
+ const isContextMenuOpen = useSelector(state =>
+ state.contextMenu.items.some(
+ i =>
+ typeof i === 'object' && 'name' in i && i.name.startsWith('account-'),
+ ),
+ );
+ const triggerRef = useRef<HTMLDivElement>(null);
+ useContextMenu({
+ triggerRef,
+ enabled: !isTouchDevice(),
+ items: [
+ {
+ name: 'account-rename',
+ text: t('Rename'),
+ onClick: () => setIsEditing(true),
+ },
+ isClosed
+ ? {
+ name: 'account-reopen',
+ text: t('Reopen'),
+ onClick: () => reopenAccount.mutate({ id: account.id }),
+ }
+ : {
+ name: 'account-close',
+ text: t('Close'),
+ onClick: () =>
+ dispatch(openAccountCloseModal({ accountId: account.id })),
+ },
+ {
+ name: 'account-group',
+ text: t('Set account group'),
+ onClick: () =>
+ dispatch(
+ pushModal({
+ modal: {
+ name: 'account-groups',
+ options: { accountId: account.id },
+ },
+ }),
+ ),
+ },
+ ],
+ });
let status: SyncDotStatus = 'unlinked';
if (!isClosed && account.bank) {
@@ -42,39 +103,69 @@ export function AccountRow({
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',
- }}
+ <AccountHoverCard
+ account={account}
+ isDisabled={isContextMenuOpen || isEditing}
>
- {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>
+ <View innerRef={triggerRef} style={{ flexShrink: 0 }}>
+ <Link
+ variant="internal"
+ to={`/accounts/${account.id}`}
+ isDisabled={isEditing}
+ 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}
+ {isEditing ? (
+ <InitialFocus>
+ <Input
+ aria-label={t('Account name')}
+ style={{ flex: 1, padding: 0, fontSize: 13 }}
+ defaultValue={account.name}
+ onEnter={newAccountName => {
+ if (newAccountName.trim() !== '') {
+ updateAccount.mutate({
+ account: { id: account.id, name: newAccountName },
+ });
+ }
+ setIsEditing(false);
+ }}
+ onEscape={() => setIsEditing(false)}
+ onBlur={() => setIsEditing(false)}
+ />
+ </InitialFocus>
+ ) : (
+ <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>
+ </View>
+ </AccountHoverCard>
);
}
diff --git a/packages/desktop-client/src/util/isTouchDevice.ts b/packages/desktop-client/src/util/isTouchDevice.ts
new file mode 100644
index 0000000000..4d4b395170
--- /dev/null
+++ b/packages/desktop-client/src/util/isTouchDevice.ts
@@ -0,0 +1,6 @@
+export function isTouchDevice(): boolean {
+ return (
+ window.matchMedia('(hover: none)').matches ||
+ window.matchMedia('(pointer: coarse)').matches
+ );
+}
diff --git a/upcoming-release-notes/add-new-sidebar-interactions.md b/upcoming-release-notes/add-new-sidebar-interactions.md
new file mode 100644
index 0000000000..79bc29fb39
--- /dev/null
+++ b/upcoming-release-notes/add-new-sidebar-interactions.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [matt-fidd]
+---
+
+Add context menus and a balance history hover tooltip to accounts and groups in the experimental new sidebar