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

✨ (dashboards) ability to quick-edit widget names from inner report pages #3587

Merged
merged 2 commits into from
Oct 7, 2024

Conversation

MatissJanis
Copy link
Member

@actual-github-bot actual-github-bot bot changed the title ✨ (dashboards) ability to quick-edit widget names from inner report pages [WIP] ✨ (dashboards) ability to quick-edit widget names from inner report pages Oct 6, 2024
Copy link

netlify bot commented Oct 6, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit b53c8f3
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/6702ed38fc8f7e0008e9e55d
😎 Deploy Preview https://deploy-preview-3587.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.

Copy link
Contributor

github-actions bot commented Oct 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.3 MB → 5.3 MB (+2.94 kB) +0.05%
Changeset
File Δ Size
src/components/EditablePageHeaderTitle.tsx 🆕 +1.72 kB 0 B → 1.72 kB
src/components/reports/reports/NetWorth.tsx 📈 +457 B (+7.79%) 5.73 kB → 6.18 kB
src/components/reports/reports/CashFlow.tsx 📈 +457 B (+5.27%) 8.46 kB → 8.91 kB
src/components/reports/reports/Spending.tsx 📈 +464 B (+2.27%) 19.93 kB → 20.38 kB
src/components/reports/Header.tsx 📉 -123 B (-2.45%) 4.9 kB → 4.78 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/ReportRouter.js 1.5 MB → 1.51 MB (+2.94 kB) +0.19%
static/js/AppliedFilters.js 20.96 kB → 21.67 kB (+727 B) +3.39%

Smaller

Asset File Size % Changed
static/js/wide.js 225.26 kB → 224.55 kB (-727 B) -0.32%

Unchanged

Asset File Size % Changed
static/js/usePreviewTransactions.js 1.64 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/narrow.js 82.55 kB 0%
static/js/index.js 3.32 MB 0%

Copy link
Contributor

github-actions bot commented Oct 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.19 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.19 MB 0%

