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

:electron: Move file settings to the file management area #3500

Conversation

MikesGlitch
Copy link
Contributor

@MikesGlitch MikesGlitch commented Sep 24, 2024

This is step 1 to resolving this issue: #3371

  • Added settings modal into file management page and moved the Change data dir functionality in
  • Provided an option to automatically move budget files as a part of changing data dir
  • Silently restart electron server when Actuals data dir is changed and refreshes data, preventing the need for a hard restart.
  • Adding info about Electrons backups (telling users that it exists or how often it runs)

Step 2 is to allow configuration before creating a budget (will tackle that in a follow up PR).

Changing the data directory

test3

Settings page (if electron):

image

Tested on:

  • Windows
  • Linux
  • Mac

Copy link
Contributor

coderabbitai bot commented Sep 24, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces several enhancements to the desktop client application, including the addition of new modal components for managing file settings and confirming directory changes. It implements functionality for moving budget directories through IPC communication and updates the application state management to accommodate new user preferences. Additionally, existing components are modified to integrate these new features, ensuring a cohesive user experience across the application. Key changes include the addition of the moveBudgetDirectory method in the global.Actual object, the introduction of modal components such as ConfirmChangeDocumentDirModal and FilesSettingsModal, and updates to existing components like BudgetListHeader to support new settings functionalities.

Possibly related PRs

Suggested labels

<sparkles: Merged>

Suggested reviewers

  • joel-jeremy

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

netlify bot commented Sep 24, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit a9668f9
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/6702875ee7ef7c00085c7270
😎 Deploy Preview https://deploy-preview-3500.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 Sep 24, 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.31 MB (+12.11 kB) +0.22%
Changeset
File Δ Size
src/components/modals/manager/ConfirmChangeDocumentDir.tsx 🆕 +6.83 kB 0 B → 6.83 kB
src/components/modals/manager/FilesSettingsModal.tsx 🆕 +5.87 kB 0 B → 5.87 kB
src/components/settings/Backups.tsx 🆕 +1.13 kB 0 B → 1.13 kB
src/components/manager/BudgetList.tsx 📈 +908 B (+8.35%) 10.62 kB → 11.51 kB
src/components/Modals.tsx 📈 +370 B (+2.41%) 14.99 kB → 15.35 kB
src/browser-preload.browser.js 📈 +36 B (+0.90%) 3.93 kB → 3.96 kB
src/components/settings/index.tsx 📉 -7 B (-0.11%) 6.06 kB → 6.05 kB
src/components/transactions/TransactionsTable.jsx 📉 -500 B (-0.76%) 63.83 kB → 63.34 kB
src/components/common/Button2.tsx 📉 -158 B (-3.01%) 5.12 kB → 4.97 kB
src/components/settings/Global.tsx 🔥 -2.36 kB (-100%) 2.36 kB → 0 B
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/index.js 3.32 MB → 3.33 MB (+12.6 kB) +0.37%

Smaller

Asset File Size % Changed
static/js/wide.js 225.75 kB → 225.26 kB (-500 B) -0.22%

Unchanged

Asset File Size % Changed
static/js/usePreviewTransactions.js 1.64 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/BackgroundImage.js 122.29 kB 0%
static/js/AppliedFilters.js 20.96 kB 0%
static/js/narrow.js 82.55 kB 0%
static/js/ReportRouter.js 1.5 MB 0%

Copy link
Contributor

github-actions bot commented Sep 24, 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 → 1.19 MB (+62 B) +0.00%
Changeset
File Δ Size
packages/loot-core/src/server/main.ts 📈 +126 B (+0.20%) 61.37 kB → 61.5 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
kcab.worker.js 1.19 MB → 1.19 MB (+62 B) +0.00%

Smaller

No assets were smaller

Unchanged

No assets were unchanged

return Promise.reject(error);
}
},
);
Copy link
Contributor Author

@MikesGlitch MikesGlitch Sep 26, 2024

Choose a reason for hiding this comment

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

