From efba86a72ddf5349a8beb5bb10557bd20d988b8e Mon Sep 17 00:00:00 2001 From: Michael Clark <5285928+MikesGlitch@users.noreply.github.com> Date: Mon, 9 Oct 2023 18:46:29 +0100 Subject: [PATCH 1/2] Maintenance: BudgetSummary & CreateLocalAccount to tsx (#1768) --- .../src/components/autocomplete/Autocomplete.tsx | 2 +- .../src/components/common/InlineField.tsx | 2 +- .../{BudgetSummary.js => BudgetSummary.tsx} | 16 +++++++++++----- ...ateLocalAccount.js => CreateLocalAccount.tsx} | 11 +++++++++-- upcoming-release-notes/1768.md | 6 ++++++ 5 files changed, 28 insertions(+), 9 deletions(-) rename packages/desktop-client/src/components/modals/{BudgetSummary.js => BudgetSummary.tsx} (86%) rename packages/desktop-client/src/components/modals/{CreateLocalAccount.js => CreateLocalAccount.tsx} (93%) create mode 100644 upcoming-release-notes/1768.md diff --git a/packages/desktop-client/src/components/autocomplete/Autocomplete.tsx b/packages/desktop-client/src/components/autocomplete/Autocomplete.tsx index 8a903955dfc..f6ea70b82d7 100644 --- a/packages/desktop-client/src/components/autocomplete/Autocomplete.tsx +++ b/packages/desktop-client/src/components/autocomplete/Autocomplete.tsx @@ -164,7 +164,7 @@ type SingleAutocompleteProps = { openOnFocus?: boolean; getHighlightedIndex?: (suggestions) => number | null; highlightFirst?: boolean; - onUpdate: (id: unknown, value: string) => void; + onUpdate?: (id: unknown, value: string) => void; strict?: boolean; onSelect: (id: unknown, value: string) => void; tableBehavior?: boolean; diff --git a/packages/desktop-client/src/components/common/InlineField.tsx b/packages/desktop-client/src/components/common/InlineField.tsx index 285191ff871..0a31f198651 100644 --- a/packages/desktop-client/src/components/common/InlineField.tsx +++ b/packages/desktop-client/src/components/common/InlineField.tsx @@ -8,7 +8,7 @@ type InlineFieldProps = { label: ReactNode; labelWidth?: number; children?: ReactNode; - width: number; + width: number | string; style?: CSSProperties; }; diff --git a/packages/desktop-client/src/components/modals/BudgetSummary.js b/packages/desktop-client/src/components/modals/BudgetSummary.tsx similarity index 86% rename from packages/desktop-client/src/components/modals/BudgetSummary.js rename to packages/desktop-client/src/components/modals/BudgetSummary.tsx index d4f3a82cba6..34aa66fe137 100644 --- a/packages/desktop-client/src/components/modals/BudgetSummary.js +++ b/packages/desktop-client/src/components/modals/BudgetSummary.tsx @@ -1,9 +1,10 @@ import React from 'react'; import { rolloverBudget } from 'loot-core/src/client/queries'; -import * as monthUtils from 'loot-core/src/shared/months'; +import { format, sheetForMonth, prevMonth } from 'loot-core/src/shared/months'; import { theme, styles } from '../../style'; +import { type CommonModalProps } from '../../types/modals'; import Button from '../common/Button'; import Modal from '../common/Modal'; import Text from '../common/Text'; @@ -35,13 +36,18 @@ function ToBudget({ toBudget }) { ); } -function BudgetSummary({ month, modalProps }) { - const prevMonthName = monthUtils.format(monthUtils.prevMonth(month), 'MMM'); +type BudgetSummaryProps = { + modalProps: CommonModalProps; + month: string; +}; + +function BudgetSummary({ month, modalProps }: BudgetSummaryProps) { + const prevMonthName = format(prevMonth(month), 'MMM'); return ( - + {() => ( - + !isNaN(parseFloat(balance)); return ( - + {() => (
Date: Mon, 9 Oct 2023 21:49:54 +0200 Subject: [PATCH 2/2] fix: csv parser delimiter (#1774) --- .../components/modals/ImportTransactions.js | 19 ++++++++++--------- upcoming-release-notes/1774.md | 6 ++++++ 2 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 upcoming-release-notes/1774.md diff --git a/packages/desktop-client/src/components/modals/ImportTransactions.js b/packages/desktop-client/src/components/modals/ImportTransactions.js index 309916656a1..e9f27f5c80a 100644 --- a/packages/desktop-client/src/components/modals/ImportTransactions.js +++ b/packages/desktop-client/src/components/modals/ImportTransactions.js @@ -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' : ','), ); @@ -666,7 +666,7 @@ export default function ImportTransactions({ modalProps, options }) { const fileType = getFileType(options.filename); const parseOptions = getParseOptions( fileType, - { csvDelimiter, hasHeaderRow }, + { delimiter, hasHeaderRow }, { fallbackMissingPayeeToMemo }, ); @@ -716,7 +716,7 @@ export default function ImportTransactions({ modalProps, options }) { const fileType = getFileType(res[0]); const parseOptions = getParseOptions( fileType, - { csvDelimiter, hasHeaderRow }, + { delimiter, hasHeaderRow }, { fallbackMissingPayeeToMemo }, ); @@ -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') { @@ -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', { @@ -990,7 +991,7 @@ export default function ImportTransactions({ modalProps, options }) { parse( filename, getParseOptions('csv', { - delimiter: csvDelimiter, + delimiter, hasHeaderRow: !hasHeaderRow, }), ); @@ -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 }; diff --git a/upcoming-release-notes/1774.md b/upcoming-release-notes/1774.md new file mode 100644 index 00000000000..1ad0be8ce55 --- /dev/null +++ b/upcoming-release-notes/1774.md @@ -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 '|'. \ No newline at end of file