A local-first personal finance app
sidebar: remove budget header dropdown (#9115)
Matt Fiddamanfdf7f1b8ce71
diff --git a/packages/desktop-client/src/components/sidebar/redesign/SidebarBudgetName.tsx b/packages/desktop-client/src/components/sidebar/redesign/SidebarBudgetName.tsxindex 1cebc8426c..2e9f845d66 100644--- a/packages/desktop-client/src/components/sidebar/redesign/SidebarBudgetName.tsx+++ b/packages/desktop-client/src/components/sidebar/redesign/SidebarBudgetName.tsx@@ -1,99 +1,141 @@-import { useRef, useState } from 'react';import { useTranslation } from 'react-i18next';import { Button } from '@actual-app/components/button';-import { SvgCheveronDown } from '@actual-app/components/icons/v1';+import { SvgTime } 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 { 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 { isElectron } from '@actual-app/core/shared/environment';+import { css, cx } from '@emotion/css';-import { closeBudget } from '#budgetfiles/budgetfilesSlice';-import { useContextMenu } from '#hooks/useContextMenu';import { useMetadataPref } from '#hooks/useMetadataPref';-import { useNavigate } from '#hooks/useNavigate';import { pushModal } from '#modals/modalsSlice';import { useDispatch } from '#redux';-export function SidebarBudgetName() {+type SidebarBudgetNameProps = {+ isEditing: boolean;+ onEditingChange: (isEditing: boolean) => void;+};++export function SidebarBudgetName({+ isEditing,+ onEditingChange,+}: SidebarBudgetNameProps) {const { t } = useTranslation();const [budgetName, setBudgetNamePref] = useMetadataPref('budgetName');const dispatch = useDispatch();- const navigate = useNavigate();- const [isEditing, setIsEditing] = useState(false);- const triggerRef = useRef<HTMLButtonElement>(null);- const { handleContextMenu } = useContextMenu({- triggerRef,- items: [- {- name: 'rename',- text: t('Rename budget'),- onClick: () => setIsEditing(true),- },- {- name: 'settings',- text: t('Settings'),- onClick: () => void navigate('/settings'),- },- isElectron() && {- name: 'loadBackup',- text: t('Load Backup…'),- onClick: () =>- dispatch(pushModal({ modal: { name: 'load-backup', options: {} } })),- },- {- name: 'close',- text: t('Switch file'),- onClick: () => void dispatch(closeBudget()),++ const iconButtonClassName = cx(+ 'hover-visible',+ css({+ backgroundColor: 'transparent',+ '&[data-hovered], &[data-focus-visible]': {+ backgroundColor: theme.sidebarControlBackground,},- ],- });+ }),+ );- if (isEditing) {- return (- <InitialFocus>- <Input- size="medium"- style={{ fontWeight: 600 }}- defaultValue={budgetName}- onEnter={newBudgetName => {- if (newBudgetName.trim() !== '') {- setBudgetNamePref(newBudgetName);- setIsEditing(false);- }- }}- onBlur={() => setIsEditing(false)}- />- </InitialFocus>- );+ function saveBudgetName(newBudgetName: string) {+ if (newBudgetName.trim() !== '' && newBudgetName !== budgetName) {+ setBudgetNamePref(newBudgetName);+ }+ onEditingChange(false);}return (- <Button- ref={triggerRef}- data-testid="budget-name"- variant="bare"- style={{- color: theme.sidebarHeaderText,- backgroundColor: 'transparent',- fontSize: 13,- fontWeight: 600,- gap: spacing.xs,- padding: 0,- justifyContent: 'flex-start',- maxWidth: '100%',- }}- onClick={handleContextMenu}- >- <Text style={styles.ellipsisText}>{budgetName || t('Unnamed')}</Text>- <SvgCheveronDown- width={11}- height={11}- style={{ flexShrink: 0, color: theme.sidebarTextSubdued }}- />- </Button>+ <>+ <View+ style={{+ flexDirection: 'row',+ alignItems: 'center',+ gap: spacing.xs,+ minWidth: 0,+ visibility: isEditing ? 'hidden' : undefined,+ '& .hover-visible': {+ opacity: 0,+ },+ '&:hover .hover-visible, & .hover-visible[data-focus-visible]': {+ opacity: 1,+ },+ }}+ >+ <Text+ data-testid="budget-name"+ style={{+ color: theme.sidebarHeaderText,+ fontSize: 13,+ fontWeight: 600,+ ...styles.ellipsisText,+ }}+ >+ {budgetName || t('Unnamed')}+ </Text>+ <Button+ variant="bare"+ className={iconButtonClassName}+ aria-label={t('Rename budget')}+ style={{ padding: spacing.xxs, flexShrink: 0 }}+ onPress={() => onEditingChange(true)}+ >+ <SvgPencil1+ width={11}+ height={11}+ style={{ color: theme.sidebarTextSubdued }}+ />+ </Button>+ {isElectron() && (+ <Tooltip+ content={t('Load Backup…')}+ placement="bottom start"+ style={styles.tooltip}+ triggerProps={{ delay: 500 }}+ >+ <Button+ variant="bare"+ className={iconButtonClassName}+ aria-label={t('Load Backup…')}+ style={{ padding: spacing.xxs, flexShrink: 0 }}+ onPress={() =>+ dispatch(+ pushModal({ modal: { name: 'load-backup', options: {} } }),+ )+ }+ >+ <SvgTime+ width={11}+ height={11}+ style={{ color: theme.sidebarTextSubdued }}+ />+ </Button>+ </Tooltip>+ )}+ </View>+ {isEditing && (+ <InitialFocus>+ <Input+ aria-label={t('Budget name')}+ size="medium"+ style={{+ position: 'absolute',+ top: '50%',+ left: 0,+ width: '100%',+ transform: 'translateY(-50%)',+ fontWeight: 600,+ }}+ defaultValue={budgetName}+ onEnter={saveBudgetName}+ onUpdate={saveBudgetName}+ onEscape={() => onEditingChange(false)}+ />+ </InitialFocus>+ )}+ </>);}diff --git a/packages/desktop-client/src/components/sidebar/redesign/SidebarHeader.tsx b/packages/desktop-client/src/components/sidebar/redesign/SidebarHeader.tsxindex 3e1e20b6fb..2034f8ab53 100644--- a/packages/desktop-client/src/components/sidebar/redesign/SidebarHeader.tsx+++ b/packages/desktop-client/src/components/sidebar/redesign/SidebarHeader.tsx@@ -1,11 +1,19 @@+import { useState } from 'react';import type { ReactNode } from 'react';+import { useTranslation } from 'react-i18next';+import { Button } from '@actual-app/components/button';import { SvgLogo } from '@actual-app/components/icons/logo';+import { styles } from '@actual-app/components/styles';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 { css } from '@emotion/css';+import { closeBudget } from '#budgetfiles/budgetfilesSlice';import { hasMacOSWindowButtons } from '#components/sidebar/SidebarShell';+import { useDispatch } from '#redux';import { SidebarBudgetName } from './SidebarBudgetName';import { SyncStatusLine } from './SyncStatusLine';@@ -17,6 +25,10 @@ type SidebarHeaderProps = {};export function SidebarHeader({ children }: SidebarHeaderProps) {+ const { t } = useTranslation();+ const dispatch = useDispatch();+ const [isEditingName, setIsEditingName] = useState(false);+return (<Viewstyle={{@@ -32,16 +44,45 @@ export function SidebarHeader({ children }: SidebarHeaderProps) {flexShrink: 0,}}>- <SvgLogo- width={28}- height={28}- style={{ flexShrink: 0, color: theme.sidebarBrand }}- />- <View style={{ minWidth: 0, flex: 1 }}>- <SidebarBudgetName />- <SyncStatusLine />+ <Tooltip+ content={t('Switch file')}+ placement="bottom start"+ style={styles.tooltip}+ triggerProps={{ delay: 500 }}+ >+ <Button+ variant="bare"+ aria-label={t('Switch file')}+ className={css({+ backgroundColor: 'transparent',+ '&[data-hovered], &[data-focus-visible]': {+ backgroundColor: theme.sidebarControlBackground,+ },+ })}+ style={{+ padding: spacing.xs,+ margin: -spacing.xs,+ flexShrink: 0,+ }}+ onPress={() => void dispatch(closeBudget())}+ >+ <SvgLogo+ width={28}+ height={28}+ style={{ color: theme.sidebarBrand }}+ />+ </Button>+ </Tooltip>+ <View style={{ position: 'relative', minWidth: 0, flex: 1 }}>+ <SidebarBudgetName+ isEditing={isEditingName}+ onEditingChange={setIsEditingName}+ />+ <View style={{ visibility: isEditingName ? 'hidden' : undefined }}>+ <SyncStatusLine />+ </View></View>- {children}+ {!isEditingName && children}</View>);}diff --git a/upcoming-release-notes/simplify-new-sidebar-budget-name.md b/upcoming-release-notes/simplify-new-sidebar-budget-name.mdnew file mode 100644index 0000000000..dd8d670f1a--- /dev/null+++ b/upcoming-release-notes/simplify-new-sidebar-budget-name.md@@ -0,0 +1,6 @@+---+category: Enhancements+authors: [matt-fidd]+---++Experimental sidebar: remove the budget name/switch/settings dropdown in the header