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 the budget page to be printable #3780

Closed

Conversation

jfdoming
Copy link
Contributor

@jfdoming jfdoming commented Nov 4, 2024

I've seen this request a few times and got curious what it'd take. Originally I tried the Reports page which seems more difficult, but the Budget page seems doable. Feedback welcome! I've only tested this in Chrome—would appreciate help testing in other browsers.

Suggested testing steps:

  1. Add a bunch of categories to the budget.
  2. Hit Ctrl-P to print the page and see what it looks like on various configurations.

@actual-github-bot actual-github-bot bot changed the title Update the budget page to be printable [WIP] Update the budget page to be printable Nov 4, 2024
Copy link

netlify bot commented Nov 4, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 10899c5
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/67285c81637907000884edbd
😎 Deploy Preview https://deploy-preview-3780.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.

@jfdoming jfdoming force-pushed the jfdoming/printable-budget-page branch from e2b93c1 to 1bfd0c5 Compare November 4, 2024 05:22
Copy link
Contributor

github-actions bot commented Nov 4, 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
10 5.34 MB → 5.34 MB (+3.42 kB) +0.06%
Changeset
File Δ Size
src/hooks/useSpaceMeasure.tsx 🆕 +777 B 0 B → 777 B
node_modules/es-define-property/index.js 📈 +210 B (+60.00%) 350 B → 560 B
src/components/budget/DynamicBudgetTable.tsx 📈 +571 B (+19.37%) 2.88 kB → 3.44 kB
node_modules/usehooks-ts/dist/index.js 📈 +1010 B (+18.31%) 5.39 kB → 6.37 kB
src/components/budget/BudgetSummaries.tsx 📈 +315 B (+13.70%) 2.25 kB → 2.55 kB
src/components/App.tsx 📈 +121 B (+2.16%) 5.48 kB → 5.59 kB
src/components/FinancesApp.tsx 📈 +182 B (+1.76%) 10.1 kB → 10.28 kB
node_modules/has-property-descriptors/index.js 📈 +9 B (+1.57%) 573 B → 582 B
src/components/sidebar/Sidebar.tsx 📈 +87 B (+1.41%) 6.04 kB → 6.13 kB
src/components/budget/BudgetTable.jsx 📈 +86 B (+1.40%) 6.01 kB → 6.09 kB
node_modules/call-bind/index.js 📈 +9 B (+0.85%) 1.04 kB → 1.05 kB
src/components/Titlebar.tsx 📈 +57 B (+0.70%) 8.01 kB → 8.06 kB
src/components/budget/index.tsx 📈 +61 B (+0.68%) 8.8 kB → 8.86 kB
node_modules/define-data-property/index.js 📈 +9 B (+0.39%) 2.24 kB → 2.25 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/wide.js 238.83 kB → 240.59 kB (+1.77 kB) +0.74%
static/js/index.js 3.34 MB → 3.35 MB (+1.65 kB) +0.05%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/workbox-window.prod.es5.js 5.69 kB 0%
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/AppliedFilters.js 21.3 kB 0%
static/js/usePreviewTransactions.js 1.64 kB 0%
static/js/narrow.js 82.57 kB 0%
static/js/ReportRouter.js 1.5 MB 0%

Copy link
Contributor

github-actions bot commented Nov 4, 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%

@jfdoming jfdoming changed the title [WIP] Update the budget page to be printable Update the budget page to be printable Nov 4, 2024
Copy link
Contributor

coderabbitai bot commented Nov 4, 2024

Walkthrough

The pull request introduces several changes across multiple components in the desktop client, primarily focusing on enhancing print styles. A new CSS media query for print is added to the index.html, App.tsx, FinancesApp.tsx, Titlebar.tsx, BudgetSummaries.tsx, BudgetTable.jsx, DynamicBudgetTable.tsx, and Sidebar.tsx. These changes modify properties such as overflow and display to ensure that content is fully visible when printed. Additionally, new hooks are introduced in BudgetSummaries.tsx and DynamicBudgetTable.tsx for improved responsiveness and layout management during printing. The useSpaceMeasure custom hook is created to dynamically measure space in components. Overall, the modifications enhance the print handling capabilities of the application without altering the core functionality or structure of the components.

Possibly related PRs

Suggested labels

:sparkles: Merged

Suggested reviewers

  • MikesGlitch

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 1

🧹 Outside diff range and nitpick comments (6)
packages/desktop-client/src/hooks/useSpaceMeasure.tsx (2)

9-28: Consider adding z-index and pointer-events to prevent interference.

The absolutely positioned measuring elements might interfere with click events on other elements. Consider adding CSS properties to prevent this.

         style={{
           width: '100%',
           height: 0,
           position: 'absolute',
+          zIndex: -1,
+          pointerEvents: 'none',
         }}

