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

Add context menu's #3381

Merged
merged 39 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
33c1f7b
feat: context menu on transactions
UnderKoen Sep 6, 2024
9967d3c
feat: context menu's on budget page
UnderKoen Sep 6, 2024
aee1f20
Merge remote-tracking branch 'origin/master' into enhancement/context…
UnderKoen Sep 6, 2024
d61cf4d
chore: release note
UnderKoen Sep 6, 2024
f194a86
fix: losing focus on context menu
UnderKoen Sep 8, 2024
696a6d7
feat: schedules context menu
UnderKoen Sep 8, 2024
453d24d
feat: payees context menu
UnderKoen Sep 8, 2024
82837ff
feat: rules context menu
UnderKoen Sep 8, 2024
c34bee9
chore: update release note
UnderKoen Sep 8, 2024
3025a1f
Merge remote-tracking branch 'origin/master' into enhancement/context…
UnderKoen Sep 8, 2024
d852acb
chore: lint
UnderKoen Sep 8, 2024
f6a388d
fix: broken balance movement menu
UnderKoen Sep 9, 2024
d068e7a
fix: placement on context menu to be closer to cursor
UnderKoen Sep 9, 2024
4660db1
feat: context menu on budget field
UnderKoen Sep 9, 2024
15f0b36
chore: lint
UnderKoen Sep 9, 2024
6b3b12f
Merge branch 'master' into enhancement/context_menu
UnderKoen Sep 9, 2024
80635c1
Merge branch 'master' into enhancement/context_menu
UnderKoen Sep 17, 2024
b9b7856
Merge remote-tracking branch 'origin/master' into enhancement/context…
UnderKoen Sep 24, 2024
5c3adb2
Update packages/desktop-client/src/components/transactions/Transactio…
UnderKoen Sep 24, 2024
e4569c4
Merge branch 'master' into enhancement/context_menu
UnderKoen Sep 24, 2024
d10cc04
Merge branch 'master' into enhancement/context_menu
UnderKoen Oct 3, 2024
12618da
Merge remote-tracking branch 'origin/master' into enhancement/context…
UnderKoen Oct 4, 2024
227988e
chore: fix merge
UnderKoen Oct 4, 2024
28c6856
fix: e2e test
UnderKoen Oct 4, 2024
fdeb84c
Merge remote-tracking branch 'origin/master' into enhancement/context…
UnderKoen Oct 13, 2024
1bb22f5
Merge remote-tracking branch 'fork/enhancement/context_menu' into enh…
UnderKoen Oct 13, 2024
93f2b2a
fix: moving of the popover in the sidebar
UnderKoen Oct 13, 2024
0b05fda
chore: lint
UnderKoen Oct 13, 2024
669df5f
Merge branch 'master' into enhancement/context_menu
UnderKoen Oct 17, 2024
0940f31
Merge branch 'master' into enhancement/context_menu
UnderKoen Oct 21, 2024
cba965d
chore: add feature flag
UnderKoen Oct 21, 2024
ace09d4
chore: fix tsc
UnderKoen Oct 21, 2024
a3492ff
chore: fix test
UnderKoen Oct 21, 2024
a20d927
Update packages/desktop-client/src/components/settings/Experimental.tsx
UnderKoen Oct 28, 2024
bcf1bea
Merge branch 'master' into enhancement/context_menu
UnderKoen Oct 28, 2024
f6d94ea
Merge remote-tracking branch 'origin/master' into enhancement/context…
UnderKoen Oct 30, 2024
d80c069
fix: to budget button
UnderKoen Oct 30, 2024
16367fb
chore: lint
UnderKoen Oct 30, 2024
a0502ef
Merge remote-tracking branch 'origin/master' into enhancement/context…
UnderKoen Nov 3, 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
8 changes: 8 additions & 0 deletions packages/desktop-client/src/components/ManageRules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ export function ManageRules({
setLoading(false);
}

async function onDeleteRule(id: string) {
setLoading(true);
await send('rule-delete', id);
await loadRules();
setLoading(false);
}
UnderKoen marked this conversation as resolved.
Show resolved Hide resolved
UnderKoen marked this conversation as resolved.
Show resolved Hide resolved

const onEditRule = useCallback(rule => {
dispatch(
pushModal('edit-rule', {
Expand Down Expand Up @@ -306,6 +313,7 @@ export function ManageRules({
hoveredRule={hoveredRule}
onHover={onHover}
onEditRule={onEditRule}
onDeleteRule={rule => onDeleteRule(rule.id)}
/>
)}
</SimpleTable>
Expand Down
9 changes: 9 additions & 0 deletions packages/desktop-client/src/components/accounts/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,15 @@ class AccountInternal extends PureComponent<
sortField={this.state.sort?.field}
ascDesc={this.state.sort?.ascDesc}
onChange={this.onTransactionsChange}
onBatchDelete={this.onBatchDelete}
Copy link
Contributor

@joel-jeremy joel-jeremy Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a useTransactionBatchActions hook. Maybe we can use that instead of passing props?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried it. But unfortunatly the table doesn't update quite right. When you duplicate an transaction you need te reload the page to see the change.

onBatchDuplicate={this.onBatchDuplicate}
onBatchLinkSchedule={this.onBatchLinkSchedule}
onBatchUnlinkSchedule={this.onBatchUnlinkSchedule}
onCreateRule={this.onCreateRule}
onScheduleAction={this.onScheduleAction}
onMakeAsNonSplitTransactions={
this.onMakeAsNonSplitTransactions
}
UnderKoen marked this conversation as resolved.
Show resolved Hide resolved
onRefetch={this.refetchTransactions}
onCloseAddTransaction={() =>
this.setState({ isAdding: false })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type CategoryEntity,
} from 'loot-core/src/types/models';

import { useFeatureFlag } from '../../hooks/useFeatureFlag';
import { SvgCheveronDown } from '../../icons/v1';
import { theme } from '../../style';
import { Button } from '../common/Button2';
Expand Down Expand Up @@ -51,6 +52,7 @@ export function SidebarCategory({
const temporary = category.id === 'new';
const [menuOpen, setMenuOpen] = useState(false);
const triggerRef = useRef(null);
const contextMenusEnabled = useFeatureFlag('contextMenus');

const displayed = (
<View
Expand All @@ -61,6 +63,13 @@ export function SidebarCategory({
WebkitUserSelect: 'none',
opacity: category.hidden || categoryGroup?.hidden ? 0.33 : undefined,
backgroundColor: 'transparent',
height: 20,
}}
ref={triggerRef}
onContextMenu={e => {
if (!contextMenusEnabled) return;
e.preventDefault();
setMenuOpen(true);
}}
>
<div
Expand All @@ -74,7 +83,7 @@ export function SidebarCategory({
>
{category.name}
</div>
<View style={{ flexShrink: 0, marginLeft: 5 }} ref={triggerRef}>
<View style={{ flexShrink: 0, marginLeft: 5 }}>
<Button
variant="bare"
className="hover-visible"
Expand All @@ -94,6 +103,7 @@ export function SidebarCategory({
isOpen={menuOpen}
onOpenChange={() => setMenuOpen(false)}
style={{ width: 200 }}
isNonModal
>
<Menu
onMenuSelect={type => {
Expand Down
12 changes: 11 additions & 1 deletion packages/desktop-client/src/components/budget/SidebarGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { type CSSProperties, useRef, useState } from 'react';
import { type ConnectDragSource } from 'react-dnd';
import { useTranslation } from 'react-i18next';

import { useFeatureFlag } from '../../hooks/useFeatureFlag';
import { SvgExpandArrow } from '../../icons/v0';
import { SvgCheveronDown } from '../../icons/v1';
import { theme } from '../../style';
Expand Down Expand Up @@ -56,6 +57,7 @@ export function SidebarGroup({
const temporary = group.id === 'new';
const [menuOpen, setMenuOpen] = useState(false);
const triggerRef = useRef(null);
const contextMenusEnabled = useFeatureFlag('contextMenus');

const displayed = (
<View
Expand All @@ -64,10 +66,17 @@ export function SidebarGroup({
alignItems: 'center',
userSelect: 'none',
WebkitUserSelect: 'none',
height: 20,
}}
ref={triggerRef}
onClick={() => {
onToggleCollapse(group.id);
}}
onContextMenu={e => {
if (!contextMenusEnabled) return;
e.preventDefault();
setMenuOpen(true);
}}
>
{!dragPreview && (
<SvgExpandArrow
Expand Down Expand Up @@ -95,7 +104,7 @@ export function SidebarGroup({
</div>
{!dragPreview && (
<>
<View style={{ marginLeft: 5, flexShrink: 0 }} ref={triggerRef}>
<View style={{ marginLeft: 5, flexShrink: 0 }}>
<Button
variant="bare"
className="hover-visible"
Expand All @@ -111,6 +120,7 @@ export function SidebarGroup({
isOpen={menuOpen}
onOpenChange={() => setMenuOpen(false)}
style={{ width: 200 }}
isNonModal
>
<Menu
onMenuSelect={type => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useCallback, useRef, useState } from 'react';

import { envelopeBudget } from 'loot-core/src/client/queries';

Expand All @@ -23,10 +23,20 @@ export function BalanceMovementMenu({
const catBalance = useEnvelopeSheetValue(
envelopeBudget.catBalance(categoryId),
);
const [menu, setMenu] = useState('menu');
const [menu, _setMenu] = useState('menu');

const ref = useRef<HTMLSpanElement>(null);
// Keep focus inside the popover on menu change
const setMenu = useCallback(
(menu: string) => {
ref.current?.focus();
_setMenu(menu);
},
[ref],
);

return (
<>
<span tabIndex={-1} ref={ref}>
{menu === 'menu' && (
<BalanceMenu
categoryId={categoryId}
Expand Down Expand Up @@ -70,6 +80,6 @@ export function BalanceMovementMenu({
}}
/>
)}
</>
</span>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { evalArithmetic } from 'loot-core/src/shared/arithmetic';
import * as monthUtils from 'loot-core/src/shared/months';
import { integerToCurrency, amountToInteger } from 'loot-core/src/shared/util';

import { useFeatureFlag } from '../../../hooks/useFeatureFlag';
import { useUndo } from '../../../hooks/useUndo';
import { SvgCheveronDown } from '../../../icons/v1';
import { styles, theme } from '../../../style';
Expand Down Expand Up @@ -215,6 +216,7 @@ export const ExpenseCategoryMonth = memo(function ExpenseCategoryMonth({
};

const { showUndoNotification } = useUndo();
const contextMenusEnabled = useFeatureFlag('contextMenus');

return (
<View
Expand All @@ -238,6 +240,12 @@ export const ExpenseCategoryMonth = memo(function ExpenseCategoryMonth({
flex: 1,
flexDirection: 'row',
}}
onContextMenu={e => {
if (!contextMenusEnabled) return;
if (editing) return;
e.preventDefault();
setBudgetMenuOpen(true);
}}
>
{!editing && (
<View
Expand Down Expand Up @@ -274,6 +282,7 @@ export const ExpenseCategoryMonth = memo(function ExpenseCategoryMonth({
isOpen={budgetMenuOpen}
onOpenChange={() => setBudgetMenuOpen(false)}
style={{ width: 200 }}
isNonModal
UnderKoen marked this conversation as resolved.
Show resolved Hide resolved
UnderKoen marked this conversation as resolved.
Show resolved Hide resolved
>
<BudgetMenu
onCopyLastMonthAverage={() => {
Expand Down Expand Up @@ -390,6 +399,11 @@ export const ExpenseCategoryMonth = memo(function ExpenseCategoryMonth({
<span
ref={balanceMenuTriggerRef}
onClick={() => setBalanceMenuOpen(true)}
onContextMenu={e => {
if (!contextMenusEnabled) return;
e.preventDefault();
setBalanceMenuOpen(true);
}}
>
<BalanceWithCarryover
carryover={envelopeBudget.catCarryover(category.id)}
Expand All @@ -406,6 +420,7 @@ export const ExpenseCategoryMonth = memo(function ExpenseCategoryMonth({
isOpen={balanceMenuOpen}
onOpenChange={() => setBalanceMenuOpen(false)}
style={{ width: 200 }}
isNonModal
>
<BalanceMovementMenu
categoryId={category.id}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import React, { useRef, useState, type CSSProperties } from 'react';
import React, {
useRef,
useState,
type CSSProperties,
useCallback,
} from 'react';

import { envelopeBudget } from 'loot-core/src/client/queries';

import { useFeatureFlag } from '../../../../hooks/useFeatureFlag';
import { Popover } from '../../../common/Popover';
import { View } from '../../../common/View';
import { CoverMenu } from '../CoverMenu';
Expand All @@ -28,8 +34,17 @@ export function ToBudget({
amountStyle,
isCollapsed = false,
}: ToBudgetProps) {
const [menuOpen, setMenuOpen] = useState<string | null>(null);
const [menuOpen, _setMenuOpen] = useState<string | null>(null);
const triggerRef = useRef(null);

const ref = useRef<HTMLSpanElement>(null);
const setMenuOpen = useCallback(
(menu: string | null) => {
if (menu) ref.current?.focus();
_setMenuOpen(menu);
},
[ref],
);
const sheetValue = useEnvelopeSheetValue({
name: envelopeBudget.toBudget,
value: 0,
Expand All @@ -41,6 +56,7 @@ export function ToBudget({
);
}
const isMenuOpen = Boolean(menuOpen);
const contextMenusEnabled = useFeatureFlag('contextMenus');

return (
<>
Expand All @@ -51,6 +67,11 @@ export function ToBudget({
style={style}
amountStyle={amountStyle}
isTotalsListTooltipDisabled={!isCollapsed || isMenuOpen}
onContextMenu={e => {
if (!contextMenusEnabled) return;
e.preventDefault();
setMenuOpen('actions');
}}
/>
</View>

Expand All @@ -60,49 +81,52 @@ export function ToBudget({
isOpen={isMenuOpen}
onOpenChange={() => setMenuOpen(null)}
style={{ width: 200 }}
isNonModal
>
{menuOpen === 'actions' && (
<ToBudgetMenu
onTransfer={() => setMenuOpen('transfer')}
onCover={() => setMenuOpen('cover')}
onHoldBuffer={() => setMenuOpen('buffer')}
onResetHoldBuffer={() => {
onBudgetAction(month, 'reset-hold');
setMenuOpen(null);
}}
/>
)}
{menuOpen === 'buffer' && (
<HoldMenu
onClose={() => setMenuOpen(null)}
onSubmit={amount => {
onBudgetAction(month, 'hold', { amount });
}}
/>
)}
{menuOpen === 'transfer' && (
<TransferMenu
initialAmount={availableValue ?? undefined}
onClose={() => setMenuOpen(null)}
onSubmit={(amount, categoryId) => {
onBudgetAction(month, 'transfer-available', {
amount,
category: categoryId,
});
}}
/>
)}
{menuOpen === 'cover' && (
<CoverMenu
showToBeBudgeted={false}
onClose={() => setMenuOpen(null)}
onSubmit={categoryId => {
onBudgetAction(month, 'cover-overbudgeted', {
category: categoryId,
});
}}
/>
)}
<span tabIndex={-1} ref={ref}>
{menuOpen === 'actions' && (
<ToBudgetMenu
onTransfer={() => setMenuOpen('transfer')}
onCover={() => setMenuOpen('cover')}
onHoldBuffer={() => setMenuOpen('buffer')}
onResetHoldBuffer={() => {
onBudgetAction(month, 'reset-hold');
setMenuOpen(null);
}}
/>
)}
{menuOpen === 'buffer' && (
<HoldMenu
onClose={() => setMenuOpen(null)}
onSubmit={amount => {
onBudgetAction(month, 'hold', { amount });
}}
/>
)}
{menuOpen === 'transfer' && (
<TransferMenu
initialAmount={availableValue ?? undefined}
onClose={() => setMenuOpen(null)}
onSubmit={(amount, categoryId) => {
onBudgetAction(month, 'transfer-available', {
amount,
category: categoryId,
});
}}
/>
)}
{menuOpen === 'cover' && (
<CoverMenu
showToBeBudgeted={false}
onClose={() => setMenuOpen(null)}
onSubmit={categoryId => {
onBudgetAction(month, 'cover-overbudgeted', {
category: categoryId,
});
}}
/>
)}
</span>
UnderKoen marked this conversation as resolved.
Show resolved Hide resolved
</Popover>
</>
);
Expand Down
Loading