Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Sidebar - Refactor the Budget Name component #3593

Merged
merged 55 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
b4713df
Initial Commit
tlesicka Oct 7, 2024
243db17
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 7, 2024
a0b69fe
Create 3593.md
tlesicka Oct 7, 2024
602ea4e
Fixed Menu Dropdown Arrow shrinks with long budget name
tlesicka Oct 7, 2024
331ffdb
Changes recommended by coderabbitai
tlesicka Oct 7, 2024
a699c00
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 7, 2024
a851814
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 7, 2024
b308aaf
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 8, 2024
27f8e24
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 9, 2024
c09c0b8
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 9, 2024
5760742
Merge remote-tracking branch 'upstream/master' into update-sidebar-ed…
tlesicka Oct 9, 2024
f939cb4
Fixed Lint issue
tlesicka Oct 9, 2024
75894d6
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 10, 2024
f08e61b
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 11, 2024
0f34752
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 11, 2024
19247fe
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 13, 2024
0aa3546
Merge remote-tracking branch 'upstream/master' into update-sidebar-ed…
tlesicka Oct 13, 2024
6312e94
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 13, 2024
358bace
Merge branch 'update-sidebar-edit-budget-name' of https://github.com/…
tlesicka Oct 13, 2024
5a387ab
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 14, 2024
bb9d455
Merge remote-tracking branch 'upstream/master' into update-sidebar-ed…
tlesicka Oct 14, 2024
374d9a9
Merge remote-tracking branch 'upstream/master' into update-sidebar-ed…
tlesicka Oct 15, 2024
0f23974
Remove Help from Menu
tlesicka Oct 15, 2024
920b9ae
Remove menu from budget name and added Actual logo with menu
tlesicka Oct 15, 2024
4e47e6e
Update VRTs
tlesicka Oct 15, 2024
ff853ae
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 15, 2024
ae1466b
Update VRTs
tlesicka Oct 15, 2024
12cf924
Merge branch 'update-sidebar-edit-budget-name' of https://github.com/…
tlesicka Oct 15, 2024
504add7
Fix logo shrinking with long budget name issue
tlesicka Oct 16, 2024
028612c
Update 3593.md
tlesicka Oct 16, 2024
13a95b4
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 17, 2024
0d10aee
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 17, 2024
bb0890e
Merge remote-tracking branch 'upstream/master' into update-sidebar-ed…
tlesicka Oct 20, 2024
60f4826
Merge remote-tracking branch 'upstream/master' into update-sidebar-ed…
tlesicka Oct 22, 2024
6527d6e
Removed Logo and pencil icon
tlesicka Oct 22, 2024
7dc5cb3
Update VRTs
tlesicka Oct 23, 2024
d21d807
Merge remote-tracking branch 'upstream/master' into update-sidebar-ed…
tlesicka Oct 23, 2024
c95431c
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 23, 2024
f2dfc1b
Removed unused classnames from SideBar and BudgetName component
tlesicka Oct 23, 2024
0c2298c
Merge remote-tracking branch 'upstream/master' into update-sidebar-ed…
tlesicka Oct 23, 2024
979485f
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 24, 2024
31a0bd5
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 24, 2024
fd8d440
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 25, 2024
3874904
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 25, 2024
6f89db5
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 26, 2024
ac60e49
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 27, 2024
802fe0e
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 27, 2024
50a7af4
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 28, 2024
d7ffa69
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 29, 2024
10b0226
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Oct 31, 2024
065ccc5
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Nov 4, 2024
4954c05
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Nov 5, 2024
781b75e
Merge branch 'actualbudget:master' into update-sidebar-edit-budget-name
tlesicka Nov 6, 2024
5c1ae42
Merge remote-tracking branch 'upstream/master' into update-sidebar-ed…
tlesicka Nov 7, 2024
21993bb
revert to upstream VRTs
tlesicka Nov 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions packages/desktop-client/src/components/sidebar/BudgetName.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import React, { type ReactNode, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux';

import { closeBudget } from 'loot-core/src/client/actions';
import * as Platform from 'loot-core/src/client/platform';

import { useMetadataPref } from '../../hooks/useMetadataPref';
import { useNavigate } from '../../hooks/useNavigate';
import { SvgExpandArrow } from '../../icons/v0';
import { SvgPencil1 } from '../../icons/v2';
import { theme } from '../../style';
import { Button } from '../common/Button2';
import { InitialFocus } from '../common/InitialFocus';
import { Input } from '../common/Input';
import { Menu } from '../common/Menu';
import { Popover } from '../common/Popover';
import { Text } from '../common/Text';
import { View } from '../common/View';

type BudgetNameProps = {
children?: ReactNode;
};

export function BudgetName({ children }: BudgetNameProps) {
const hasWindowButtons = !Platform.isBrowser && Platform.OS === 'mac';

return (
<View
style={{
paddingTop: 35,
height: 30,
flexDirection: 'row',
alignItems: 'center',
margin: '0 8px 23px 20px',
userSelect: 'none',
transition: 'padding .4s',
...(hasWindowButtons && {
paddingTop: 20,
justifyContent: 'flex-start',
}),
'& .hover-visible': {
opacity: 0,
transition: 'opacity .25s',
},
'&:hover .hover-visible': {
opacity: 1,
},
tlesicka marked this conversation as resolved.
Show resolved Hide resolved
tlesicka marked this conversation as resolved.
Show resolved Hide resolved
tlesicka marked this conversation as resolved.
Show resolved Hide resolved
}}
>
<EditableBudgetName />

<View style={{ flex: 1, flexDirection: 'row' }} />

{children}
</View>
);
}

function EditableBudgetName() {
const { t } = useTranslation();
const dispatch = useDispatch();
const navigate = useNavigate();
const [budgetName, setBudgetNamePref] = useMetadataPref('budgetName');
tlesicka marked this conversation as resolved.
Show resolved Hide resolved
const [editing, setEditing] = useState(false);
const [menuOpen, setMenuOpen] = useState(false);
const triggerRef = useRef(null);
tlesicka marked this conversation as resolved.
Show resolved Hide resolved

function onMenuSelect(type: string) {
setMenuOpen(false);

switch (type) {
case 'settings':
navigate('/settings');
break;
case 'help':
window.open('https://actualbudget.org/docs/', '_blank');
break;
tlesicka marked this conversation as resolved.
Show resolved Hide resolved
case 'close':
dispatch(closeBudget());
break;
default:
}
}

const items = [
{ name: 'settings', text: t('Settings') },
...(Platform.isBrowser ? [{ name: 'help', text: t('Help') }] : []),
tlesicka marked this conversation as resolved.
Show resolved Hide resolved
{ name: 'close', text: t('Close file') },
];

if (editing) {
return (
<InitialFocus>
<Input
style={{
maxWidth: 'calc(100% - 23px)',
fontSize: 16,
fontWeight: 500,
}}
defaultValue={budgetName}
onEnter={async e => {
const inputEl = e.target as HTMLInputElement;
const newBudgetName = inputEl.value;
if (newBudgetName.trim() !== '') {
setBudgetNamePref(newBudgetName);
setEditing(false);
}
}}
tlesicka marked this conversation as resolved.
Show resolved Hide resolved
onBlur={() => setEditing(false)}
/>
</InitialFocus>
);
}

return (
<>
<Button
ref={triggerRef}
variant="bare"
style={{
color: theme.buttonNormalBorder,
fontSize: 16,
fontWeight: 500,
marginLeft: -5,
flex: '0 auto',
}}
onPress={() => setMenuOpen(true)}
>
<Text style={{ whiteSpace: 'nowrap', overflow: 'hidden' }}>
{budgetName || t('A budget has no name')}
</Text>
<SvgExpandArrow width={7} height={7} style={{ marginLeft: 5 }} />
</Button>

<Popover
triggerRef={triggerRef}
placement="bottom start"
isOpen={menuOpen}
onOpenChange={() => setMenuOpen(false)}
>
<Menu onMenuSelect={onMenuSelect} items={items} />
</Popover>

<Button
variant="bare"
aria-label={t('Edit budget name')}
className="hover-visible"
onPress={() => setEditing(true)}
>
<SvgPencil1
style={{
width: 11,
height: 11,
color: theme.pageTextSubdued,
}}
/>
</Button>
</>
);
}
137 changes: 11 additions & 126 deletions packages/desktop-client/src/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,24 @@
import React, { useRef, useState } from 'react';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux';

import { Resizable } from 're-resizable';

import {
closeBudget,
moveAccount,
replaceModal,
} from 'loot-core/src/client/actions';
import { moveAccount, replaceModal } from 'loot-core/src/client/actions';
import * as Platform from 'loot-core/src/client/platform';

import { useAccounts } from '../../hooks/useAccounts';
import { useGlobalPref } from '../../hooks/useGlobalPref';
import { useLocalPref } from '../../hooks/useLocalPref';
import { useMetadataPref } from '../../hooks/useMetadataPref';
import { useNavigate } from '../../hooks/useNavigate';
import { useResizeObserver } from '../../hooks/useResizeObserver';
import { SvgExpandArrow } from '../../icons/v0';
import { SvgReports, SvgWallet } from '../../icons/v1';
import { SvgCalendar } from '../../icons/v2';
import { useResponsive } from '../../ResponsiveProvider';
import { styles, theme } from '../../style';
import { Button } from '../common/Button2';
import { InitialFocus } from '../common/InitialFocus';
import { Input } from '../common/Input';
import { Menu } from '../common/Menu';
import { Popover } from '../common/Popover';
import { Text } from '../common/Text';
import { View } from '../common/View';

import { Accounts } from './Accounts';
import { BudgetName } from './BudgetName';
import { Item } from './Item';
import { useSidebar } from './SidebarProvider';
import { ToggleButton } from './ToggleButton';
Expand Down Expand Up @@ -135,32 +123,21 @@ export function Sidebar() {
opacity: 1,
width: hasWindowButtons ? null : 'auto',
},
'& .hover-visible': {
display: 'none',
},
'&:hover .hover-visible': {
display: 'flex',
},
flex: 1,
...styles.darkScrollbar,
}}
>
<View
style={{
paddingTop: 35,
height: 30,
flexDirection: 'row',
alignItems: 'center',
margin: '0 8px 23px 20px',
transition: 'padding .4s',
...(hasWindowButtons && {
paddingTop: 20,
justifyContent: 'flex-start',
}),
}}
>
<EditableBudgetName />

