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

Conversation

UnderKoen
Copy link
Member

@UnderKoen UnderKoen commented Sep 6, 2024

Currently only on budget page and transactions

Still todo

  • Schedules
  • Payees
  • Rules

@actual-github-bot actual-github-bot bot changed the title Add context menu's [WIP] Add context menu's Sep 6, 2024
Copy link

netlify bot commented Sep 6, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit a0502ef
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/672778b7ecaf1c0008d8e031
😎 Deploy Preview https://deploy-preview-3381.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

…_menu

# Conflicts:
#	packages/desktop-client/src/components/transactions/TransactionsTable.jsx
Copy link
Contributor

github-actions bot commented Sep 6, 2024

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
9 5.32 MB → 5.33 MB (+13.93 kB) +0.26%
Changeset
File Δ Size
src/components/transactions/TransactionMenu.tsx 🆕 +2.69 kB 0 B → 2.69 kB
src/components/common/Popover.tsx 📈 +528 B (+97.96%) 539 B → 1.04 kB
src/components/payees/PayeeTableRow.tsx 📈 +2.08 kB (+51.46%) 4.04 kB → 6.12 kB
src/components/rules/RuleRow.tsx 📈 +1.72 kB (+33.51%) 5.13 kB → 6.86 kB
src/components/budget/envelope/budgetsummary/ToBudget.tsx 📈 +623 B (+22.90%) 2.66 kB → 3.26 kB
src/components/budget/envelope/BalanceMovementMenu.tsx 📈 +173 B (+12.06%) 1.4 kB → 1.57 kB
src/components/schedules/SchedulesTable.tsx 📈 +962 B (+8.67%) 10.84 kB → 11.78 kB
src/components/rules/RulesList.tsx 📈 +36 B (+7.21%) 499 B → 535 B
src/components/settings/Experimental.tsx 📈 +303 B (+6.49%) 4.56 kB → 4.85 kB
src/hooks/useFeatureFlag.ts 📈 +23 B (+6.44%) 357 B → 380 B
src/components/transactions/TransactionList.jsx 📈 +306 B (+6.20%) 4.82 kB → 5.12 kB
src/components/budget/SidebarCategory.tsx 📈 +232 B (+4.58%) 4.95 kB → 5.18 kB
src/components/transactions/TransactionsTable.jsx 📈 +2.81 kB (+4.42%) 63.53 kB → 66.33 kB
src/components/budget/SidebarGroup.tsx 📈 +232 B (+4.02%) 5.63 kB → 5.86 kB
src/components/budget/envelope/EnvelopeBudgetComponents.tsx 📈 +482 B (+3.34%) 14.09 kB → 14.56 kB
src/components/ManageRules.tsx 📈 +206 B (+2.42%) 8.33 kB → 8.53 kB
src/components/payees/PayeeTable.tsx 📈 +30 B (+2.05%) 1.43 kB → 1.46 kB
src/components/budget/envelope/budgetsummary/ToBudgetAmount.tsx 📈 +44 B (+1.97%) 2.19 kB → 2.23 kB
src/components/payees/ManagePayees.tsx 📈 +138 B (+1.82%) 7.41 kB → 7.54 kB
src/components/accounts/Account.tsx 📈 +425 B (+0.95%) 43.91 kB → 44.32 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/index.js 3.33 MB → 3.34 MB (+7.27 kB) +0.21%
static/js/wide.js 232.16 kB → 238.83 kB (+6.66 kB) +2.87%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/resize-observer.js 18.37 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/narrow.js 82.57 kB 0%
static/js/usePreviewTransactions.js 1.64 kB 0%
static/js/AppliedFilters.js 21.3 kB 0%
static/js/ReportRouter.js 1.5 MB 0%

Copy link
Contributor

github-actions bot commented Sep 6, 2024

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.27 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
kcab.worker.js 1.27 MB 0%

@Teprifer
Copy link

Teprifer commented Sep 6, 2024

Had a sneak peak, Chrome on w11:

