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

feat: add "last reconciled" timestamp to accounts #4459

Merged
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
14 changes: 14 additions & 0 deletions packages/desktop-client/src/components/accounts/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,13 @@ class AccountInternal extends PureComponent<

onDoneReconciling = async () => {
const { accountId } = this.props;
const account = this.props.accounts.find(
account => account.id === accountId,
);
if (!account) {
throw new Error(`Account with ID ${accountId} not found.`);
}

const { reconcileAmount } = this.state;

const { data } = await runQuery(
Expand All @@ -1034,6 +1041,13 @@ class AccountInternal extends PureComponent<
await this.lockTransactions();
}

const lastReconciled = new Date().getTime().toString();
this.props.dispatch(
updateAccount({
account: { ...account, last_reconciled: lastReconciled },
}),
);

this.setState({
reconcileAmount: null,
showCleared: this.state.prevShowCleared,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export function Balances({
}}
/>
</Button>

{showExtraBalances && <MoreBalances balanceQuery={balanceQuery} />}

{selectedItems.size > 0 && (
Expand Down
29 changes: 24 additions & 5 deletions packages/desktop-client/src/components/accounts/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ import { Menu } from '@actual-app/components/menu';
import { Popover } from '@actual-app/components/popover';
import { Stack } from '@actual-app/components/stack';
import { styles } from '@actual-app/components/styles';
import { Tooltip } from '@actual-app/components/tooltip';
import { View } from '@actual-app/components/view';

import { tsToRelativeTime } from 'loot-core/shared/util';
import {
type AccountEntity,
type RuleConditionEntity,
type TransactionEntity,
type TransactionFilterEntity,
} from 'loot-core/types/models';

import { useGlobalPref } from '../../hooks/useGlobalPref';
import { useLocalPref } from '../../hooks/useLocalPref';
import { useSplitsExpanded } from '../../hooks/useSplitsExpanded';
import { useSyncServerStatus } from '../../hooks/useSyncServerStatus';
Expand Down Expand Up @@ -185,6 +188,8 @@ export function AccountHeader({
onMakeAsNonSplitTransactions,
}: AccountHeaderProps) {
const { t } = useTranslation();
const [language] = useGlobalPref('language');

const [menuOpen, setMenuOpen] = useState(false);
const [reconcileOpen, setReconcileOpen] = useState(false);
const searchInput = useRef<HTMLInputElement>(null);
Expand Down Expand Up @@ -374,19 +379,33 @@ export function AccountHeader({
onMakeAsNonSplitTransactions={onMakeAsNonSplitTransactions}
/>
)}
<View style={{ flex: '0 0 auto' }}>
<View style={{ flex: '0 0 auto', marginLeft: 10 }}>
{account && (
<>
<Tooltip
style={{
...styles.tooltip,
marginBottom: 10,
}}
content={
account?.last_reconciled
? `${t('Reconciled')} ${tsToRelativeTime(account.last_reconciled, language || 'en-US')}`
: t('Not yet reconciled')
}
placement="top"
triggerProps={{
isDisabled: reconcileOpen,
}}
>
<Button
ref={reconcileRef}
variant="bare"
aria-label={t('Reconcile')}
style={{ padding: 6, marginLeft: 10 }}
style={{ padding: 6 }}
onPress={() => {
setReconcileOpen(true);
}}
>
<View title={t('Reconcile')}>
<View>
<SvgLockClosed width={14} height={14} />
</View>
</Button>
Expand All @@ -403,7 +422,7 @@ export function AccountHeader({
onReconcile={onReconcile}
/>
</Popover>
</>
</Tooltip>
)}
</View>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type Spreadsheets = {
'offbudget-accounts-balance': number;
balanceCleared: number;
balanceUncleared: number;
lastReconciled: string | null;
};
category: {
// Common fields
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN TRANSACTION;

ALTER TABLE accounts ADD COLUMN last_reconciled text;

COMMIT;
1 change: 1 addition & 0 deletions packages/loot-core/src/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function generateAccount(
name,
offbudget: offbudget ? 1 : 0,
sort_order: 0,
last_reconciled: null,
tombstone: 0,
closed: 0,
...emptySyncFields(),
Expand Down
13 changes: 11 additions & 2 deletions packages/loot-core/src/server/accounts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,17 @@ export type AccountHandlers = {
'account-unlink': typeof unlinkAccount;
};

async function updateAccount({ id, name }: Pick<AccountEntity, 'id' | 'name'>) {
await db.update('accounts', { id, name });
async function updateAccount({
id,
name,
last_reconciled,
}: Pick<AccountEntity, 'id' | 'name'> &
Partial<Pick<AccountEntity, 'last_reconciled'>>) {
await db.update('accounts', {
id,
name,
...(last_reconciled && { last_reconciled }),
});
return {};
}

Expand Down
1 change: 1 addition & 0 deletions packages/loot-core/src/server/aql/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const schema = {
account_id: f('string'),
official_name: f('string'),
account_sync_source: f('string'),
last_reconciled: f('string'),
last_sync: f('string'),
},
categories: {
Expand Down
16 changes: 16 additions & 0 deletions packages/loot-core/src/shared/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @ts-strict-ignore
import { formatDistanceToNow } from 'date-fns';
import * as locales from 'date-fns/locale';

export function last<T>(arr: Array<T>) {
return arr[arr.length - 1];
}
Expand Down Expand Up @@ -481,3 +484,16 @@ export function sortByKey<T>(arr: T[], key: keyof T): T[] {
return 0;
});
}

// Date utilities

export function tsToRelativeTime(ts: string | null, language: string): string {
if (!ts) return 'Unknown';

const parsed = new Date(parseInt(ts, 10));
const locale =
locales[language.replace('-', '') as keyof typeof locales] ??
locales['enUS'];

return formatDistanceToNow(parsed, { addSuffix: true, locale });
}
1 change: 1 addition & 0 deletions packages/loot-core/src/types/models/account.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type AccountEntity = {
offbudget: 0 | 1;
closed: 0 | 1;
sort_order: number;
last_reconciled: string | null;
tombstone: 0 | 1;
} & (_SyncFields<true> | _SyncFields<false>);

Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/4459.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Features
authors: [tostasmistas]
---

Add "last reconciled" timestamp to accounts