<View style={{ flex: 1, flexDirection: 'row' }} />

<BudgetName>
{!sidebar.alwaysFloats && (
<ToggleButton isFloating={isFloating} onFloat={onFloat} />
)}
</View>
</BudgetName>

tlesicka marked this conversation as resolved.
Show resolved Hide resolved
<View style={{ overflow: 'auto' }}>
<Item title={t('Budget')} Icon={SvgWallet} to="/budget" />
Expand Down Expand Up @@ -189,95 +166,3 @@ export function Sidebar() {
</Resizable>
);
}

function EditableBudgetName() {
const { t } = useTranslation();
const dispatch = useDispatch();
const navigate = useNavigate();
const [budgetName, setBudgetNamePref] = useMetadataPref('budgetName');
const [editing, setEditing] = useState(false);
const [menuOpen, setMenuOpen] = useState(false);
const triggerRef = useRef(null);

function onMenuSelect(type: string) {
setMenuOpen(false);

switch (type) {
case 'rename':
setEditing(true);
break;
case 'settings':
navigate('/settings');
break;
case 'help':
window.open('https://actualbudget.org/docs/', '_blank');
break;
case 'close':
dispatch(closeBudget());
break;
default:
}
}

const items = [
{ name: 'rename', text: t('Rename budget') },
{ name: 'settings', text: t('Settings') },
...(Platform.isBrowser ? [{ name: 'help', text: t('Help') }] : []),
{ name: 'close', text: t('Close file') },
];

if (editing) {
return (
<InitialFocus>
<Input
style={{
width: 160,
fontSize: 16,
fontWeight: 500,
}}
defaultValue={budgetName}
onEnter={async e => {
const inputEl = e.target as HTMLInputElement;
const newBudgetName = inputEl.value;
if (newBudgetName.trim() !== '') {
setBudgetNamePref(newBudgetName);
setEditing(false);
}
}}
onBlur={() => setEditing(false)}
/>
</InitialFocus>
);
}

return (
<>
<Button
ref={triggerRef}
variant="bare"
style={{
color: theme.buttonNormalBorder,
fontSize: 16,
fontWeight: 500,
marginLeft: -5,
flex: '0 auto',
}}
onPress={() => setMenuOpen(true)}
>
<Text style={{ whiteSpace: 'nowrap', overflow: 'hidden' }}>
{budgetName || t('A budget has no name')}
</Text>
<SvgExpandArrow width={7} height={7} style={{ marginLeft: 5 }} />
</Button>

<Popover
triggerRef={triggerRef}
placement="bottom start"
isOpen={menuOpen}
onOpenChange={() => setMenuOpen(false)}
>
<Menu onMenuSelect={onMenuSelect} items={items} />
</Popover>
</>
);
}
6 changes: 6 additions & 0 deletions upcoming-release-notes/3593.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [tlesicka]
---

Removed "Rename budget" from sidebar menu and replaced with a pencil icon next to the budget name. Budget rename input box is now responsive.
Loading