Transaction table: the right click menu isn't dismissed on left click, so it's possible to right click and bring up a menu, left click to try dismiss(doesn't), then right click again and get two multiple menus:

image
Can also reproduce if the second click is a right click outside the transaction table.

Budget table:
Right clicking on one category prevents right clicking on another until the menu is dismissed. Although left click does dismiss it here.

@UnderKoen UnderKoen changed the title [WIP] Add context menu's Add context menu's Sep 8, 2024
@jfdoming
Copy link
Contributor

jfdoming commented Sep 8, 2024

This is really cool! Quick observation: I noticed that the positioning of the menu is not quite under the cursor—for transactions, rules, and payees, it's a few pixels below it, and for schedules, it seems to always be at the bottom of the entry. I think folks are more likely used to context menus appearing directly at the cursor. Would it be possible to make it behave that way instead?

@UnderKoen
Copy link
Member Author

@jfdoming I changed the positioning on the context menu. I didn't do this on the budget page because it didn't really work.

@youngcw
Copy link
Member

youngcw commented Sep 10, 2024

Is it worth having context menus in the budget table? They were already viewable with a regular click.

I think it would be worthwile to have the budget table bulk edit options available in the context menu when multiple transactions are selected

@UnderKoen
Copy link
Member Author

Is it worth having context menus in the budget table?

My intuition is to right click to see the option. I constantly right click when wanting to do these actions.

next steps didn't work
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
packages/desktop-client/src/components/budget/envelope/budgetsummary/ToBudget.tsx (1)

19-19: Reorder imports according to conventions.

The useFeatureFlag import should be grouped with other hook imports from the application.

Apply this diff to fix the import ordering:

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';
import { useEnvelopeSheetValue } from '../EnvelopeBudgetComponents';
import { HoldMenu } from '../HoldMenu';
import { TransferMenu } from '../TransferMenu';

import { ToBudgetAmount } from './ToBudgetAmount';
import { ToBudgetMenu } from './ToBudgetMenu';
- import { useFeatureFlag } from '../../../../hooks/useFeatureFlag';
🧰 Tools
🪛 GitHub Check: lint

[warning] 19-19:
../../../../hooks/useFeatureFlag import should occur before import of ../../../common/Popover

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bcf1bea and d80c069.

📒 Files selected for processing (2)
  • packages/desktop-client/src/components/budget/envelope/budgetsummary/ToBudget.tsx (6 hunks)
  • packages/desktop-client/src/components/budget/envelope/budgetsummary/ToBudgetAmount.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/desktop-client/src/components/budget/envelope/budgetsummary/ToBudgetAmount.tsx
🧰 Additional context used
🪛 GitHub Check: lint
packages/desktop-client/src/components/budget/envelope/budgetsummary/ToBudget.tsx

[warning] 19-19:
../../../../hooks/useFeatureFlag import should occur before import of ../../../common/Popover


[warning] 46-46:
React Hook useCallback has an unnecessary dependency: 'triggerRef'. Either exclude it or remove the dependency array

🔇 Additional comments (2)
packages/desktop-client/src/components/budget/envelope/budgetsummary/ToBudget.tsx (2)

59-59: LGTM! Good use of feature flag.

The feature flag integration is well-implemented, allowing for controlled rollout of the context menu functionality.


70-74: LGTM! Well-structured context menu handler.

The context menu handler is properly implemented with:

  • Feature flag check
  • Prevention of default behavior
  • Clear action handling

@UnderKoen
Copy link
Member Author

Fixxed after approval:

  • The button to budget wasn't opening secondary menu's. Now it does

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
packages/desktop-client/src/components/payees/PayeeTableRow.tsx (1)

149-192: LGTM: Well-structured menu implementation with proper error handling

The menu implementation correctly handles conditional items and follows the codebase standards for null checks and error handling.

Consider adding keyboard accessibility support for the context menu. This could include:

  • Handling the 'Menu' or 'Applications' key press
  • Adding role="menu" and aria-label
  • Supporting Escape key to close the menu

Example implementation:

 <Row
   ref={triggerRef}
+  onKeyDown={e => {
+    if (!contextMenusEnabled) return;
+    if (e.key === 'Menu' || (e.key === 'F10' && e.shiftKey)) {
+      e.preventDefault();
+      setMenuOpen(true);
+      const rect = triggerRef.current.getBoundingClientRect();
+      setCrossOffset(rect.width / 2);
+      setOffset(0);
+    }
+  }}
   // ... existing props
 >
   <Popover
     // ... existing props
+    role="menu"
+    aria-label={t('Payee actions')}
   >
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 16367fb and 7d1146c.

📒 Files selected for processing (2)
  • packages/desktop-client/src/components/payees/PayeeTable.tsx (1 hunks)
  • packages/desktop-client/src/components/payees/PayeeTableRow.tsx (4 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/desktop-client/src/components/payees/PayeeTableRow.tsx (10)
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:158-168
Timestamp: 2024-10-08T15:46:15.739Z
Learning: In this codebase, it's acceptable to use `&&` to conditionally include items in arrays, even if it may result in falsey values. The `Menu` component handles falsey values appropriately.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:158-168
Timestamp: 2024-09-24T20:35:56.009Z
Learning: In this codebase, it's acceptable to use `&&` to conditionally include items in arrays, even if it may result in falsey values. The `Menu` component handles falsey values appropriately.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:143-143
Timestamp: 2024-09-24T20:35:06.300Z
Learning: In the `PayeeTableRow` component, the vertical offset for menu positioning is correctly calculated using `setOffset(e.clientY - rect.bottom);` due to the menu alignment.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:143-143
Timestamp: 2024-10-08T15:46:15.739Z
Learning: In the `PayeeTableRow` component, the vertical offset for menu positioning is correctly calculated using `setOffset(e.clientY - rect.bottom);` due to the menu alignment.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:184-185
Timestamp: 2024-09-24T20:32:31.244Z
Learning: In this codebase, throwing errors in the default case of switch statements within UI event handlers is the standard practice.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:184-185
Timestamp: 2024-10-08T15:46:15.739Z
Learning: In this codebase, throwing errors in the default case of switch statements within UI event handlers is the standard practice.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:175-175
Timestamp: 2024-09-24T20:31:48.061Z
Learning: The `favorite` field expects integer values `1` or `0`, not boolean `true` or `false`.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:175-175
Timestamp: 2024-10-08T15:46:15.739Z
Learning: The `favorite` field expects integer values `1` or `0`, not boolean `true` or `false`.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:158-159
Timestamp: 2024-09-24T20:31:09.185Z
Learning: When checking with `null`, prefer using `==` instead of `===` to match both `null` and `undefined`, since TypeScript checking is not as strict in this project.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:158-159
Timestamp: 2024-10-08T15:46:15.739Z
Learning: When checking with `null`, prefer using `==` instead of `===` to match both `null` and `undefined`, since TypeScript checking is not as strict in this project.
🪛 GitHub Check: typecheck
packages/desktop-client/src/components/payees/PayeeTable.tsx

[failure] 67-67:
Identifier expected.


[failure] 88-88:
Unexpected token. Did you mean {'>'} or &gt;?

🪛 Biome
packages/desktop-client/src/components/payees/PayeeTable.tsx

[error] 67-67: Expected a JSX attribute but instead found '='.

Expected a JSX attribute here.

(parse)


[error] 67-67: expected ... but instead found tableNavigator

Remove tableNavigator

(parse)

🔇 Additional comments (5)
packages/desktop-client/src/components/payees/PayeeTable.tsx (2)

28-28: LGTM: Clean type definition update

The addition of onDelete to the PayeeTableProps type is well-structured and maintains type safety through the use of Pick utility type.


72-85: Verify context menu implementation in PayeeTableRow

Since this PR implements context menus, we should verify that PayeeTableRow properly handles menu positioning and dismissal, as these were mentioned as issues in the PR comments.

✅ Verification successful

Based on the shell script results, I can see that PayeeTableRow.tsx properly implements context menu functionality using Popover and Menu components. The implementation includes:

  1. Context menu trigger via right-click with proper positioning calculation (lines 140-147)
  2. Popover component with proper placement and positioning props (lines 149-158)
  3. Menu component with appropriate items and handlers (lines 159-191)
  4. Non-modal behavior to allow proper dismissal (line 157)

Let me verify the imports to ensure the components are properly imported.


Context menu implementation is properly handled

The PayeeTableRow component correctly implements context menu functionality with:

  • Proper imports of Menu and Popover components
  • Accurate positioning using client coordinates
  • Non-modal behavior for proper dismissal
  • Feature flag control for context menu enablement
  • Comprehensive menu items with appropriate handlers
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for context menu implementation in PayeeTableRow
ast-grep --pattern 'const PayeeTableRow = $_' -A 20

# Look for Popover or Menu component usage
rg -l "import.*(?:Popover|Menu)" packages/desktop-client/src/components/payees/PayeeTableRow.tsx

Length of output: 31703


Script:

#!/bin/bash
# Check imports in PayeeTableRow.tsx
rg -A 5 "^import.*(?:Popover|Menu)" packages/desktop-client/src/components/payees/PayeeTableRow.tsx

Length of output: 269

packages/desktop-client/src/components/payees/PayeeTableRow.tsx (3)

Line range hint 2-82: LGTM: Clean imports and well-typed props

The new imports are properly organized, and the onDelete prop is correctly typed with PayeeEntity['id'].


113-118: LGTM: Clean state management with feature flag integration

The state management for the context menu is well-structured, and the feature flag integration aligns with the PR objectives for controlled rollout of context menus.


140-147: LGTM: Well-implemented context menu handler

The context menu handler is properly guarded by the feature flag and uses correct positioning calculations.

…_menu

# Conflicts:
#	packages/desktop-client/src/components/payees/PayeeTable.tsx
@UnderKoen UnderKoen force-pushed the enhancement/context_menu branch from 7d1146c to a0502ef Compare November 3, 2024 13:20
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
packages/desktop-client/src/components/payees/PayeeTableRow.tsx (1)

149-171: Consider adding keyboard navigation support.

While the context menu implementation is solid, consider enhancing accessibility by adding keyboard navigation support (e.g., using arrow keys to navigate menu items).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7d1146c and a0502ef.

📒 Files selected for processing (2)
  • packages/desktop-client/src/components/payees/PayeeTable.tsx (1 hunks)
  • packages/desktop-client/src/components/payees/PayeeTableRow.tsx (4 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/desktop-client/src/components/payees/PayeeTableRow.tsx (10)
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:158-168
Timestamp: 2024-10-08T15:46:15.739Z
Learning: In this codebase, it's acceptable to use `&&` to conditionally include items in arrays, even if it may result in falsey values. The `Menu` component handles falsey values appropriately.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:158-168
Timestamp: 2024-09-24T20:35:56.009Z
Learning: In this codebase, it's acceptable to use `&&` to conditionally include items in arrays, even if it may result in falsey values. The `Menu` component handles falsey values appropriately.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:143-143
Timestamp: 2024-09-24T20:35:06.300Z
Learning: In the `PayeeTableRow` component, the vertical offset for menu positioning is correctly calculated using `setOffset(e.clientY - rect.bottom);` due to the menu alignment.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:143-143
Timestamp: 2024-10-08T15:46:15.739Z
Learning: In the `PayeeTableRow` component, the vertical offset for menu positioning is correctly calculated using `setOffset(e.clientY - rect.bottom);` due to the menu alignment.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:184-185
Timestamp: 2024-09-24T20:32:31.244Z
Learning: In this codebase, throwing errors in the default case of switch statements within UI event handlers is the standard practice.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:184-185
Timestamp: 2024-10-08T15:46:15.739Z
Learning: In this codebase, throwing errors in the default case of switch statements within UI event handlers is the standard practice.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:175-175
Timestamp: 2024-09-24T20:31:48.061Z
Learning: The `favorite` field expects integer values `1` or `0`, not boolean `true` or `false`.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:175-175
Timestamp: 2024-10-08T15:46:15.739Z
Learning: The `favorite` field expects integer values `1` or `0`, not boolean `true` or `false`.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:158-159
Timestamp: 2024-09-24T20:31:09.185Z
Learning: When checking with `null`, prefer using `==` instead of `===` to match both `null` and `undefined`, since TypeScript checking is not as strict in this project.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/payees/PayeeTableRow.tsx:158-159
Timestamp: 2024-10-08T15:46:15.739Z
Learning: When checking with `null`, prefer using `==` instead of `===` to match both `null` and `undefined`, since TypeScript checking is not as strict in this project.
🔇 Additional comments (8)
packages/desktop-client/src/components/payees/PayeeTable.tsx (4)

28-28: LGTM: Type definition is well-structured.

The addition of 'onDelete' to PayeeTableProps is properly typed and aligns with the component's enhanced functionality.


34-38: LGTM: Clean props destructuring.

The component implementation properly handles the new onDelete prop while maintaining good code organization.


42-47: Reiterating previous feedback about ref type checking.


67-80: Verify context menu positioning behavior.

Based on the PR comments, there are concerns about context menu positioning. While the props are correctly passed, we should verify the positioning behavior in PayeeTableRow.

packages/desktop-client/src/components/payees/PayeeTableRow.tsx (4)

2-2: LGTM: Type definitions and imports are well-structured.

The new imports and type definitions are properly organized and typed, maintaining type safety with PayeeEntity.

Also applies to: 11-12, 82-82


113-117: LGTM: Context menu state management is well-implemented.

The state management for the context menu follows React best practices using appropriate hooks and refs.


140-147: LGTM: Context menu event handling is properly implemented.

The event handler correctly prevents default behavior and calculates menu positioning.


172-190: Consider handling concurrent menu actions.

The menu action handling could potentially face race conditions if multiple actions are triggered in quick succession. Consider adding a loading state or disabling the menu while an action is in progress.

@cordlord
Copy link

cordlord commented Dec 9, 2024

Sorry if I missed it or this isn't the right place, but has anyone had success using this on Firefox?

All I get is the default context menu.

@UnderKoen
Copy link
Member Author

@cordlord this is currently behind a feature flag, you can enable this in the settings under experimental

@cordlord
Copy link

cordlord commented Dec 9, 2024

@UnderKoen Bingo. Didn't even think to check here first. My bad. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants