Fix company cards import crash by transposing spreadsheet data densely - #97573
Open
yusufdeveloper2903 wants to merge 1 commit into
Open
Fix company cards import crash by transposing spreadsheet data densely#97573yusufdeveloper2903 wants to merge 1 commit into
yusufdeveloper2903 wants to merge 1 commit into
Conversation
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.
Explanation of Change
setSpreadsheetDatatransposed the uploaded spreadsheet withfirstRow.map(...).XLSX.utils.sheet_to_json(worksheet, {header: 1})returns rows as sparse arrays — a blank column is left as an array hole, notundefined— andArray.prototype.mapskips holes and re-emits them. So a blank column in the header row produced a hole inIMPORTED_SPREADSHEET.data.The company cards import iterates every column with
for...of, which yieldsundefinedfor a hole (unlikemap), then callscolumn.at(rowIndex). The existing?? ''guards the result of.at(), not the receiver, so it threwTypeError: Cannot read properties of undefined (reading 'at'). SinceimportTransactionsisasyncand passed straight toonPress, it surfaced as the reported unhandled rejection.Fixed at the single producer by building the transpose densely with
Array.from({length: numColumns}, ...), soIMPORTED_SPREADSHEET.dataalways honors its declared rectangularstring[][]type.numColumnsisfirstRow.length, which already counts holes, so for any dense (normal) file the output is identical — only the previously-missing column changes, becoming a real column of empty strings.This also fixes a second symptom: the mapping UI renders columns with
spreadsheetColumns.map(...), which skipped the hole, so users sawN-1columns whilecolumnNameswas generated fromdata.length(N) — the UI and the column role map were out of sync. Every import flow (company cards, tags, categories, per diem, members) reads this samedata, so fixing the producer removes the latent hole risk from all of them without touching any consumer.Added
tests/unit/ImportSpreadsheetTest.tsas a regression test — 3 of its 6 cases fail without this change.Fixed Issues
$ #97101
PROPOSAL: #97101 (comment)
Tests
blank-column.csvwith a blank second column (note the two commas):blank-column.csvIgnorerole (before this fix only 5 were shown and the blank one was silently dropped)TypeError: Cannot read properties of undefined (reading 'at')and nothing was imported)Offline tests
QA Steps
Same as tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
After fix:
REC-20260731191024.mp4