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 29, 2025
1 parent aef48d2 commit d44da4a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 deletions.
17 changes: 7 additions & 10 deletions packages/desktop-client/src/components/banksync/AccountRow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import React, { memo } from 'react';
import { Trans } from 'react-i18next';

Expand All @@ -10,19 +9,17 @@ import { theme } from '../../style';
import { Button } from '../common/Button2';
import { Row, Cell } from '../table';

const tsToString = (ts, dateFormat) => {
const tsToString = (ts: string | null, dateFormat: string) => {
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 = {
account: AccountEntity;
hovered: boolean;
onHover: (id: AccountEntity['id']) => void;
onHover: (id: AccountEntity['id'] | null) => void;
onAction: (account: AccountEntity, action: 'link' | 'edit') => void;
};

Expand All @@ -48,7 +45,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 +54,7 @@ export const AccountRow = memo(
</Cell>

<Cell
name="stage"
name="bankName"
width="flex"
plain
style={{ color: theme.tableText, padding: '10px' }}
Expand All @@ -66,7 +63,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 @@ -8,8 +8,8 @@ import { AccountRow } from './AccountRow';

type AccountsListProps = {
accounts: AccountEntity[];
hoveredAccount?: string | undefined;
onHover: (id: AccountEntity['id']) => void;
hoveredAccount?: string | null;
onHover: (id: AccountEntity['id'] | null) => void;
onAction: (account: AccountEntity, action: 'link' | 'edit') => void;
};

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
4 changes: 2 additions & 2 deletions packages/desktop-client/src/components/banksync/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function BankSync() {
const dispatch = useDispatch();
const { isNarrowWidth } = useResponsive();

const [hoveredAccount, setHoveredAccount] = useState<AccountEntity['id']>('');
const [hoveredAccount, setHoveredAccount] = useState<AccountEntity['id'] | null>(null);

Check failure on line 46 in packages/desktop-client/src/components/banksync/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `AccountEntity['id']·|·null` with `⏎····AccountEntity['id']·|·null⏎··`

const groupedAccounts = useMemo(() => {
const unsorted = accounts
Expand Down Expand Up @@ -90,7 +90,7 @@ export function BankSync() {
}
};

const onHover = useCallback((id: AccountEntity['id']) => {
const onHover = useCallback((id: AccountEntity['id'] | null) => {
setHoveredAccount(id);
}, []);

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 d44da4a

Please sign in to comment.