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

fix: csv parser delimiter #1774

Merged
merged 8 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 };
MatissJanis marked this conversation as resolved.
Show resolved Hide resolved
} 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 '|'.