5-35: Consider documenting the hook's usage patterns.

This hook is well-designed and could be useful beyond just print layouts. Consider adding JSDoc comments to document:

  1. The hook's purpose and use cases
  2. Requirements for parent container positioning
  3. Example usage patterns
packages/desktop-client/src/components/budget/BudgetSummaries.tsx (1)

50-51: Consider preventing layout shifts during printing.

While the width calculation is correct, consider caching the measured width when printing starts to prevent potential layout shifts during the print process.

-  const totalWidth = isPrinting ? (measure.width() ?? widthState) : widthState;
+  const measuredWidth = measure.width();
+  const [printWidth, setPrintWidth] = useState(0);
+  
+  useEffect(() => {
+    if (isPrinting && measuredWidth) {
+      setPrintWidth(measuredWidth);
+    }
+  }, [isPrinting, measuredWidth]);
+  
+  const totalWidth = isPrinting ? (printWidth || measuredWidth || widthState) : widthState;
packages/desktop-client/src/components/budget/DynamicBudgetTable.tsx (2)

157-181: Consider optimizing the print layout implementation.

While the implementation works, there are a few suggestions for improvement:

  1. The comment "Important: re-render when printing" suggests this is a workaround. Consider adding more detailed documentation explaining why this is necessary.
  2. The current implementation might cause unnecessary re-renders during printing.

Consider these improvements:

- // Important: re-render when printing to get the correct width
+ // When printing, we bypass AutoSizer and use fixed dimensions from useSpaceMeasure
+ // because AutoSizer's measurements aren't reliable in print media context.
+ // This ensures consistent table dimensions in the printed output.
  const isPrinting = useMediaQuery('print');
