Skip to content

Commit

Permalink
fix: csv parser delimiter (#1774)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiBelmo authored Oct 9, 2023
1 parent efba86a commit 3dfe633
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ export default function ImportTransactions({ modalProps, options }) {
// options which are simple post-processing. That means if you
// parsed different files without closing the modal, it wouldn't
// re-read this.
let [csvDelimiter, setCsvDelimiter] = useState(
let [delimiter, setDelimiter] = useState(
prefs[`csv-delimiter-${accountId}`] ||
(filename.endsWith('.tsv') ? '\t' : ','),
);
Expand Down Expand Up @@ -666,7 +666,7 @@ export default function ImportTransactions({ modalProps, options }) {
const fileType = getFileType(options.filename);
const parseOptions = getParseOptions(
fileType,
{ csvDelimiter, hasHeaderRow },
{ delimiter, hasHeaderRow },
{ fallbackMissingPayeeToMemo },
);

Expand Down Expand Up @@ -716,7 +716,7 @@ export default function ImportTransactions({ modalProps, options }) {
const fileType = getFileType(res[0]);
const parseOptions = getParseOptions(
fileType,
{ csvDelimiter, hasHeaderRow },
{ delimiter, hasHeaderRow },
{ fallbackMissingPayeeToMemo },
);

Expand Down Expand Up @@ -787,7 +787,7 @@ export default function ImportTransactions({ modalProps, options }) {
savePrefs({
[`csv-mappings-${accountId}`]: JSON.stringify(fieldMappings),
});
savePrefs({ [`csv-delimiter-${accountId}`]: csvDelimiter });
savePrefs({ [`csv-delimiter-${accountId}`]: delimiter });
}

if (filetype === 'csv' || filetype === 'qif') {
Expand Down Expand Up @@ -966,11 +966,12 @@ export default function ImportTransactions({ modalProps, options }) {
options={[
[',', ','],
[';', ';'],
['|', '|'],
['\t', 'tab'],
]}
value={csvDelimiter}
value={delimiter}
onChange={value => {
setCsvDelimiter(value);
setDelimiter(value);
parse(
filename,
getParseOptions('csv', {
Expand All @@ -990,7 +991,7 @@ export default function ImportTransactions({ modalProps, options }) {
parse(
filename,
getParseOptions('csv', {
delimiter: csvDelimiter,
delimiter,
hasHeaderRow: !hasHeaderRow,
}),
);
Expand Down Expand Up @@ -1070,8 +1071,8 @@ export default function ImportTransactions({ modalProps, options }) {

function getParseOptions(fileType, csvOptions, ofxOptions) {
if (fileType === 'csv') {
const { csvDelimiter, hasHeaderRow } = csvOptions;
return { csvDelimiter, hasHeaderRow };
const { delimiter, hasHeaderRow } = csvOptions;
return { delimiter, hasHeaderRow };
} else if (isOfxFile(fileType)) {
const { fallbackMissingPayeeToMemo } = ofxOptions;
return { fallbackMissingPayeeToMemo };
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/1774.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [KaiBelmo]
---

Fix selecting delimiters in CSV options when uploading a CSV; it will apply to parsing. Also added a new delimiter '|'.

0 comments on commit 3dfe633

Please sign in to comment.