-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix: csv import with less than 5 columns #3605
Conversation
✅ Deploy Preview for actualbudget ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
WalkthroughThe pull request introduces a new utility function, Possibly related PRs
Suggested labels
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used📓 Learnings (1)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
If #3499 is merged I could easily add an regression test for this bug. |
Bundle Stats — desktop-clientHey 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
Changeset
View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger
Smaller No assets were smaller Unchanged
|
Bundle Stats — loot-coreHey 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
Changeset
View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger
Smaller No assets were smaller Unchanged No assets were unchanged |
There was a problem hiding this 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 (3)
packages/desktop-client/src/components/modals/ImportTransactionsModal/FieldMappings.jsx (1)
Line range hint
1-138
: Summary: Centralized transaction processing with potential wide-ranging effects.The changes to this component are minimal but potentially impactful. The introduction of
stripCsvImportTransaction
centralizes the logic for processing CSV import transactions, which is a good practice for maintainability and consistency. However, this change may affect the structure of thetrans
object, which is used throughout the component to generate options for various fields.To ensure the robustness of this change:
- Thoroughly test the component with various CSV import scenarios to verify that all necessary transaction properties are preserved after processing.
- Update the component's documentation or comments to reflect the new data flow and any changes in the expected structure of the
trans
object.- Consider adding PropTypes or TypeScript types for the
trans
object to enforce its structure and catch potential issues early in development.packages/desktop-client/src/components/modals/ImportTransactionsModal/utils.js (1)
189-194
: LGTM with suggestions for improvementThe
stripCsvImportTransaction
function is well-implemented and effectively removes specific properties from the transaction object. However, consider the following suggestions:
- Add input validation to handle cases where
transaction
might benull
orundefined
.- Consider adding a brief comment explaining why these specific properties are being stripped.
Here's a suggested implementation with these improvements:
/** * Strips specific properties from a CSV import transaction. * @param {Object} transaction - The transaction object to process. * @returns {Object} A new object with the specified properties removed. */ export function stripCsvImportTransaction(transaction) { if (!transaction || typeof transaction !== 'object') { return {}; } // Remove properties used internally during the import process const { existing, ignored, selected, selected_merge, trx_id, ...trans } = transaction; return trans; }This implementation adds a simple check for the input and includes a brief explanation in the comments.
packages/loot-core/src/server/accounts/rules.ts (1)
403-403
: Approve: Consistent type safety, consider refactoringThis change completes the set of improvements for string comparisons in the
eval
method, ensuring type safety for thehasTags
condition. It's consistent with the changes made forcontains
anddoesNotContain
.Given that this pattern is now repeated three times in the
eval
method, consider refactoring to reduce duplication:Consider extracting the string conversion logic into a helper method to reduce code duplication:
private ensureString(value: any): string { return `${value}`; } // Then in the eval method: case 'contains': case 'doesNotContain': case 'hasTags': if (fieldValue === null) { return false; } return this.ensureString(fieldValue).indexOf(this.value) !== -1;This refactoring would centralize the string conversion logic, making it easier to maintain and modify in the future if needed.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
upcoming-release-notes/3605.md
is excluded by!**/*.md
📒 Files selected for processing (4)
- packages/desktop-client/src/components/modals/ImportTransactionsModal/FieldMappings.jsx (2 hunks)
- packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx (2 hunks)
- packages/desktop-client/src/components/modals/ImportTransactionsModal/utils.js (1 hunks)
- packages/loot-core/src/server/accounts/rules.ts (2 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx (1)
Learnt from: MatissJanis PR: actualbudget/actual#3570 File: packages/desktop-client/src/components/modals/ImportTransactionsModal/utils.ts:120-130 Timestamp: 2024-10-05T10:59:08.817Z Learning: Avoid overcomplicating the `ImportTransaction` type; prefer to keep it simple.
🔇 Additional comments (11)
packages/desktop-client/src/components/modals/ImportTransactionsModal/FieldMappings.jsx (2)
23-23
: LGTM. Verify impact on component and transaction structure.The use of
stripCsvImportTransaction
to process the first transaction simplifies the code and centralizes the logic for transaction processing. However, this change may affect the structure of thetrans
object and, consequently, theoptions
derived from it.To ensure the change doesn't introduce unintended side effects, please run the following script:
Additionally, ensure that all properties previously accessed on
trans
are still available after processing withstripCsvImportTransaction
.
9-9
: LGTM. Verify the utility function implementation.The import statement for
stripCsvImportTransaction
is correctly added. This new utility function seems to be crucial for processing CSV import transactions.To ensure the utility function is properly implemented, please run the following script:
✅ Verification successful
Verified the implementation of
stripCsvImportTransaction
inutils.js
. The function correctly exports and handles the expected transaction properties.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation of stripCsvImportTransaction in utils.js # Test: Check if the function is exported and its basic structure ast-grep --lang javascript --pattern 'export function stripCsvImportTransaction($_) { $$$ }' packages/desktop-client/src/components/modals/ImportTransactionsModal/utils.js # Test: Check if the function is handling the expected transaction properties rg --type js 'function stripCsvImportTransaction' -A 10 packages/desktop-client/src/components/modals/ImportTransactionsModal/utils.jsLength of output: 1146
packages/desktop-client/src/components/modals/ImportTransactionsModal/utils.js (1)
189-194
: Verify usage of new function across the codebaseThe addition of
stripCsvImportTransaction
function is a good utility for processing transaction objects. To ensure its proper integration:
- Verify that this function is used consistently where needed in the import process.
- Check for any potential side effects in modules that will use this function.
Run the following script to check the usage of
stripCsvImportTransaction
across the codebase:This will help identify where the function is being imported and used, allowing us to verify its correct implementation across the codebase.
✅ Verification successful
Function
stripCsvImportTransaction
is correctly utilized across the codebaseThe
stripCsvImportTransaction
function is properly imported and used in the following modules:
ImportTransactionsModal.jsx
: Utilizes the function to process transactions effectively.FieldMappings.jsx
: Applies the function to handle transaction data accurately.No unintended side effects or inconsistencies detected.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check usage of stripCsvImportTransaction function # Search for import statements echo "Checking import statements:" rg --type js --type jsx "import.*stripCsvImportTransaction.*from.*utils" -g '!utils.js' # Search for function usage echo "\nChecking function usage:" rg --type js --type jsx "stripCsvImportTransaction\(" -g '!utils.js'Length of output: 344
Script:
#!/bin/bash # Description: Check usage of stripCsvImportTransaction function # Search for import statements in .js and .jsx files echo "Checking import statements:" rg "import.*stripCsvImportTransaction.*from.*utils" -g "*.js" -g "*.jsx" --ignore-file '!utils.js' # Search for function usage in .js and .jsx files echo "\nChecking function usage:" rg "stripCsvImportTransaction\(" -g "*.js" -g "*.jsx" --ignore-file '!utils.js'Length of output: 999
packages/loot-core/src/server/accounts/rules.ts (3)
387-387
: Approve: Improved type safety in string comparisonThis change enhances the robustness of the
contains
condition by explicitly convertingfieldValue
to a string before performing theindexOf
check. This prevents potential type errors whenfieldValue
is not a string, making the code more resilient to unexpected input types.
392-392
: Approve: Consistent type safety improvementThis change mirrors the improvement made in the
contains
case, ensuring type safety for thedoesNotContain
condition. By convertingfieldValue
to a string, it prevents potential type errors and maintains consistency in how string comparisons are handled throughout theeval
method.
Line range hint
387-403
: Summary: Improved type safety in string comparisonsThe changes in this file consistently enhance type safety for string comparisons in the
eval
method of theCondition
class. By explicitly convertingfieldValue
to a string before performingindexOf
operations, the code becomes more robust against potential type errors.These modifications affect the
contains
,doesNotContain
, andhasTags
conditions, ensuring consistent behavior across different types of string-based comparisons. The changes are well-considered and improve the overall reliability of the rule evaluation process.Consider the suggested refactoring to further improve code maintainability by reducing duplication in the string conversion logic.
packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx (5)
Line range hint
1012-1029
: Enhanced import logic for reconciliation and forced transaction additionThe
onImport
function has been updated with more sophisticated logic for handling reconciliation and forced transaction addition. This includes checks forisMatchedTransaction
,ignored
, andselected_merge
properties.These changes significantly alter the import behavior. Please ensure:
- The new logic correctly handles all possible combinations of transaction states.
- Edge cases are properly addressed (e.g., what happens if a transaction is both ignored and selected?).
- The UI accurately reflects these new states to avoid user confusion.
Consider adding comprehensive unit tests for this function. You can use this script to find related test files:
#!/bin/bash # Search for test files related to import functionality rg "import.*test" --type js
Line range hint
1180-1184
: UI updates for new reconciliation optionsNew UI elements have been added to support the enhanced reconciliation functionality:
- A checkbox for merging with existing transactions.
- Filtered rendering of transactions based on the
isMatchedTransaction
property.Please ensure:
- The new UI elements are accessible and their purpose is clear to users.
- The filtering of transactions in the UI accurately reflects the backend logic.
- There are no unintended side effects on the layout or performance of the component.
You can use this script to check for accessibility and performance considerations:
#!/bin/bash # Search for accessibility attributes and performance optimizations echo "Accessibility checks:" rg "aria-|role=" --type js echo "\nPerformance optimizations:" rg "React\.memo|useMemo|useCallback" --type jsAlso applies to: 1252-1257
Line range hint
1-1352
: Summary of changes and suggestions for improvementThis PR introduces significant enhancements to the import process, particularly in handling reconciliation and matched transactions. While these changes add valuable functionality, they also increase the complexity of the
ImportTransactionsModal
component.Key points:
- New utility function
stripCsvImportTransaction
for processing CSV imports.- Enhanced logic in
getImportPreview
andonImport
for handling matched and reconciled transactions.- UI updates to reflect new reconciliation options.
To improve maintainability and reduce complexity:
- Consider breaking down this large component into smaller, more focused components.
- Implement comprehensive unit and integration tests for the new functionality.
- Add detailed documentation explaining the new reconciliation process and its various states.
- Consider implementing a state management solution (e.g., Redux, MobX) to handle the complex state logic more efficiently.
To ensure these changes don't introduce regressions:
- Conduct thorough end-to-end testing of the import process with various file types and edge cases.
- Verify performance with large transaction sets.
- Ensure backwards compatibility with existing imported data.
You can use this script to identify potential areas for refactoring:
#!/bin/bash # Find large components and functions that might benefit from refactoring echo "Large components (>500 lines):" rg -U "export.*function.*\{" --type js | awk '{print length, $0}' | sort -rn | head -10 echo "\nComplex functions (>50 lines):" rg -U "function.*\{" --type js | awk '{print length, $0}' | sort -rn | head -10
63-63
: Modification in initial mappings derivationThe
getInitialMappings
function now usesstripCsvImportTransaction
to process the first transaction before deriving field mappings.Please ensure that this change doesn't affect the field detection logic, especially for edge cases. Consider adding unit tests to verify the behavior with various CSV structures.
To verify the impact, you can run the following script:
✅ Verification successful
Verified:
stripCsvImportTransaction
does not impact field detection logicThe
stripCsvImportTransaction
function removes specific metadata fields without altering the core transaction data used for field detection.
- Impact Assessment:
- Removed fields (
existing
,ignored
,selected
,selected_merge
,trx_id
) are not involved in field detection.- Core transaction data remains unaffected, ensuring field detection operates correctly.
No issues found with the current implementation.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for all usages of getInitialMappings and stripCsvImportTransaction echo "Usages of getInitialMappings:" rg "getInitialMappings" --type js echo "\nUsages of stripCsvImportTransaction:" rg "stripCsvImportTransaction" --type jsLength of output: 1387
Script:
#!/bin/bash # Inspect usages of stripCsvImportTransaction in FieldMappings.jsx rg "stripCsvImportTransaction" packages/desktop-client/src/components/modals/ImportTransactionsModal/FieldMappings.jsxLength of output: 231
Script:
#!/bin/bash # Retrieve the implementation of stripCsvImportTransaction from utils.js rg "function stripCsvImportTransaction" packages/desktop-client/src/components/modals/ImportTransactionsModal/utils.js -A 10Length of output: 295
Line range hint
292-295
: New logic to skip matched transactions in import previewA new check has been added to skip transactions that are already matched. This is likely an optimization, but it changes the behavior of the import preview.
Please verify that:
- This change doesn't hide important information from the user.
- The UI properly indicates when transactions are skipped.
- The total count of imported transactions is still accurate.
You can use this script to check for any UI components that might need updating:
...ges/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx
Show resolved
Hide resolved
There was a problem hiding this 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 (3)
packages/desktop-client/src/components/modals/ImportTransactionsModal/FieldMappings.jsx (1)
Line range hint
1-138
: Address PR objective: CSV import with less than 5 columnsWhile the changes improve code organization, they don't directly address the PR objective of fixing CSV import with less than 5 columns. Consider the following suggestions:
- Ensure that
stripCsvImportTransaction
correctly handles transactions with fewer than 5 columns.- Add error handling or validation for cases where required fields are missing.
- Implement the regression test mentioned in the PR description once PR test: csv import e2e tests #3499 is merged.
Would you like assistance in implementing these suggestions or creating a GitHub issue to track them?
packages/desktop-client/src/components/modals/ImportTransactionsModal/utils.js (1)
189-194
: LGTM! Consider adding input validation and documentation.The new
stripCsvImportTransaction
function is well-implemented and serves its purpose of removing specific properties from a transaction object. It's a clean and straightforward utility function that will be useful for processing CSV import transactions.To further improve the function, consider the following suggestions:
- Add input validation to ensure
transaction
is an object.- Include JSDoc documentation for better code readability and maintainability.
Here's an example of how you could implement these suggestions:
/** * Strips specific properties from a CSV import transaction object. * @param {Object} transaction - The transaction object to process. * @returns {Object} A new object with the specified properties removed. * @throws {TypeError} If the input is not an object. */ export function stripCsvImportTransaction(transaction) { if (typeof transaction !== 'object' || transaction === null) { throw new TypeError('Input must be an object'); } const { existing, ignored, selected, selected_merge, trx_id, ...trans } = transaction; return trans; }These changes would enhance the robustness and clarity of the function without altering its core functionality.
packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx (1)
Line range hint
1-1006
: Consider refactoring for improved maintainabilityWhile the changes in this PR are minimal and focused on fixing the CSV import issue, the overall file is quite large and complex. Consider the following suggestions for future improvements:
- Break down the
ImportTransactionsModal
component into smaller, more manageable sub-components.- Extract utility functions and constants into separate files to reduce the file size and improve readability.
- Use custom hooks to manage complex state logic, which could help in separating concerns and make the component easier to test.
- Consider using a state management library like Redux or Recoil for handling complex state interactions, especially if this component's state is used in other parts of the application.
These suggestions are not directly related to the current PR but could be considered for future refactoring efforts to improve the overall maintainability of the codebase.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
upcoming-release-notes/3605.md
is excluded by!**/*.md
📒 Files selected for processing (4)
- packages/desktop-client/src/components/modals/ImportTransactionsModal/FieldMappings.jsx (2 hunks)
- packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx (2 hunks)
- packages/desktop-client/src/components/modals/ImportTransactionsModal/utils.js (1 hunks)
- packages/loot-core/src/server/accounts/rules.ts (2 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx (1)
Learnt from: MatissJanis PR: actualbudget/actual#3570 File: packages/desktop-client/src/components/modals/ImportTransactionsModal/utils.ts:120-130 Timestamp: 2024-10-05T10:59:08.817Z Learning: Avoid overcomplicating the `ImportTransaction` type; prefer to keep it simple.
🔇 Additional comments (9)
packages/desktop-client/src/components/modals/ImportTransactionsModal/FieldMappings.jsx (1)
9-9
: LGTM: New utility function import.The import of
stripCsvImportTransaction
from the local./utils
module is correctly implemented. This approach promotes good code organization by separating utility functions into a dedicated file.packages/desktop-client/src/components/modals/ImportTransactionsModal/utils.js (1)
188-194
: Good integration with existing utilities.The placement and implementation of the new
stripCsvImportTransaction
function integrate well with the existing codebase. It complements other utility functions in this file, such asapplyFieldMappings
, by providing an additional tool for transaction object manipulation.To ensure proper usage across the codebase:
Let's verify the usage of this new function:
This will help us confirm that the function is being imported and used correctly in other parts of the application.
✅ Verification successful
Function
stripCsvImportTransaction
is correctly integrated and utilized.The
stripCsvImportTransaction
function is properly imported and used in the following files:
FieldMappings.jsx
ImportTransactionsModal.jsx
No issues were found with its integration into the codebase.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for usage of stripCsvImportTransaction in other files # Search for import statements echo "Checking import statements:" rg --type js "import.*stripCsvImportTransaction.*from.*utils" packages/desktop-client/src # Search for function usage echo "\nChecking function usage:" rg --type js "stripCsvImportTransaction\(" packages/desktop-client/srcLength of output: 881
packages/loot-core/src/server/accounts/rules.ts (4)
387-387
: Improved type safety in string comparisonThis change ensures that
fieldValue
is always converted to a string before theindexOf
operation is performed. This is a good defensive programming practice that prevents potential type-related issues, especially iffieldValue
could be of a non-string type.
392-392
: Consistent type safety improvementThis change applies the same type safety improvement as in the
contains
case, ensuringfieldValue
is converted to a string before theindexOf
operation. This maintains consistency in how string comparisons are handled across different conditions.
403-403
: Completed type safety improvementsThis change completes the pattern of type safety improvements across all relevant cases in the
eval
method. By consistently convertingfieldValue
to a string in thehasTags
case, we ensure that all string comparisons in this method are handled safely and uniformly.
Line range hint
387-403
: Summary of changes: Improved type safety in condition evaluationThese changes collectively enhance the robustness of the
eval
method in theCondition
class. By consistently convertingfieldValue
to a string using template literals in thecontains
,doesNotContain
, andhasTags
cases, the code now handles potential type mismatches more gracefully. This improvement directly addresses the issue mentioned in the PR title regarding CSV import with less than 5 columns, as it allows for more flexible handling of field values that may not always be strings.The modifications are consistent, well-implemented, and improve the overall reliability of the condition evaluation process. These changes should help prevent potential bugs related to type coercion in string comparisons.
packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx (3)
Line range hint
1-1006
: Summary of changes and recommendationsThe main change in this PR is the introduction of the
stripCsvImportTransaction
function to process transactions in thegetInitialMappings
function. This change aims to fix the issue with CSV imports containing less than 5 columns.Next steps and recommendations:
- Thoroughly test the CSV import functionality with various column counts to ensure the fix works as intended and doesn't introduce any regressions.
- Consider adding or updating unit tests to cover the new functionality and edge cases.
- In future iterations, consider refactoring this large component into smaller, more manageable pieces to improve maintainability.
- Update the documentation to reflect any changes in the CSV import behavior, if necessary.
Overall, the changes look good and are focused on addressing the specific issue mentioned in the PR objective.
63-63
: Verify CSV import functionality with various column countsTo ensure that the changes effectively address the issue of importing CSV files with less than 5 columns, we should test the import functionality with various CSV files containing different numbers of columns.
Consider adding the following test cases:
- CSV file with 3 columns
- CSV file with 4 columns
- CSV file with 5 columns
- CSV file with more than 5 columns
These tests will help verify that the
stripCsvImportTransaction
function correctly handles different column counts without breaking existing functionality.If no existing tests are found, consider adding new test cases to cover these scenarios.
63-63
: 💡 Codebase verificationUtilize the new
stripCsvImportTransaction
utility function.The
stripCsvImportTransaction
function is now used to process the first transaction before deriving field mappings. This change aligns with the PR objective of fixing CSV imports with less than 5 columns.However, to ensure this change doesn't introduce any regressions, we should verify its impact on the rest of the codebase.
Let's check for other usages of
getInitialMappings
:✅ Verification successful
Correct the shell script to successfully search for
getInitialMappings
usages.It appears there was a syntax error in the previous shell script. Please run the following corrected script to search for other usages of
getInitialMappings
:
Confirmed:
getInitialMappings
is used only withinImportTransactionsModal.jsx
.No additional usages found, ensuring that the changes remain isolated and should not introduce regressions elsewhere.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for other usages of getInitialMappings rg "getInitialMappings" --type jsLength of output: 120
Script:
#!/bin/bash # Search for other usages of getInitialMappings rg "getInitialMappings" --type jsLength of output: 474
packages/desktop-client/src/components/modals/ImportTransactionsModal/FieldMappings.jsx
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for jumping on to this! Just a couple of nits
packages/desktop-client/src/components/modals/ImportTransactionsModal/FieldMappings.jsx
Show resolved
Hide resolved
Co-authored-by: Matt Fiddaman <github@m.fiddaman.uk>
packages/desktop-client/src/components/modals/ImportTransactionsModal/FieldMappings.jsx
Outdated
Show resolved
Hide resolved
…nsModal/FieldMappings.jsx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this!
broken csv before:
CSV import actual issue.csv