Copies the budget files into the new directory, then removes the old directory.

  • If it fails the copy nothing is deleted - recoverable.
  • If it fails the delete the copy has been successful - recoverable

In the event of a failure the user is instructed to check the directories so they can remedy it manually or fix whatever was causing the error (like a file lock).

@MikesGlitch MikesGlitch marked this pull request as ready for review September 26, 2024 20:01
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: 7

🧹 Outside diff range and nitpick comments (10)
packages/loot-core/typings/window.d.ts (1)

20-23: LGTM! Consider adding documentation and error handling.

The new moveBudgetDirectory method is well-defined and aligns with the PR objectives. It correctly uses TypeScript types and follows naming conventions.

To improve the code further:

  1. Add JSDoc comments to explain the method's purpose and parameters. For example:
/**
 * Moves the budget directory from the current location to a new one.
 * @param currentBudgetDirectory The current location of the budget directory.
 * @param newDirectory The new location for the budget directory.
 * @returns A promise that resolves when the operation is complete.
 */
moveBudgetDirectory: (
  currentBudgetDirectory: string,
  newDirectory: string,
) => Promise<void>;
  1. Consider how error handling will be implemented in the actual function. You might want to update the return type to Promise<void | Error> if you plan to return errors, or ensure that error handling is documented in the implementation.
packages/desktop-electron/preload.ts (1)

76-86: Consider updating documentation and tests

The new moveBudgetDirectory method enhances the file management capabilities as intended. To ensure long-term maintainability:

  1. Update any relevant documentation to reflect this new functionality.
  2. Consider adding unit tests for this new method, if not already done.
packages/desktop-client/src/browser-preload.browser.js (1)

155-155: Consider additional updates to support budget directory movement

While the addition of moveBudgetDirectory is a good start, consider the following suggestions to ensure comprehensive support for this new functionality:

  1. Document the intended use and parameters of the moveBudgetDirectory method. This will help other developers understand how to use it when it's fully implemented.

  2. Consider if any additional methods or updates to existing methods (like openFileDialog or saveFile) are needed to fully support the budget directory movement functionality.

  3. Ensure that any related state management or IPC communication needed for this feature is properly set up in this file or related files.

Here's a suggested documentation format for the method:

/**
 * Moves the budget directory to a new location.
 * @param {string} newPath - The new path for the budget directory.
 * @returns {Promise<boolean>} - Resolves to true if the move was successful, false otherwise.
 * @throws {Error} If the operation fails.
 */
moveBudgetDirectory: (newPath) => {
  // TODO: Implement budget directory movement functionality
  console.warn('moveBudgetDirectory: Not yet implemented');
  throw new Error('moveBudgetDirectory is not yet implemented');
},

This documentation provides clear expectations for the method's future implementation and usage.

packages/desktop-client/src/components/modals/manager/FilesSettingsModal.tsx (2)

16-16: Consider removing unused state variable.

The state variable _documentDirChanged is declared but never used in the component. Consider removing it to keep the code clean and avoid potential confusion.

-  const [_documentDirChanged, setDirChanged] = useState(false);
+  const [, setDirChanged] = useState(false);

If the state is not needed at all, you can remove the entire line.


84-85: Consider removing unused variable.

The variable _setServerSelfSignedCertPref is declared but never used in the component. Consider removing it to keep the code clean and avoid potential confusion.

-  const [serverSelfSignedCertPref, _setServerSelfSignedCertPref] =
-    useGlobalPref('serverSelfSignedCert');
+  const [serverSelfSignedCertPref] = useGlobalPref('serverSelfSignedCert');
packages/desktop-client/src/components/settings/index.tsx (1)

180-180: LGTM: Conditional rendering of Backups component added

The addition of the Backups component with conditional rendering based on isElectron() aligns well with the PR objectives. This change enhances the settings page for Electron environments while maintaining compatibility with other platforms.

Consider extracting the isElectron() check into a constant at the beginning of the component for improved readability:

export function Settings() {
  const [floatingSidebar] = useGlobalPref('floatingSidebar');
  const [budgetName] = useMetadataPref('budgetName');
+ const isElectronEnv = isElectron();

  // ... (rest of the component code)

  return (
    <Page
      // ... (other JSX)
    >
      <View>
        {/* ... (other components) */}
-       {isElectron() && <Backups />}
+       {isElectronEnv && <Backups />}
        {/* ... (rest of the JSX) */}
      </View>
    </Page>
  );
}

This change would make the code more readable and allow for easier reuse of the isElectron check if needed elsewhere in the component.

packages/loot-core/src/client/state-types/modals.d.ts (1)

91-94: LGTM: 'confirm-change-document-dir' modal type added.

The addition of the 'confirm-change-document-dir' modal type with currentBudgetDirectory and newDirectory properties is well-defined and aligns with the PR objective of allowing users to change the data directory.

For consistency with other modal types in this file, consider using camelCase for the modal name. Apply this change:

-  'confirm-change-document-dir': {
+  'confirmChangeDocumentDir': {
     currentBudgetDirectory: string;
     newDirectory: string;
   };
packages/desktop-client/src/components/manager/BudgetList.tsx (2)

337-354: LGTM: New SettingsButton component looks good.

The SettingsButton component is well-implemented, using proper React practices and maintaining consistency with other components. It's great to see the use of internationalization and accessibility attributes.

Consider extracting the inline styles to a separate object or using a styled-component approach for better maintainability. For example:

const settingsButtonStyle = {
  padding: 10
};

// Then in the component:
<Button
  variant="bare"
  aria-label={t('Menu')}
  onPress={onOpenSettings}
  style={settingsButtonStyle}
>
  <SvgCog style={{ width: 18, height: 18 }} />
</Button>

Line range hint 356-392: LGTM: BudgetListHeader updated correctly with new SettingsButton.

The BudgetListHeader component has been successfully updated to include the new SettingsButton. The conditional rendering based on the Electron environment is appropriate, and the layout changes improve the organization of the buttons.

Consider extracting the inline styles for the button container to a separate object or using a styled-component approach. This would improve readability and maintainability. For example:

const buttonContainerStyle = {
  flexDirection: 'row' as const,
  gap: '0.2rem',
};

// Then in the component:
<View style={buttonContainerStyle}>
  <RefreshButton onRefresh={onRefresh} />
  {isElectron() && <SettingsButton onOpenSettings={onOpenSettings} />}
</View>
packages/desktop-client/src/components/Modals.tsx (1)

578-587: LGTM: New modal cases added correctly

The new case statements for 'files-settings' and 'confirm-change-document-dir' modals are correctly implemented and follow the existing pattern in the switch statement. The props are correctly passed to the ConfirmChangeDocumentDirModal component.

For consistency with other single-line cases, consider simplifying the 'files-settings' case to a single line:

-        case 'files-settings':
-          return <FilesSettingsModal key={name} />;
+        case 'files-settings': return <FilesSettingsModal key={name} />;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4373f4d and f964dcd.

⛔ Files ignored due to path filters (2)
  • upcoming-release-notes/3500.md is excluded by !**/*.md
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (14)
  • packages/desktop-client/src/browser-preload.browser.js (1 hunks)
  • packages/desktop-client/src/components/Modals.tsx (2 hunks)
  • packages/desktop-client/src/components/manager/BudgetList.tsx (5 hunks)
  • packages/desktop-client/src/components/modals/manager/ConfirmChangeDocumentDir.tsx (1 hunks)
  • packages/desktop-client/src/components/modals/manager/FilesSettingsModal.tsx (1 hunks)
  • packages/desktop-client/src/components/settings/Backups.tsx (1 hunks)
  • packages/desktop-client/src/components/settings/Global.tsx (0 hunks)
  • packages/desktop-client/src/components/settings/index.tsx (3 hunks)
  • packages/desktop-electron/index.ts (2 hunks)
  • packages/desktop-electron/package.json (2 hunks)
  • packages/desktop-electron/preload.ts (1 hunks)
  • packages/loot-core/src/client/state-types/modals.d.ts (1 hunks)
  • packages/loot-core/src/server/main.ts (2 hunks)
  • packages/loot-core/typings/window.d.ts (1 hunks)
💤 Files not reviewed due to no reviewable changes (1)
  • packages/desktop-client/src/components/settings/Global.tsx
🔇 Additional comments (28)
packages/desktop-client/src/components/settings/Backups.tsx (3)

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

The imports are logically structured, including React core, third-party library (react-i18next), and local components. All imported items are used in the component.


8-27: LGTM: Component structure is clean and follows best practices.

The Backups component is well-structured:

  • It's a functional component, aligning with modern React patterns.
  • It uses composition with Setting and Text components, suggesting a consistent UI structure.
  • The component is properly exported for use in other parts of the application.

1-27: Overall, excellent implementation of the Backups component.

The Backups component is well-implemented, adhering to React and TypeScript best practices. It's focused, uses appropriate sub-components, and consistently applies internationalization. The code is clean, readable, and maintainable.

A minor suggestion for improvement has been made regarding parameterizing backup details, but this doesn't detract from the overall quality of the implementation.

packages/desktop-electron/preload.ts (2)

Line range hint 1-86: Overall, the changes look good and align with the PR objectives.

The new moveBudgetDirectory method is well-integrated into the existing structure of the preload script. It enhances the file management capabilities as intended, without introducing unnecessary complexity.


77-86: LGTM! The moveBudgetDirectory method is well-implemented.

The new method is correctly added to the Actual object and properly uses ipcRenderer.invoke for IPC communication. The naming is clear, and the types are correctly specified.

To ensure complete implementation, let's verify the corresponding handler in the main process:

This script will help confirm that the main process is prepared to handle the 'move-budget-directory' event.

packages/desktop-electron/package.json (3)

93-93: LGTM: Addition of fs-extra dependency

The addition of fs-extra (version ^11.2.0) is appropriate for enhancing file system operations. This aligns well with the PR objective of moving budget files when the data directory changes.


102-102: LGTM: Addition of @types/fs-extra dependency

The inclusion of @types/fs-extra (version ^11) is appropriate for providing TypeScript type definitions. This addition enhances type safety and improves the development experience when working with fs-extra.


93-93: Summary: Appropriate additions to enhance file system operations

The additions of fs-extra and @types/fs-extra are well-justified and align perfectly with the PR objectives. These dependencies will facilitate the implementation of moving budget files when the data directory changes, as outlined in the PR summary. The use of up-to-date versions and the inclusion of TypeScript definitions demonstrate good development practices.

Also applies to: 102-102

packages/desktop-client/src/components/modals/manager/ConfirmChangeDocumentDir.tsx (3)

1-10: LGTM: Import statements are well-organized and appropriate.

The import statements are logically organized and include all necessary dependencies for the components. Good job on keeping the imports clean and relevant.


36-173: LGTM: Well-structured component with proper state management and error handling.

The ConfirmChangeDocumentDirModal component is well-implemented with good use of React hooks for state management. It properly handles loading states, error conditions, and provides clear user feedback. The internationalization support is a great addition for maintaining a multilingual application.


57-80: Ensure proper security measures when changing directories.

When changing directories and moving files, it's crucial to ensure that the application has the necessary permissions and that the operation doesn't pose any security risks. Consider implementing the following security measures:

  1. Validate the new directory path to prevent potential directory traversal attacks.
  2. Ensure that the application has the necessary permissions to read from and write to both the old and new directories.
  3. Implement proper error handling and rollback mechanisms in case the directory change or file move operations fail midway.
  4. Consider adding a check to ensure that the new directory is not a subdirectory of the old one to prevent potential infinite loops or data corruption.

To help verify these security considerations, you can run the following script:

This script will help identify if these security considerations are already being addressed in the codebase.

packages/desktop-client/src/components/modals/manager/FilesSettingsModal.tsx (5)

1-12: LGTM: Import statements are appropriate and concise.

The import statements are well-organized and include all necessary dependencies for the components in this file. There are no unused imports, which is good for maintaining clean code.


14-81: LGTM: FileLocationSettings component is well-implemented.

The FileLocationSettings component is well-structured and follows React best practices. It correctly uses hooks for managing state and preferences, and the UI is styled consistently with the application's theme. The directory selection process is handled asynchronously, which is appropriate for file system operations.


83-135: LGTM: SelfSignedCertLocationSettings component is well-implemented.

The SelfSignedCertLocationSettings component is well-structured and follows React best practices. It correctly uses hooks for managing preferences and employs conditional rendering based on the existence of the certificate preference. The UI is styled consistently with the application's theme.


137-183: LGTM: FilesSettingsModal component is well-implemented.

The FilesSettingsModal component is well-structured and serves as an effective container for the file settings UI. It correctly uses the useDispatch hook for managing actions and implements a closeModal function that ensures all files are reloaded when the modal is closed, which is good for maintaining data consistency. The component's layout is clear and consistent with the application's theme, incorporating the FileLocationSettings and SelfSignedCertLocationSettings components appropriately.


1-183: Overall, the file is well-implemented and aligns with PR objectives.

This new file, FilesSettingsModal.tsx, successfully introduces components for managing file settings, which aligns well with the PR objectives of moving file settings to the file management area. The implementation is clean, well-organized, and follows React best practices.

Key points:

  1. The FileLocationSettings component allows users to view and change the data directory, as specified in the PR objectives.
  2. The SelfSignedCertLocationSettings component provides information about the server's self-signed certificate when applicable.
  3. The FilesSettingsModal component serves as a container for these settings, providing a cohesive user interface.

The code demonstrates good use of React hooks, consistent styling, and appropriate error handling. While there are a couple of minor issues with unused variables, these do not affect functionality and can be easily addressed.

This implementation lays a solid foundation for the file management enhancements described in the PR objectives.

packages/desktop-client/src/components/settings/index.tsx (3)

5-5: LGTM: Import path update for isElectron

The import path for isElectron has been updated from 'loot-core/src/shared/environment' to 'loot-core/shared/environment'. This change appears to be part of a project restructuring and doesn't affect the functionality.


Line range hint 1-190: Overall assessment: Changes align well with PR objectives

The modifications to the Settings component successfully integrate the new Backups functionality for Electron environments while maintaining compatibility with other platforms. The code structure is clean, and the changes are well-implemented.

Key points:

  1. Import statements have been updated appropriately.
  2. The new Backups component is conditionally rendered based on the Electron environment.
  3. The removal of GlobalSettings and addition of Backups align with the PR objectives.

These changes enhance the settings page as described in the PR summary, providing a solid foundation for future improvements to the file management area.


27-27: LGTM: New Backups component import added

The addition of the Backups import aligns with the PR objectives to include information about Electron's backup functionality. This is a good enhancement to the settings page.

To ensure the Backups component is properly implemented, please run the following script:

✅ Verification successful

Verified: Backups component correctly implemented

The Backups component exists and is properly implemented, providing clear information about the backup functionality as intended. This addition enhances the settings page by informing users about backup frequency and storage details.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the Backups component

# Test: Check if the Backups component file exists
fd -t f "Backups.tsx" packages/desktop-client/src/components/settings

# Test: Examine the contents of the Backups component
fd -t f "Backups.tsx" packages/desktop-client/src/components/settings -x cat

Length of output: 804

packages/loot-core/src/client/state-types/modals.d.ts (2)

89-90: LGTM: 'files-settings' modal type added.

The addition of the 'files-settings' modal type with a null value is appropriate for a settings modal that doesn't require additional parameters. This aligns with the PR objective of adding file management settings.


89-94: Summary: New modal types added for file management features.

The addition of 'files-settings' and 'confirm-change-document-dir' modal types enhances the type definitions for the new file management features. These changes are minimal, focused, and well-integrated into the existing FinanceModals type. They provide proper type safety for the new modals, aligning with the PR objectives of improving file management functionality.

packages/desktop-electron/index.ts (1)

21-21: LGTM: Appropriate import for the new functionality.

The import of copy and remove functions from fs-extra is correct and necessary for the new budget directory moving feature.

packages/desktop-client/src/components/manager/BudgetList.tsx (3)

15-18: LGTM: Import statements updated correctly.

The new imports for isElectron, isNonProductionEnvironment, and SvgCog are correctly added and necessary for the new functionality.

Also applies to: 32-32


469-469: LGTM: BudgetList component updated correctly.

The BudgetList component has been properly updated to pass the onOpenSettings prop to BudgetListHeader. The use of pushModal action to open the 'files-settings' modal is appropriate and consistent with the application's modal management approach.


Line range hint 1-538: Overall assessment: Changes are well-implemented and align with PR objectives.

The modifications to BudgetList.tsx successfully introduce the new settings functionality while maintaining code quality and consistency. The new SettingsButton component and the updates to BudgetListHeader and BudgetList components are well-structured and properly integrated.

A few minor suggestions have been made for improving code maintainability, primarily related to extracting inline styles. These are not critical issues but could enhance the code's readability and maintainability in the long term.

The changes align well with the PR objectives of moving file settings to the file management area and lay a good foundation for further enhancements.

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

44-44: LGTM: Import statement for ConfirmChangeDocumentDirModal

The import statement for the new ConfirmChangeDocumentDirModal component is correctly added and follows the existing import pattern in the file.


46-46: LGTM: Import statement for FilesSettingsModal

The import statement for the new FilesSettingsModal component is correctly added and follows the existing import pattern in the file.


44-46: Summary: New file management modals integrated successfully

The changes in this file successfully integrate the new FilesSettingsModal and ConfirmChangeDocumentDirModal components into the existing Modals component. These additions align well with the PR objectives of enhancing file management capabilities and providing a confirmation step for changing the document directory.

The implementation is consistent with the existing code structure and follows established patterns. The new modals are correctly imported and integrated into the switch statement that determines which modal to display.

These changes lay a solid foundation for the file management enhancements described in the PR objectives.

Also applies to: 578-587

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/alerts.tsx (1)

71-71: Approved: Style override behavior improved, but consider adding documentation.

The change to move the spread operator ...style to the end of the style object is a good improvement. This allows the style prop to override default styles, providing more flexibility for customization.

Consider adding a comment or updating the component's documentation to clarify this new behavior. This will help other developers understand that custom styles passed via the style prop will now take precedence over the default styles.

Example documentation:

/**
 * Information alert component.
 * @param {Object} props - The component props.
 * @param {CSSProperties} [props.style] - Custom styles to apply. These will override default styles.
 */
export const Information = ({ style, children }: ScopedAlertProps) => {
  // ... (rest of the component code)
};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f66d481 and 4cbbde1.

📒 Files selected for processing (3)
  • packages/desktop-client/src/components/alerts.tsx (1 hunks)
  • packages/desktop-client/src/components/modals/manager/ConfirmChangeDocumentDir.tsx (1 hunks)
  • packages/desktop-client/src/components/settings/Backups.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/desktop-client/src/components/modals/manager/ConfirmChangeDocumentDir.tsx
  • packages/desktop-client/src/components/settings/Backups.tsx

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/loot-core/src/server/main.ts (1)

1276-1284: LGTM! Consider adding a comment for clarity.

The addition of serverSelfSignedCert to the global preferences is a good enhancement for handling secure connections, especially in development or testing environments.

Consider adding a brief comment explaining the purpose of the serverSelfSignedCert preference for better code documentation:

 [, serverSelfSignedCert],
+    // Path to a self-signed certificate for secure server connections
   ] = await asyncStorage.multiGet([
     'floating-sidebar',
     'max-months',
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0eec5dc and 8ec29e2.

📒 Files selected for processing (3)
  • packages/desktop-client/src/components/settings/index.tsx (3 hunks)
  • packages/desktop-electron/package.json (2 hunks)
  • packages/loot-core/src/server/main.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/desktop-client/src/components/settings/index.tsx
  • packages/desktop-electron/package.json
🔇 Additional comments (1)
packages/loot-core/src/server/main.ts (1)

1303-1303: LGTM! Consistent handling of the new preference.

The addition of serverSelfSignedCert to the returned preferences object is well-implemented. It follows the pattern of other preferences and correctly defaults to undefined if not set.

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-electron/index.ts (1)

407-434: Solid implementation with room for minor improvements.

The implementation of the 'move-budget-directory' IPC handler is well-structured and addresses the main concerns raised in the previous review. Good job on the input validation and error handling. Here are a few suggestions for further improvement:

  1. Consider returning a success message or boolean to indicate successful completion.
  2. Add a check to ensure the destination directory is empty to prevent unintended overwrites.
  3. For large directories, implement a progress reporting mechanism to provide feedback to the user during the operation.

Here's a suggested improvement incorporating these points:

ipcMain.handle(
  'move-budget-directory',
  async (_event, currentBudgetDirectory: string, newDirectory: string) => {
    try {
      if (!currentBudgetDirectory || !newDirectory) {
        throw new Error('The from and to directories must be provided');
      }

      if (newDirectory.startsWith(currentBudgetDirectory)) {
        throw new Error(
          'The destination must not be a subdirectory of the current directory',
        );
      }

      if (!(await exists(newDirectory))) {
        throw new Error('The destination directory does not exist');
      }

      const destContents = await fs.readdir(newDirectory);
      if (destContents.length > 0) {
        throw new Error('The destination directory is not empty');
      }

      await copy(currentBudgetDirectory, newDirectory, {
        overwrite: true,
        filter: (src, dest) => {
          // You can implement progress reporting here
          console.log(`Copying: ${src}`);
          return true;
        },
      });
      await remove(currentBudgetDirectory);

      return { success: true, message: 'Budget directory moved successfully' };
    } catch (error) {
      console.error('There was an error moving your directory', error);
      throw error;
    }
  },
);

This implementation adds a check for an empty destination directory, includes a basic progress reporting mechanism (which can be enhanced to send progress to the renderer process), and returns a success message.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8ec29e2 and 9365eb2.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (2)
  • packages/desktop-electron/index.ts (2 hunks)
  • packages/desktop-electron/package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/desktop-electron/package.json

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 (4)
packages/desktop-client/src/components/modals/manager/FilesSettingsModal.tsx (4)

1-13: Consider reordering imports for consistency.

The imports are generally well-organized, but there's a minor opportunity for improvement in the order.

Consider moving the import of SvgPencil1 before the import of theme and styles to maintain a consistent order:

 import { useGlobalPref } from '../../../hooks/useGlobalPref';
+import { SvgPencil1 } from '../../../icons/v2';
 import { theme, styles } from '../../../style';
 import { Button } from '../../common/Button2';
 import { Modal, ModalCloseButton, ModalHeader } from '../../common/Modal';
 import { Text } from '../../common/Text';
 import { View } from '../../common/View';
-import { SvgPencil1 } from '../../../icons/v2';
🧰 Tools
🪛 GitHub Check: lint

[warning] 13-13:
../../../icons/v2 import should occur before import of ../../../style


15-88: Well-implemented component with room for enhanced error handling.

The FileLocationSettings component is well-structured and effectively manages the document directory setting. The use of useGlobalPref for state management and the implementation of the directory selection process are commendable.

Consider adding error handling for the file dialog operation:

 async function onChooseDocumentDir() {
-  const chosenDirectory = await window.Actual?.openFileDialog({
-    properties: ['openDirectory'],
-  });
+  try {
+    const chosenDirectory = await window.Actual?.openFileDialog({
+      properties: ['openDirectory'],
+    });
 
-  if (chosenDirectory && documentDir && chosenDirectory[0] !== documentDir) {
-    setDirChanged(true);
+    if (chosenDirectory && documentDir && chosenDirectory[0] !== documentDir) {
+      setDirChanged(true);
 
-    dispatch(
-      pushModal('confirm-change-document-dir', {
-        currentBudgetDirectory: documentDir,
-        newDirectory: chosenDirectory[0],
-      }),
-    );
+      dispatch(
+        pushModal('confirm-change-document-dir', {
+          currentBudgetDirectory: documentDir,
+          newDirectory: chosenDirectory[0],
+        }),
+      );
+    }
+  } catch (error) {
+    console.error('Error selecting directory:', error);
+    // Consider adding user feedback here, e.g., a toast notification
   }
 }

This change will help catch and log any errors that might occur during the file dialog operation, improving the robustness of the component.


90-142: Consider enhancing the SelfSignedCertLocationSettings component.

The SelfSignedCertLocationSettings component effectively displays the server's self-signed certificate location when applicable. The conditional rendering and styling are well-implemented.

Consider the following enhancements to improve user experience and functionality:

  1. Add a tooltip or info icon that explains the purpose and importance of the self-signed certificate when hovered over.
  2. Implement a way to verify the certificate's validity or expiration date.
  3. Provide a button to regenerate the certificate if it's expired or invalid.

Here's a conceptual example of how you might implement the first suggestion:

import { Tooltip } from '../../common/Tooltip';  // Assume this component exists

// Inside the component's JSX
<Text>
  <strong>
    <Trans>Server self-signed certificate</Trans>
  </strong>{' '}
  <Tooltip content={<Trans>This certificate ensures a secure connection between the client and server.</Trans>}>
    <span style={{ cursor: 'help' }}>ℹ️</span>
  </Tooltip>
</Text>

These enhancements would provide users with more information and control over the self-signed certificate, improving overall security awareness and management.


144-190: Well-structured modal component with a minor suggestion for improvement.

The FilesSettingsModal component is well-implemented, providing a cohesive container for the file settings. The use of Redux for state management and the overall structure of the modal are commendable.

Consider renaming the "OK" button to "Save" or "Apply" to more accurately reflect its action:

 <Button
   variant="primary"
   style={{
     padding: '10px 30px',
     fontSize: 14,
     alignSelf: 'center',
   }}
   onPress={() => closeModal(close)}
 >
-  <Trans>OK</Trans>
+  <Trans>Save</Trans>
 </Button>

This change would make it clearer to users that their settings will be saved when they dismiss the modal.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9365eb2 and ca7e59b.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (1)
  • packages/desktop-client/src/components/modals/manager/FilesSettingsModal.tsx (1 hunks)
🧰 Additional context used
🪛 GitHub Check: lint
packages/desktop-client/src/components/modals/manager/FilesSettingsModal.tsx

[warning] 13-13:
../../../icons/v2 import should occur before import of ../../../style

🔇 Additional comments (1)
packages/desktop-client/src/components/modals/manager/FilesSettingsModal.tsx (1)

1-190: Summary: Well-implemented file settings modal aligning with PR objectives.

This new file successfully implements the file settings modal as described in the PR objectives. The components work together seamlessly to provide users with the ability to manage file locations and view certificate information. The implementation aligns well with the goal of moving file settings to the file management area.

Key strengths:

  1. Proper use of React hooks and Redux for state management.
  2. Consistent styling and layout across components.
  3. Implementation of file dialog for changing the document directory.
  4. Conditional rendering of certificate information based on user preferences.

The suggested improvements, if implemented, would further enhance the robustness, user experience, and clarity of the file settings functionality.

Overall, this implementation provides a solid foundation for the file management enhancements described in the PR objectives.

🧰 Tools
🪛 GitHub Check: lint

[warning] 13-13:
../../../icons/v2 import should occur before import of ../../../style

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

Successfully merging this pull request may close these issues.

[Feature] Desktop App: Allow user to configure the data directory on Budget Management screen
1 participant