- const measure = useSpaceMeasure();
+ // Memoize the measure hook to prevent unnecessary recalculations
+ const measure = React.useMemo(() => useSpaceMeasure(), []);

  return (
    <>
      {measure.elements}
-     <AutoSizer>
+     <AutoSizer disableHeight={isPrinting} disableWidth={isPrinting}>
        {({ width, height }) => {
          if (isPrinting) {
            return (
              <DynamicBudgetTableInner
                width={measure.width()}
                height={measure.height()}
                {...props}
              />
            );
          }

Line range hint 1-181: Consider alternative approaches to print layout management.

While the current implementation works, it introduces complexity by mixing runtime layout measurement with print media handling. Consider these architectural alternatives:

  1. Use CSS Grid or Flexbox with print-specific styles to handle layout without JavaScript measurement.
  2. Create a separate print-optimized view that doesn't require dynamic measurements.

These alternatives could simplify the code and make it more maintainable.

Would you like me to elaborate on these alternative approaches?

packages/desktop-client/src/components/budget/BudgetTable.jsx (1)

Line range hint 19-21: Fix typo in variable name setShowHiddenCategoriesPef.

There appears to be a typo in the variable name. It should be setShowHiddenCategoriesPref to maintain consistency with the "preference" terminology.

Apply this diff to fix the typo:

  const [showHiddenCategories, setShowHiddenCategoriesPef] = useLocalPref(
    'budget.showHiddenCategories',
  );
+  const [showHiddenCategories, setShowHiddenCategoriesPref] = useLocalPref(
+    'budget.showHiddenCategories',
+  );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e078ed2 and 10899c5.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/3780.md is excluded by !**/*.md
📒 Files selected for processing (10)
  • packages/desktop-client/index.html (1 hunks)
  • packages/desktop-client/src/components/App.tsx (1 hunks)
  • packages/desktop-client/src/components/FinancesApp.tsx (1 hunks)
  • packages/desktop-client/src/components/Titlebar.tsx (1 hunks)
  • packages/desktop-client/src/components/budget/BudgetSummaries.tsx (3 hunks)
  • packages/desktop-client/src/components/budget/BudgetTable.jsx (1 hunks)
  • packages/desktop-client/src/components/budget/DynamicBudgetTable.tsx (4 hunks)
  • packages/desktop-client/src/components/budget/index.tsx (1 hunks)
  • packages/desktop-client/src/components/sidebar/Sidebar.tsx (1 hunks)
  • packages/desktop-client/src/hooks/useSpaceMeasure.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • packages/desktop-client/src/components/App.tsx
  • packages/desktop-client/src/components/FinancesApp.tsx
  • packages/desktop-client/src/components/Titlebar.tsx
  • packages/desktop-client/src/components/budget/index.tsx
🔇 Additional comments (11)
packages/desktop-client/src/hooks/useSpaceMeasure.tsx (1)

1-3: LGTM! Clean and minimal imports.

The imports are well-organized with proper separation between external and internal dependencies.

packages/desktop-client/index.html (2)

116-120: LGTM! Print media query implementation looks good.

The addition of the print media query to set body { overflow: visible } is a necessary foundation for making content printable. This change correctly overrides the default overflow: hidden style during printing.


116-120: Verify the impact of global overflow change.

Since this change affects the entire body element, we should ensure it doesn't cause unintended side effects on other pages during printing.

✅ Verification successful

Print overflow styles are consistently applied across components

Based on the search results, the change to make body overflow visible during print is consistent with the application's print styling pattern. Several components already implement the same overflow: visible style for print media:

  • FinancesApp component
  • App component
  • BudgetTable component
  • Budget index component

Other print-related styles (in Sidebar and Titlebar) handle visibility appropriately by hiding non-essential UI elements during printing. This change aligns with the existing print styling strategy across the application.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Look for pages/components that might be affected by the overflow change
# Search for components that explicitly set overflow styles which might conflict with print styles

# Test 1: Find components with overflow styles
echo "Checking for components with overflow styles:"
rg -t tsx -t jsx -t css "overflow:\s*(hidden|auto|scroll)" packages/desktop-client/src

# Test 2: Find existing print-related styles that might interact with this change
echo -e "\nChecking for existing print-related styles:"
rg -t tsx -t jsx -t css "@media\s+print" packages/desktop-client/src

Length of output: 419


Script:

#!/bin/bash
# Let's try without file type restrictions since the previous attempt failed
# and search for overflow styles and print media queries

# Search for overflow styles
echo "Checking for components with overflow styles:"
rg "overflow:\s*(hidden|auto|scroll)" packages/desktop-client

# Search for print-related styles
echo -e "\nChecking for existing print-related styles:"
rg "@media\s+print" packages/desktop-client

Length of output: 1297


Script:

#!/bin/bash
# Let's examine the content of print media queries to understand their interaction with overflow

echo "Checking content of print media queries:"
rg -A 3 "@media\s+print" packages/desktop-client

# Also check the full context of the body overflow in index.html
echo -e "\nChecking context of body overflow in index.html:"
rg -B 5 -A 5 "body\s*{[^}]*overflow:" packages/desktop-client/index.html

Length of output: 2883

packages/desktop-client/src/components/budget/BudgetSummaries.tsx (4)

42-44: LGTM! Clean implementation of print detection.

The print detection is well implemented using the useMediaQuery hook with a clear explanatory comment.


91-95: LGTM! Well-structured animation handling.

The conditional animation logic is well implemented, correctly disabling transforms during printing while maintaining the animation functionality during normal viewing.


78-78: Consider accessibility implications of measurement elements.

While the layout adjustments are correct, ensure that any measurement elements added to the DOM are properly hidden from screen readers and don't interfere with keyboard navigation.

#!/bin/bash
# Description: Check if measurement elements have proper accessibility attributes

# Look for aria-hidden or similar accessibility attributes in the useSpaceMeasure implementation
rg -A 5 "measure\.elements" 

Also applies to: 86-86


11-11: Verify the implementation of useSpaceMeasure hook.

The imports look good, but let's verify the implementation of the custom useSpaceMeasure hook to ensure it handles print measurements correctly.

Also applies to: 16-16

✅ Verification successful

The useSpaceMeasure hook implementation is correct and appropriate for its usage

The hook is well-implemented and provides the necessary functionality for measuring container dimensions:

  • Creates invisible measurement elements for width and height
  • Returns width, height functions, and measurement elements
  • Properly used in BudgetSummaries for layout calculations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of useSpaceMeasure hook
# Expected: The hook should handle space measurements, particularly for print media

# Check the implementation
ast-grep --pattern 'export function useSpaceMeasure() {
  $$$
}'

# Look for any tests
rg -l "useSpaceMeasure" --glob "**/*.test.*"

Length of output: 1278


Script:

#!/bin/bash
# Let's try a different approach to find the hook implementation
# Search for files containing useSpaceMeasure
rg -l "useSpaceMeasure"

# Search for the actual implementation with context
rg -A 10 "export.*useSpaceMeasure"

# Look for any space measurement related hooks
fd -e ts -e tsx | xargs rg -l "SpaceMeasure"

Length of output: 1351


Script:

#!/bin/bash
# Let's get the complete implementation of useSpaceMeasure hook
cat packages/desktop-client/src/hooks/useSpaceMeasure.tsx

# Also check how it's being used in BudgetSummaries
rg -A 5 "useSpaceMeasure" packages/desktop-client/src/components/budget/BudgetSummaries.tsx

Length of output: 1452

packages/desktop-client/src/components/budget/DynamicBudgetTable.tsx (2)

6-10: LGTM! Clean import additions for print functionality.

The new imports for useMediaQuery and useSpaceMeasure are well-organized and align with the PR's objective of making the budget page printable.


Line range hint 120-139: LGTM! Clean implementation of print-specific header handling.

The conditional rendering of BudgetPageHeader based on the print state is well-implemented. This ensures a cleaner print layout by removing the header during printing.

Let's verify that no other components depend on the header being present:

✅ Verification successful

Print layout change for BudgetPageHeader is safe to proceed

The search results confirm that BudgetPageHeader is only used within DynamicBudgetTable.tsx and is properly encapsulated. The component is self-contained and no other components depend on its presence, making it safe to hide during printing. The implementation correctly maintains all necessary props and functionality for normal viewing while cleanly handling the print state.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for components that might depend on BudgetPageHeader's presence
rg -l "BudgetPageHeader" | xargs rg "BudgetPageHeader.*props|ref"

Length of output: 65


Script:

#!/bin/bash
# Let's try a different approach to find BudgetPageHeader usage and dependencies
rg -A 5 "BudgetPageHeader" --type typescript --type tsx

Length of output: 90


Script:

#!/bin/bash
# Search for BudgetPageHeader references without file type filters
rg -A 5 "BudgetPageHeader"

Length of output: 2648

packages/desktop-client/src/components/budget/BudgetTable.jsx (1)

216-218: LGTM! Print style changes look good.

The addition of the print media query to make the content fully visible when printing is appropriate and aligns with the PR objective. This ensures that all budget data will be properly rendered in the printed output without being cut off by scroll containers.

packages/desktop-client/src/components/sidebar/Sidebar.tsx (1)

78-82: LGTM! Verify print styles across components.

The implementation correctly hides the sidebar during printing, which is appropriate for a printable budget page.

Let's verify the consistency of print styles across related components:

✅ Verification successful

Print styles are consistently implemented across components

The verification shows that print-related styles are properly coordinated across components:

  • Navigation elements (Sidebar, Titlebar) are hidden with display: none
  • Content containers (FinancesApp, Budget components) use overflow: visible to ensure proper content rendering
  • The implementation follows a consistent pattern using emotion's css prop
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for print-related media queries across components
# Expected: Similar print style implementations in related components

# Search for print-related media queries
rg -l "@media print" "packages/desktop-client/src/components"

# Check specific style implementations
rg -A 3 "@media print.*display.*none" "packages/desktop-client/src/components"

Length of output: 471


Script:

#!/bin/bash
# Let's examine the print-related styles in the identified files
for file in "packages/desktop-client/src/components/FinancesApp.tsx" "packages/desktop-client/src/components/Titlebar.tsx" "packages/desktop-client/src/components/App.tsx" "packages/desktop-client/src/components/sidebar/Sidebar.tsx" "packages/desktop-client/src/components/budget/index.tsx" "packages/desktop-client/src/components/budget/BudgetTable.jsx"; do
  echo "=== $file ==="
  rg -A 5 "@media print" "$file"
done

Length of output: 4417

@Teprifer
Copy link

Teprifer commented Nov 4, 2024

Using my real budget. yay privacy mode working in the print.

Firefox - defaulted to 1 page by condensing it down. Seems overall it thinks the page is much wider than it is?
image
image

100% scale is, probably best not done heh.
image

Snippet of pages 2 and 3:
image

Chome has it neatly centered and fine etc. and splits over two pages, Edge is similar, both also show a yellow underline for the demo build notice of the netlify link that Firefox doesn't:
image

Firefox will render background colours correctly:

Chrome doesn't render background colours per the theme used, note the dark theme underneath the print window(right side), but light in the print window:
image

This works correctly in firefox:
image

@youngcw
Copy link
Member

youngcw commented Nov 4, 2024

Any idea on why the print is insisting on starting in October instead of using the current view? It will add more months if I add them, as long as I only want to look at 3 at a time. Any more than 3 and I will still just get 3 in the print preview

@joel-jeremy
Copy link
Contributor

joel-jeremy commented Nov 4, 2024

Just some thought on the implementation. Would a PrivacyFilter style component work to specify which components are visible on print or not? e.g.

<PrintAware display="flex" overflow="visible">
    <MyComponent />
</PrintAware>

PrintAware component would just wrap it's children with a div that has @media print className. This would allow us to declaratively configure how components should behave during printing.


import { View } from '../components/common/View';

export const useSpaceMeasure = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would existing useViewportSize/useWindowSize hooks achieve the same thing as this hook?

Copy link
Contributor

@MikesGlitch MikesGlitch left a comment

Choose a reason for hiding this comment

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

This looks cool.

I noticed the budget rows have a larger width than the header - replicated on Edge and firefox:

image

Also When I select the 5 month display and try to print on Edge it only prints 3 months in the portait. On Firefox it prints 5. It works fine if you print to landscape.

I think these are minor though.

Copy link
Contributor

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Dec 10, 2024
Copy link
Contributor

This PR was closed because it has been stalled for 5 days with no activity.

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

Successfully merging this pull request may close these issues.

5 participants