feat(csv): add column mapping for CSV imports#28
Merged
Conversation
Add CanonicalColumn, CSVColumnSchema, CSVColumnMapping, and CSVAutoDetectResult types for mapping arbitrary CSV headers to AssetFlow's expected columns. Add extractHeaders, extractSampleRows, autoDetectMapping, and mapping-based parseAssetCSV/parseCashFlowCSV overloads to CSVParsingService. These enable CSV import without requiring users to manually rename columns. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Shared sheet component for mapping arbitrary CSV column headers to AssetFlow's canonical columns (Asset Name, Market Value, etc.). Displays a full CSV table preview with per-column dropdowns, auto-detects and pre-selects matching columns, validates that all required columns are mapped without duplicates. Uses NavigationStack with toolbar for macOS Liquid Glass integration. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
loadCSVData now auto-detects column headers. If they match the expected canonical columns (case-insensitive), parsing proceeds immediately. If not, the mapping sheet state is populated so the view can present ColumnMappingSheet for user-driven mapping. confirmColumnMapping accepts the user's mapping and parses the CSV using the mapping-based overloads. clearLoadedData resets all mapping state. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add loadCSVForMapping to BulkEntryViewModel that auto-detects CSV headers. If they match, importCSV runs directly. Otherwise, mapping state is populated for ColumnMappingSheet presentation. confirmColumnMapping accepts the user's mapping and imports the parsed rows into the bulk entry table. BulkEntryView now shows ColumnMappingSheet when needed and displays import results after mapping confirmation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Update SPEC.md to replace deferred column mapping note with full description and remove from future features list. Update APIDesign.md with new CSVParsingService methods and column mapping types. Update BusinessLogic.md import flow with auto-detection step. Update UserInterfaceDesign.md with column mapping sheet description. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace force unwrap with optional map and use for-where clause. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…g sheet Add instructional hint text above the CSV table preview. Add padding between CSV content and horizontal scroll bar. Use horizontal-only scroll so the sheet height fits its content dynamically. Add Traditional Chinese (zh-Hant) translations for all column mapping strings in the Import string catalog. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
BulkEntryView imports CSV per-platform, so the platform is already known. Add assetWithoutPlatform schema variant that omits Platform from the mapping options to avoid confusion. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add Column Mapping section to import-csv guide explaining auto- detection, the mapping sheet UI, preselection, validation, and re-mapping. Add tip callout to the file requirements table pointing users to the new section. Add column mapping paragraph to bulk-entry per-platform CSV import section, noting that Platform is excluded from the mapping options. Both English and Traditional Chinese (zh-TW) versions updated. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1. Guard required columns in mapping-based parse methods — return error result instead of silently defaulting to wrong indices. 2. Set selectedFileData at the start of loadCSVData to prevent nil when called directly without loadFile. 3. Refactor importCSV to delegate to importCSVFromParsedRows, eliminating ~60 lines of duplicated matching logic. 4. Add comment explaining intentional triple-decode trade-off (clarity over micro-optimization for small data). 5. Compute duplicateColumns once per render in csvTable, not per pickerCell call. 6. Fix unused variable warning in BulkEntryViewModelTests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a column mapping feature to both ImportView and BulkEntryView that allows users to import CSV files with non-standard column headers without manual renaming. When CSV headers don't match the expected column names, a mapping sheet appears automatically; when they match (case-insensitive), parsing proceeds directly with no extra steps.
Changes
Column mapping types and auto-detection (
CSVParsingTypes.swift,CSVParsingService+ColumnMapping.swift)CanonicalColumn,CSVColumnSchema,CSVColumnMapping, andCSVAutoDetectResulttypesextractHeaders,extractSampleRows,autoDetectMapping, and mapping-basedparseAssetCSV/parseCashFlowCSVoverloadsColumnMappingSheet (
Views/Components/ColumnMappingSheet.swift)NavigationStackwith toolbar for macOS Liquid Glass integrationImportView integration (
ImportViewModel.swift,ImportView.swift)loadCSVDatanow auto-detects headers and shows mapping sheet when neededconfirmColumnMappingparses with the user's mapping and feeds into the existing preview pipelineBulkEntryView integration (
BulkEntryViewModel.swift,BulkEntryView.swift)loadCSVForMappingandconfirmColumnMappingmethodsimportCSVto delegate toimportCSVFromParsedRows, eliminating duplicated logicDocumentation
Testing
CSVColumnMappingTestscoveringextractHeaders,extractSampleRows,autoDetectMapping, mapping-based parsing, and round-trip consistencyImportViewModelTestscovering auto-detect skip, mapping sheet trigger,confirmColumnMapping, partial mapping, cash flow variant, and state cleanupBulkEntryViewModelTestscovering canonical pass-through, non-matching sheet trigger, andconfirmColumnMappingresult🤖 Generated with Claude Code