@@ -73,141 +70,140 @@ export function Header({
flexShrink: 0,
}}
>
{!['/reports/custom'].includes(path) && (
Copy link
Member Author

Choose a reason for hiding this comment

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

This component is not used in the custom reports page anymore.

Copy link
Contributor

coderabbitai bot commented Oct 6, 2024

Walkthrough

This pull request introduces a new React component, EditablePageHeaderTitle, which allows users to edit a title directly within the user interface. The component accepts two props: title, representing the initial title, and onSave, a callback for saving the new title. It manages its own state to track whether it is in editing mode and updates the title accordingly. The editing experience is enhanced with event handlers for saving and canceling edits.

Additionally, modifications are made to several existing components, including Header, CashFlow, NetWorth, and Spending, to incorporate the new EditablePageHeaderTitle component. The Header component sees a structural overhaul, removing the useLocation hook and refactoring the rendering logic to improve responsiveness. The other components integrate the editable title feature, allowing users to dynamically change the widget's titles while also updating the associated metadata. Error messaging improvements are made in the server-side report handling functions, clarifying the context of existing report names.

Possibly related PRs

Suggested labels

:sparkles: Merged

Suggested reviewers

  • joel-jeremy
  • carkom

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

🧹 Outside diff range and nitpick comments (10)
packages/desktop-client/src/components/EditablePageHeaderTitle.tsx (2)

34-55: LGTM: Editing mode render logic is well-implemented, with a minor suggestion.

The conditional rendering for the editing mode is correctly implemented with appropriate event handlers. The use of InitialFocus is a nice touch for improved UX. The dynamic width calculation for the input is clever and ensures a good user experience.

Consider moving the inline styles to a separate stylesheet or using a styled-component for better maintainability. This would make the component more readable and easier to maintain in the future.


57-89: LGTM: View mode render logic is well-implemented, with suggestions for improvement.

The view mode rendering is well-structured with a good use of layout and hover effects. The edit button implementation with hover visibility is a nice UX touch.

  1. Consider moving the inline styles to a separate stylesheet or using styled-components for better maintainability and readability.
  2. To improve accessibility, consider adding an aria-label to the edit button to describe its purpose for screen readers. For example:
    <Button
      aria-label="Edit title"
      // ... other props
    >
packages/loot-core/src/server/reports/app.ts (2)

143-143: Improved error message clarity and consistency.

The change from "filter" to "report" in the error message accurately reflects the context of the function, which is updating a report. This modification enhances the clarity of the error message and aligns with the PR objectives.

For consistency with the createReport function, consider extracting the error message to a constant. This would make future updates easier and ensure consistency across both functions. For example:

const REPORT_NAME_EXISTS_ERROR = (name: string) => `There is already a report named ${name}`;

// Then use it in both functions:
throw new Error(REPORT_NAME_EXISTS_ERROR(item.name));

Line range hint 1-164: Suggestions for overall improvements

The file structure and logic are well-implemented. Here are some suggestions for further improvements:

  1. Consider creating a constant for the 'custom_reports' table name to avoid repetition and make future changes easier.

  2. The reportNameExists function could be simplified by using a single query with a WHERE clause that handles both new and existing reports. This would reduce code duplication and potentially improve performance.

  3. Error messages could be centralized into an object or enum for easier management and consistency.

  4. Consider adding more specific error types (e.g., ReportNameExistsError) to allow for more granular error handling on the client side.

  5. The reportModel.validate function could benefit from stronger typing, possibly using a library like Zod for runtime type checking.

Would you like me to provide code examples for any of these suggestions?

packages/desktop-client/src/components/reports/reports/NetWorth.tsx (2)

150-163: LGTM: Well-implemented onSaveWidgetName function

The onSaveWidgetName function is well-implemented and correctly handles saving the new widget name. It includes proper error handling and uses a default name if necessary. The server update logic is correct.

Consider adding a success notification similar to the one in the onSaveWidget function to provide feedback to the user when the widget name is successfully updated.


180-191: LGTM: Well-implemented editable title in PageHeader

The changes to the PageHeader component correctly implement the editable title feature. The conditional rendering ensures that the EditablePageHeaderTitle is only shown when a widget exists, which is the correct behavior.

For consistency with the rest of the codebase, consider using optional chaining (widget?.) instead of the widget ? ... : ... ternary operator. This would make the code more concise and align with the coding style used elsewhere in the file.

packages/desktop-client/src/components/reports/reports/CashFlow.tsx (3)

171-185: LGTM: Title declaration and onSaveWidgetName function.

The title declaration and onSaveWidgetName function are well-implemented. The function correctly handles edge cases and updates the widget metadata.

Consider adding a success notification after saving the widget name, similar to the onSaveWidget function:

dispatch(
  addNotification({
    type: 'message',
    message: t('Widget name successfully updated.'),
  }),
);

204-215: LGTM: PageHeader title rendering logic.

The conditional rendering of the EditablePageHeaderTitle component is well-implemented. It correctly handles the cases with and without a widget.

To improve readability, consider extracting the title rendering logic into a separate variable:

const headerTitle = widget ? (
  <EditablePageHeaderTitle
    title={title}
    onSave={onSaveWidgetName}
  />
) : title;

return (
  <PageHeader title={headerTitle} />
);

Line range hint 1-365: Overall implementation aligns well with PR objectives.

The changes successfully implement the ability to quick-edit widget names from the CashFlow report page, which is consistent with the PR objectives. The feature is well-integrated into the existing component structure without introducing unnecessary complexity.

To further improve the implementation:

  1. Consider extracting the widget name editing logic into a custom hook (e.g., useEditableWidgetName) to promote reusability across different report types.
  2. Implement error handling for the onSaveWidgetName function to gracefully handle potential API errors.
packages/desktop-client/src/components/reports/reports/Spending.tsx (1)

185-199: LGTM: New title logic and onSaveWidgetName function

The changes improve the widget name handling and add the ability to save updated names. The fallback to a translated string is a good practice.

A minor suggestion:

Consider extracting the default name t('Monthly Spending') into a constant at the top of the file to avoid repetition:

+const DEFAULT_WIDGET_NAME = t('Monthly Spending');
 // ...
-const title = widget?.meta?.name || t('Monthly Spending');
+const title = widget?.meta?.name || DEFAULT_WIDGET_NAME;
 // ...
-const name = newName || t('Monthly Spending');
+const name = newName || DEFAULT_WIDGET_NAME;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 38c5f89 and b53c8f3.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/3587.md is excluded by !**/*.md
📒 Files selected for processing (6)
  • packages/desktop-client/src/components/EditablePageHeaderTitle.tsx (1 hunks)
  • packages/desktop-client/src/components/reports/Header.tsx (1 hunks)
  • packages/desktop-client/src/components/reports/reports/CashFlow.tsx (3 hunks)
  • packages/desktop-client/src/components/reports/reports/NetWorth.tsx (3 hunks)
  • packages/desktop-client/src/components/reports/reports/Spending.tsx (3 hunks)
  • packages/loot-core/src/server/reports/app.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (14)
packages/desktop-client/src/components/EditablePageHeaderTitle.tsx (5)

1-9: LGTM: Imports are well-organized and necessary.

The imports are logically structured and include all the necessary components and utilities for the EditablePageHeaderTitle component.


11-14: LGTM: Props type is well-defined.

The EditablePageHeaderTitleProps type clearly defines the expected props for the component, with appropriate types for both the title and onSave properties.


16-23: LGTM: Component definition and state management are well-implemented.

The component is defined following React best practices. The state initialization and synchronization with props using useEffect are correctly implemented. Good job on renaming the title prop to initialTitle to avoid confusion with the title state.


25-32: LGTM: Save callback is well-implemented with proper memoization.

The onSaveValue callback is correctly memoized using useCallback. It properly updates both the parent component and the internal state, and exits edit mode after saving. This implementation ensures good performance and user experience.


1-89: Overall assessment: Well-implemented component with minor suggestions for improvement.

The EditablePageHeaderTitle component is a solid implementation that meets the PR objective of allowing quick editing of widget names. It follows React best practices, uses hooks effectively, and provides a good user experience.

Key strengths:

  1. Clear and concise props definition
  2. Effective use of React hooks for state management
  3. Good separation of editing and view modes
  4. Clever input width calculation for a smooth editing experience

Suggestions for improvement:

  1. Move inline styles to a separate stylesheet or use styled-components
  2. Enhance accessibility by adding appropriate ARIA labels

This component should integrate well with the existing codebase and provide the desired functionality for editing widget names from inner report pages.

packages/loot-core/src/server/reports/app.ts (2)

123-123: Improved error message clarity.

The change from "filter" to "report" in the error message accurately reflects the context of the function, which is creating a report. This modification enhances the clarity of the error message and aligns with the PR objectives.


Line range hint 1-164: Conclusion: Changes improve clarity and align with PR objectives

The modifications to the error messages in this file enhance clarity and accurately reflect the context of report operations. These changes align well with the PR objectives of improving dashboard functionality related to reports.

The overall structure and functionality of the file are sound, with appropriate error handling and TypeScript usage. The suggestions provided for further improvements could enhance code maintainability and error handling in the future.

packages/desktop-client/src/components/reports/reports/NetWorth.tsx (3)

23-23: LGTM: Import statement for EditablePageHeaderTitle

The import statement for EditablePageHeaderTitle is correctly placed and aligns with the new feature for editable widget titles.


149-149: LGTM: Improved title fallback logic

The change from nullish coalescing (??) to logical OR (||) operator improves the title assignment logic. This ensures that if widget?.meta?.name is falsy (including an empty string), the default title 'Net Worth' will be used, which is the desired behavior.


Line range hint 1-265: Summary: Well-implemented editable widget title feature

The changes in this file successfully implement the ability to edit widget names from inner report pages, which aligns with the PR objectives. The implementation is clean, consistent, and follows good coding practices. The new EditablePageHeaderTitle component is properly integrated, and the necessary logic for saving the updated widget name is in place.

A few minor suggestions have been made for further improvement:

  1. Adding a success notification when the widget name is updated.
  2. Using optional chaining for consistency in the PageHeader component.

Overall, these changes effectively enhance the user experience by allowing quick editing of widget names directly from the Net Worth report page.

packages/desktop-client/src/components/reports/reports/CashFlow.tsx (1)

29-29: LGTM: Import statement for EditablePageHeaderTitle.

The import statement for EditablePageHeaderTitle is correctly placed and consistent with its usage in the component.

packages/desktop-client/src/components/reports/reports/Spending.tsx (3)

29-29: LGTM: New import for EditablePageHeaderTitle

The import for EditablePageHeaderTitle is correctly placed and aligns with the PR objective of allowing quick editing of widget names.


212-223: LGTM: Integration of EditablePageHeaderTitle

The PageHeader component has been successfully updated to include the EditablePageHeaderTitle when a widget is present. This change aligns well with the PR objective of allowing quick editing of widget names from inner report pages.

The conditional rendering and prop passing are implemented correctly.


Line range hint 1-624: Summary: Successful implementation of inline widget name editing

The changes in this file successfully implement the ability to quick-edit widget names from inner report pages, as per the PR objectives. The implementation is clean, well-integrated, and follows good practices such as error handling and fallback to default values.

Key improvements:

  1. Addition of the EditablePageHeaderTitle component
  2. Implementation of the onSaveWidgetName function
  3. Integration of the editable title in the PageHeader

These changes enhance the user experience by allowing seamless editing of widget names directly from the report page.

@MatissJanis MatissJanis changed the title [WIP] ✨ (dashboards) ability to quick-edit widget names from inner report pages ✨ (dashboards) ability to quick-edit widget names from inner report pages Oct 6, 2024
Copy link
Member

@youngcw youngcw left a comment

Choose a reason for hiding this comment

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

Looks good

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.

2 participants