Skip to content

Commit

Permalink
Coderabbit
Browse files Browse the repository at this point in the history
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
matt-fidd and coderabbitai[bot] committed Jan 28, 2025
1 parent a4d6565 commit 3dc37f1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
12 changes: 5 additions & 7 deletions packages/desktop-client/src/components/banksync/AccountRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import { Row, Cell } from '../table';
const tsToString = (ts, dateFormat) => {
if (!ts) return 'Unknown';

const tsObj = new Date(parseInt(ts, 10));
const date = format(tsObj, dateFormat);

return `${date} ${tsObj.toLocaleTimeString()}`;
const parsed = new Date(parseInt(ts, 10));
return `${format(parsed, dateFormat)} ${format(parsed, 'HH:mm:ss')}`;
};

type AccountRowProps = {
Expand Down Expand Up @@ -48,7 +46,7 @@ export const AccountRow = memo(
onMouseLeave={() => onHover && onHover(null)}
>
<Cell
name="stage"
name="accountName"
width={250}
plain
style={{ color: theme.tableText, padding: '10px' }}
Expand All @@ -57,7 +55,7 @@ export const AccountRow = memo(
</Cell>

<Cell
name="stage"
name="bankName"
width="flex"
plain
style={{ color: theme.tableText, padding: '10px' }}
Expand All @@ -66,7 +64,7 @@ export const AccountRow = memo(
</Cell>

<Cell
name="stage"
name="lastSync"
width={200}
plain
style={{ color: theme.tableText, padding: '10px' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,13 @@ export function EditSyncAccount({ account }: EditSyncAccountProps) {

const exampleTransaction = useMemo(() => {
const data = transactions?.[0]?.raw_synced_data;
return data ? JSON.parse(data) : undefined;
if (!data) return undefined;
try {
return JSON.parse(data);
} catch (error) {
console.error('Failed to parse transaction data:', error);
return undefined;
}
}, [transactions]);

const onSave = async (close: () => void) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function FieldMapping({
return (
<>
<Select
aria-label={t('Transaction direction')}
options={transactionDirectionOptions.map(x => [x.value, x.label])}
value={transactionDirection}
onChange={newValue =>
Expand Down Expand Up @@ -113,6 +114,9 @@ export function FieldMapping({
</Text>

<Select
aria-label={t('Synced field to map to {{field}}', {
field: field.actualField,
})}
options={field.syncFields.map(({ field }) => [field, field])}
value={mapping.get(field.actualField)}
style={{
Expand Down
24 changes: 17 additions & 7 deletions packages/loot-core/src/server/util/custom-sync-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@ export const mappingsToString = (mapping: Mappings): string =>
),
);

export const mappingsFromString = (str: string): Mappings =>
new Map(
Object.entries(JSON.parse(str)).map(([key, value]) => [
key,
new Map(Object.entries(value as object)),
]),
);
export const mappingsFromString = (str: string): Mappings => {
try {
const parsed = JSON.parse(str);
if (typeof parsed !== 'object' || parsed === null) {
throw new Error('Invalid mapping format');
}
return new Map(
Object.entries(parsed).map(([key, value]) => [
key,
new Map(Object.entries(value as object)),
]),
);
} catch (e) {
const message = e instanceof Error ? e.message : e;
throw new Error(`Failed to parse mapping: ${message}`);
}
};

export const defaultMappings: Mappings = new Map([
[
Expand Down

0 comments on commit 3dc37f1

Please sign in to comment.