Skip to content

A local-first personal finance app

:recycle: (typescript) migrated account header to TS (#3640)

Matiss Janis Aboltins9aac44c58f78
diff --git a/packages/desktop-client/src/components/accounts/Account.tsx b/packages/desktop-client/src/components/accounts/Account.tsx
index 0a623e3528..1a8009db0b 100644
--- a/packages/desktop-client/src/components/accounts/Account.tsx
+++ b/packages/desktop-client/src/components/accounts/Account.tsx
@@ -68,6 +68,7 @@ import { styles, theme } from '../../style';
import { Button } from '../common/Button2';
import { Text } from '../common/Text';
import { View } from '../common/View';
+import { type SavedFilter } from '../filters/SavedFilterMenuButton';
import { TransactionList } from '../transactions/TransactionList';
import { validateAccountName } from '../util/accountValidation';
@@ -283,7 +284,7 @@ type AccountInternalProps = {
type AccountInternalState = {
search: string;
filterConditions: ConditionEntity[];
- filterId: Record<string, unknown>;
+ filterId?: SavedFilter;
filterConditionsOp: 'and' | 'or';
loading: boolean;
workingHard: boolean;
@@ -309,6 +310,14 @@ type AccountInternalState = {
filteredAmount: null | number;
};
+export type TableRef = MutableRefObject<{
+ edit: (updatedId: string | null, op?: string, someBool?: boolean) => void;
+ setRowAnimation: (animation: boolean) => void;
+ scrollTo: (focusId: string) => void;
+ scrollToTop: () => void;
+ getScrolledItem: () => string;
+} | null>;
+
class AccountInternal extends PureComponent<
AccountInternalProps,
AccountInternalState
@@ -316,12 +325,7 @@ class AccountInternal extends PureComponent<
paged: ReturnType<typeof pagedQuery> | null;
rootQuery: Query;
currentQuery: Query;
- table: MutableRefObject<{
- edit: (updatedId: string | null, op?: string, someBool?: boolean) => void;
- setRowAnimation: (animation: boolean) => void;
- scrollTo: (focusId: string) => void;
- scrollToTop: () => void;
- } | null>;
+ table: TableRef;
unlisten?: () => void;
dispatchSelected?: (action: Actions) => void;
@@ -333,7 +337,7 @@ class AccountInternal extends PureComponent<
this.state = {
search: '',
filterConditions: props.filterConditions || [],
- filterId: {},
+ filterId: undefined,
filterConditionsOp: 'and',
loading: true,
workingHard: false,
@@ -859,7 +863,7 @@ class AccountInternal extends PureComponent<
return {
name: `balance-query-${id}`,
query: this.makeRootQuery().calculate({ $sum: '$amount' }),
- };
+ } as const;
}
getFilteredAmount = async () => {
@@ -1307,13 +1311,10 @@ class AccountInternal extends PureComponent<
}
};
- onReloadSavedFilter = (
- savedFilter: TransactionFilterEntity & { status?: string },
- item: string,
- ) => {
+ onReloadSavedFilter = (savedFilter: SavedFilter, item: string) => {
if (item === 'reload') {
const [savedFilter] = this.props.savedFilters.filter(
- f => f.id === this.state.filterId.id,
+ f => f.id === this.state.filterId?.id,
);
this.setState({ filterConditionsOp: savedFilter.conditionsOp ?? 'and' });
this.applyFilters([...savedFilter.conditions]);
@@ -1330,7 +1331,7 @@ class AccountInternal extends PureComponent<
onClearFilters = () => {
this.setState({ filterConditionsOp: 'and' });
- this.setState({ filterId: {} });
+ this.setState({ filterId: undefined });
this.applyFilters([]);
if (this.state.search !== '') {
this.onSearch(this.state.search);
@@ -1360,7 +1361,7 @@ class AccountInternal extends PureComponent<
onDeleteFilter = (condition: RuleConditionEntity) => {
this.applyFilters(this.state.filterConditions.filter(c => c !== condition));
if (this.state.filterConditions.length === 1) {
- this.setState({ filterId: {} });
+ this.setState({ filterId: undefined });
this.setState({ filterConditionsOp: 'and' });
} else {
this.setState({
@@ -1715,9 +1716,9 @@ class AccountInternal extends PureComponent<
isSorted={this.state.sort !== null}
reconcileAmount={reconcileAmount}
search={this.state.search}
+ // @ts-expect-error fix me
filterConditions={this.state.filterConditions}
filterConditionsOp={this.state.filterConditionsOp}
- pushModal={this.props.pushModal}
onSearch={this.onSearch}
onShowTransactions={this.onShowTransactions}
onMenuSelect={this.onMenuSelect}
diff --git a/packages/desktop-client/src/components/accounts/Header.jsx b/packages/desktop-client/src/components/accounts/Header.tsx
similarity index 72%
rename from packages/desktop-client/src/components/accounts/Header.jsx
rename to packages/desktop-client/src/components/accounts/Header.tsx
index 319d8251f2..f0b8be52ab 100644
--- a/packages/desktop-client/src/components/accounts/Header.jsx
+++ b/packages/desktop-client/src/components/accounts/Header.tsx
@@ -1,7 +1,20 @@
-import React, { useState, useRef, Fragment } from 'react';
+import React, {
+ useState,
+ useRef,
+ Fragment,
+ type ReactNode,
+ type ComponentProps,
+} from 'react';
import { useHotkeys } from 'react-hotkeys-hook';
import { Trans, useTranslation } from 'react-i18next';
+import {
+ type AccountEntity,
+ type RuleConditionEntity,
+ type TransactionEntity,
+ type TransactionFilterEntity,
+} from 'loot-core/types/models';
+
import { useLocalPref } from '../../hooks/useLocalPref';
import { useSplitsExpanded } from '../../hooks/useSplitsExpanded';
import { useSyncServerStatus } from '../../hooks/useSyncServerStatus';
@@ -26,12 +39,89 @@ import { Stack } from '../common/Stack';
import { View } from '../common/View';
import { FilterButton } from '../filters/FiltersMenu';
import { FiltersStack } from '../filters/FiltersStack';
+import { type SavedFilter } from '../filters/SavedFilterMenuButton';
import { NotesButton } from '../NotesButton';
import { SelectedTransactionsButton } from '../transactions/SelectedTransactionsButton';
+import { type TableRef } from './Account';
import { Balances } from './Balance';
import { ReconcilingMessage, ReconcileMenu } from './Reconcile';
+type AccountHeaderProps = {
+ tableRef: TableRef;
+ editingName: boolean;
+ isNameEditable: boolean;
+ workingHard: boolean;
+ accountName: string;
+ account: AccountEntity;
+ filterId?: SavedFilter;
+ savedFilters: TransactionFilterEntity[];
+ accountsSyncing: string[];
+ failedAccounts: AccountSyncSidebarProps['failedAccounts'];
+ accounts: AccountEntity[];
+ transactions: TransactionEntity[];
+ showBalances: boolean;
+ showExtraBalances: boolean;
+ showCleared: boolean;
+ showReconciled: boolean;
+ showEmptyMessage: boolean;
+ balanceQuery: ComponentProps<typeof ReconcilingMessage>['balanceQuery'];
+ reconcileAmount: number;
+ canCalculateBalance: () => boolean;
+ isFiltered: boolean;
+ filteredAmount: number;
+ isSorted: boolean;
+ search: string;
+ filterConditions: RuleConditionEntity[];
+ filterConditionsOp: 'and' | 'or';
+ onSearch: (newSearch: string) => void;
+ onAddTransaction: () => void;
+ onShowTransactions: ComponentProps<
+ typeof SelectedTransactionsButton
+ >['onShow'];
+ onDoneReconciling: ComponentProps<typeof ReconcilingMessage>['onDone'];
+ onCreateReconciliationTransaction: ComponentProps<
+ typeof ReconcilingMessage
+ >['onCreateTransaction'];
+ onToggleExtraBalances: ComponentProps<
+ typeof Balances
+ >['onToggleExtraBalances'];
+ onSaveName: AccountNameFieldProps['onSaveName'];
+ saveNameError: AccountNameFieldProps['saveNameError'];
+ onExposeName: (isExposed: boolean) => void;
+ onSync: () => void;
+ onImport: () => void;
+ onMenuSelect: AccountMenuProps['onMenuSelect'];
+ onReconcile: AccountMenuProps['onReconcile'];
+ onBatchEdit: ComponentProps<typeof SelectedTransactionsButton>['onEdit'];
+ onBatchDelete: ComponentProps<typeof SelectedTransactionsButton>['onDelete'];
+ onBatchDuplicate: ComponentProps<
+ typeof SelectedTransactionsButton
+ >['onDuplicate'];
+ onBatchLinkSchedule: ComponentProps<
+ typeof SelectedTransactionsButton
+ >['onLinkSchedule'];
+ onBatchUnlinkSchedule: ComponentProps<
+ typeof SelectedTransactionsButton
+ >['onUnlinkSchedule'];
+ onApplyFilter: (filter: RuleConditionEntity) => void;
+} & Pick<
+ ComponentProps<typeof SelectedTransactionsButton>,
+ | 'onCreateRule'
+ | 'onScheduleAction'
+ | 'onSetTransfer'
+ | 'onMakeAsSplitTransaction'
+ | 'onMakeAsNonSplitTransactions'
+> &
+ Pick<
+ ComponentProps<typeof FiltersStack>,
+ | 'onUpdateFilter'
+ | 'onDeleteFilter'
+ | 'onConditionsOpChange'
+ | 'onClearFilters'
+ | 'onReloadSavedFilter'
+ >;
+
export function AccountHeader({
tableRef,
editingName,
@@ -59,7 +149,6 @@ export function AccountHeader({
search,
filterConditions,
filterConditionsOp,
- pushModal,
onSearch,
onAddTransaction,
onShowTransactions,
@@ -89,10 +178,10 @@ export function AccountHeader({
onSetTransfer,
onMakeAsSplitTransaction,
onMakeAsNonSplitTransactions,
-}) {
+}: AccountHeaderProps) {
const { t } = useTranslation();
const [menuOpen, setMenuOpen] = useState(false);
- const searchInput = useRef(null);
+ const searchInput = useRef<HTMLInputElement>(null);
const triggerRef = useRef(null);
const splitsExpanded = useSplitsExpanded();
const syncServerStatus = useSyncServerStatus();
@@ -100,7 +189,7 @@ export function AccountHeader({
const isServerOffline = syncServerStatus === 'offline';
const [_, setExpandSplitsPref] = useLocalPref('expand-splits');
- let canSync = account && account.account_id && isUsingServer;
+ let canSync = !!(account?.account_id && isUsingServer);
if (!account) {
// All accounts - check for any syncable account
canSync = !!accounts.find(account => !!account.account_id) && isUsingServer;
@@ -223,7 +312,6 @@ export function AccountHeader({
? accountsSyncing.includes(account.id)
: accountsSyncing.length > 0
}
- style={{ marginRight: 4 }}
/>{' '}
{isServerOffline ? t('Bank Sync Offline') : t('Bank Sync')}
</Button>
@@ -247,7 +335,8 @@ export function AccountHeader({
</Button>
)}
<View style={{ flexShrink: 0 }}>
- <FilterButton onApply={onApplyFilter} type="accounts" />
+ {/* @ts-expect-error fix me */}
+ <FilterButton onApply={onApplyFilter} />
</View>
<View style={{ flex: 1 }} />
<Search
@@ -262,7 +351,6 @@ export function AccountHeader({
</View>
) : (
<SelectedTransactionsButton
- account={account}
getTransaction={id => transactions.find(t => t.id === id)}
onShow={onShowTransactions}
onDuplicate={onBatchDuplicate}
@@ -273,7 +361,6 @@ export function AccountHeader({
onCreateRule={onCreateRule}
onSetTransfer={onSetTransfer}
onScheduleAction={onScheduleAction}
- pushModal={pushModal}
showMakeTransfer={showMakeTransfer}
onMakeAsSplitTransaction={onMakeAsSplitTransaction}
onMakeAsNonSplitTransactions={onMakeAsNonSplitTransactions}
@@ -354,10 +441,14 @@ export function AccountHeader({
onMenuSelect(item);
}}
items={[
- isSorted && {
- name: 'remove-sorting',
- text: t('Remove all sorting'),
- },
+ ...(isSorted
+ ? [
+ {
+ name: 'remove-sorting',
+ text: t('Remove all sorting'),
+ } as const,
+ ]
+ : []),
{ name: 'export', text: t('Export') },
]}
/>
@@ -392,7 +483,23 @@ export function AccountHeader({
);
}
-function AccountSyncSidebar({ account, failedAccounts, accountsSyncing }) {
+type AccountSyncSidebarProps = {
+ account: AccountEntity;
+ failedAccounts: Map<
+ string,
+ {
+ type: string;
+ code: string;
+ }
+ >;
+ accountsSyncing: string[];
+};
+
+function AccountSyncSidebar({
+ account,
+ failedAccounts,
+ accountsSyncing,
+}: AccountSyncSidebarProps) {
return (
<View
style={{
@@ -410,6 +517,16 @@ function AccountSyncSidebar({ account, failedAccounts, accountsSyncing }) {
);
}
+type AccountNameFieldProps = {
+ account: AccountEntity;
+ accountName: string;
+ isNameEditable: boolean;
+ editingName: boolean;
+ saveNameError?: ReactNode;
+ onSaveName: (newName: string) => void;
+ onExposeName: (isExposed: boolean) => void;
+};
+
function AccountNameField({
account,
accountName,
@@ -418,7 +535,7 @@ function AccountNameField({
saveNameError,
onSaveName,
onExposeName,
-}) {
+}: AccountNameFieldProps) {
const { t } = useTranslation();
if (editingName) {
@@ -427,7 +544,7 @@ function AccountNameField({
<InitialFocus>
<Input
defaultValue={accountName}
- onEnter={e => onSaveName(e.target.value)}
+ onEnter={e => onSaveName(e.currentTarget.value)}
onBlur={e => onSaveName(e.target.value)}
onEscape={() => onExposeName(false)}
style={{
@@ -515,6 +632,30 @@ function AccountNameField({
}
}
+type AccountMenuProps = {
+ account: AccountEntity;
+ canSync: boolean;
+ showBalances: boolean;
+ canShowBalances: boolean;
+ showCleared: boolean;
+ showReconciled: boolean;
+ onClose: ComponentProps<typeof ReconcileMenu>['onClose'];
+ isSorted: boolean;
+ onReconcile: ComponentProps<typeof ReconcileMenu>['onReconcile'];
+ onMenuSelect: (
+ item:
+ | 'link'
+ | 'unlink'
+ | 'close'
+ | 'reopen'
+ | 'export'
+ | 'toggle-balance'
+ | 'remove-sorting'
+ | 'toggle-cleared'
+ | 'toggle-reconciled',
+ ) => void;
+};
+
function AccountMenu({
account,
canSync,
@@ -526,7 +667,7 @@ function AccountMenu({
isSorted,
onReconcile,
onMenuSelect,
-}) {
+}: AccountMenuProps) {
const { t } = useTranslation();
const [tooltip, setTooltip] = useState('default');
const syncServerStatus = useSyncServerStatus();
@@ -547,16 +688,24 @@ function AccountMenu({
}
}}
items={[
- isSorted && {
- name: 'remove-sorting',
- text: t('Remove all sorting'),
- },
- canShowBalances && {
- name: 'toggle-balance',
- text: showBalances
- ? t('Hide running balance')
- : t('Show running balance'),
- },
+ ...(isSorted
+ ? [
+ {
+ name: 'remove-sorting',
+ text: t('Remove all sorting'),
+ } as const,
+ ]
+ : []),
+ ...(canShowBalances
+ ? [
+ {
+ name: 'toggle-balance',
+ text: showBalances
+ ? t('Hide running balance')
+ : t('Show running balance'),
+ } as const,
+ ]
+ : []),
{
name: 'toggle-cleared',
text: showCleared
@@ -571,21 +720,28 @@ function AccountMenu({
},
{ name: 'export', text: t('Export') },
{ name: 'reconcile', text: t('Reconcile') },
- account &&
- !account.closed &&
- (canSync
- ? {
- name: 'unlink',
- text: t('Unlink account'),
- }
- : syncServerStatus === 'online' && {
- name: 'link',
- text: t('Link account'),
- }),
- account.closed
- ? { name: 'reopen', text: t('Reopen account') }
- : { name: 'close', text: t('Close account') },
- ].filter(x => x)}
+ ...(account && !account.closed
+ ? canSync
+ ? [
+ {
+ name: 'unlink',
+ text: t('Unlink account'),
+ } as const,
+ ]
+ : syncServerStatus === 'online'
+ ? [
+ {
+ name: 'link',
+ text: t('Link account'),
+ } as const,
+ ]
+ : []
+ : []),
+
+ ...(account.closed
+ ? [{ name: 'reopen', text: t('Reopen account') } as const]
+ : [{ name: 'close', text: t('Close account') } as const]),
+ ]}
/>
);
}
diff --git a/packages/desktop-client/src/components/filters/FilterMenu.tsx b/packages/desktop-client/src/components/filters/FilterMenu.tsx
index c3adb2048e..94d389998c 100644
--- a/packages/desktop-client/src/components/filters/FilterMenu.tsx
+++ b/packages/desktop-client/src/components/filters/FilterMenu.tsx
@@ -9,7 +9,7 @@ export function FilterMenu({
filterId,
onFilterMenuSelect,
}: {
- filterId: SavedFilter;
+ filterId?: SavedFilter;
onFilterMenuSelect: (item: string) => void;
}) {
const { t } = useTranslation();
@@ -20,12 +20,12 @@ export function FilterMenu({
onFilterMenuSelect(item);
}}
items={
- !filterId.id
+ !filterId?.id
? [
{ name: 'save-filter', text: t('Save new filter') },
{ name: 'clear-filter', text: t('Clear all conditions') },
]
- : filterId.id !== null && filterId.status === 'saved'
+ : filterId?.id !== null && filterId?.status === 'saved'
? [
{ name: 'rename-filter', text: t('Rename') },
{ name: 'delete-filter', text: t('Delete') },
diff --git a/packages/desktop-client/src/components/filters/FiltersStack.tsx b/packages/desktop-client/src/components/filters/FiltersStack.tsx
index ec639437e0..f145c78686 100644
--- a/packages/desktop-client/src/components/filters/FiltersStack.tsx
+++ b/packages/desktop-client/src/components/filters/FiltersStack.tsx
@@ -32,7 +32,7 @@ export function FiltersStack({
onDeleteFilter: (filter: RuleConditionEntity) => void;
onClearFilters: () => void;
onReloadSavedFilter: (savedFilter: SavedFilter, value?: string) => void;
- filterId: SavedFilter;
+ filterId?: SavedFilter;
savedFilters: TransactionFilterEntity[];
onConditionsOpChange: (value: 'and' | 'or') => void;
}) {
diff --git a/packages/desktop-client/src/components/filters/SavedFilterMenuButton.tsx b/packages/desktop-client/src/components/filters/SavedFilterMenuButton.tsx
index bd42f61ead..d6fd2e1002 100644
--- a/packages/desktop-client/src/components/filters/SavedFilterMenuButton.tsx
+++ b/packages/desktop-client/src/components/filters/SavedFilterMenuButton.tsx
@@ -32,7 +32,7 @@ export function SavedFilterMenuButton({
}: {
conditions: RuleConditionEntity[];
conditionsOp: 'and' | 'or';
- filterId: SavedFilter;
+ filterId?: SavedFilter;
onClearFilters: () => void;
onReloadSavedFilter: (savedFilter: SavedFilter, value?: string) => void;
savedFilters: TransactionFilterEntity[];
@@ -44,8 +44,8 @@ export function SavedFilterMenuButton({
const triggerRef = useRef(null);
const [err, setErr] = useState(null);
const [menuItem, setMenuItem] = useState('');
- const [name, setName] = useState(filterId.name);
- const id = filterId.id;
+ const [name, setName] = useState(filterId?.name ?? '');
+ const id = filterId?.id;
let savedFilter: SavedFilter;
const onFilterMenuSelect = async (item: string) => {
@@ -69,8 +69,8 @@ export function SavedFilterMenuButton({
savedFilter = {
conditions,
conditionsOp,
- id: filterId.id,
- name: filterId.name,
+ id: filterId?.id,
+ name: filterId?.name ?? '',
status: 'saved',
};
const response = await sendCatch('filter-update', {
@@ -137,9 +137,9 @@ export function SavedFilterMenuButton({
}
const updatedFilter = {
- conditions: filterId.conditions,
- conditionsOp: filterId.conditionsOp,
- id: filterId.id,
+ conditions: filterId?.conditions,
+ conditionsOp: filterId?.conditionsOp,
+ id: filterId?.id,
name,
};
@@ -178,9 +178,9 @@ export function SavedFilterMenuButton({
flexShrink: 0,
}}
>
- {!filterId.id ? t('Unsaved filter') : filterId.name}&nbsp;
+ {!filterId?.id ? t('Unsaved filter') : filterId?.name}&nbsp;
</Text>
- {filterId.id && filterId.status !== 'saved' && (
+ {filterId?.id && filterId?.status !== 'saved' && (
<Text>
<Trans>(modified)</Trans>&nbsp;
</Text>
diff --git a/packages/desktop-client/src/components/table.tsx b/packages/desktop-client/src/components/table.tsx
index 68ba75b353..a253acd89c 100644
--- a/packages/desktop-client/src/components/table.tsx
+++ b/packages/desktop-client/src/components/table.tsx
@@ -811,19 +811,19 @@ export function TableHeader({
);
}
-type SelectedItemsButtonProps<T extends MenuItem = MenuItem> = {
+type SelectedItemsButtonProps<Name extends string> = {
id: string;
name: ((count: number) => string) | string;
- items: Array<T | typeof Menu.line>;
- onSelect: (name: string, items: Array<string>) => void;
+ items: MenuItem<Name>[];
+ onSelect: (name: Name, items: string[]) => void;
};
-export function SelectedItemsButton<T extends MenuItem = MenuItem>({
+export function SelectedItemsButton<Name extends string>({
id,
name,
items,
onSelect,
-}: SelectedItemsButtonProps<T>) {
+}: SelectedItemsButtonProps<Name>) {
const selectedItems = useSelectedItems();
const [menuOpen, setMenuOpen] = useState(false);
const triggerRef = useRef(null);
diff --git a/packages/desktop-client/src/components/transactions/SelectedTransactionsButton.jsx b/packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsx
similarity index 75%
rename from packages/desktop-client/src/components/transactions/SelectedTransactionsButton.jsx
rename to packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsx
index fbb65a602c..fa1c85836e 100644
--- a/packages/desktop-client/src/components/transactions/SelectedTransactionsButton.jsx
+++ b/packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsx
@@ -6,11 +6,41 @@ import { useDispatch } from 'react-redux';
import { pushModal } from 'loot-core/client/actions';
import { isPreviewId } from 'loot-core/shared/transactions';
import { validForTransfer } from 'loot-core/src/client/transfer';
+import { type TransactionEntity } from 'loot-core/types/models';
import { useSelectedItems } from '../../hooks/useSelected';
import { Menu } from '../common/Menu';
import { SelectedItemsButton } from '../table';
+type SelectedTransactionsButtonProps = {
+ getTransaction: (id: string) => TransactionEntity | undefined;
+ onShow: (selectedIds: string[]) => void;
+ onDuplicate: (selectedIds: string[]) => void;
+ onDelete: (selectedIds: string[]) => void;
+ onEdit: (
+ type:
+ | 'date'
+ | 'amount'
+ | 'account'
+ | 'payee'
+ | 'notes'
+ | 'category'
+ | 'cleared',
+ selectedIds: string[],
+ ) => void;
+ onLinkSchedule: (selectedIds: string[]) => void;
+ onUnlinkSchedule: (selectedIds: string[]) => void;
+ onCreateRule: (selectedIds: string[]) => void;
+ onSetTransfer: (selectedIds: string[]) => void;
+ onScheduleAction: (
+ action: 'post-transaction' | 'skip',
+ selectedIds: string[],
+ ) => void;
+ showMakeTransfer: boolean;
+ onMakeAsSplitTransaction: (selectedIds: string[]) => void;
+ onMakeAsNonSplitTransactions: (selectedIds: string[]) => void;
+};
+
export function SelectedTransactionsButton({
getTransaction,
onShow,
@@ -25,7 +55,7 @@ export function SelectedTransactionsButton({
showMakeTransfer,
onMakeAsSplitTransaction,
onMakeAsNonSplitTransactions,
-}) {
+}: SelectedTransactionsButtonProps) {
const { t } = useTranslation();
const dispatch = useDispatch();
const selectedItems = useSelectedItems();
@@ -82,8 +112,8 @@ export function SelectedTransactionsButton({
const areAllSameDateAndAccount = transactions.every(
tx =>
tx &&
- tx.date === firstTransaction.date &&
- tx.account === firstTransaction.account,
+ tx.date === firstTransaction?.date &&
+ tx.account === firstTransaction?.account,
);
const areNoSplitTransactions = transactions.every(
tx => tx && !tx.is_parent && !tx.is_child,
@@ -177,21 +207,29 @@ export function SelectedTransactionsButton({
<SelectedItemsButton
id="transactions"
name={count => t('{{count}} transactions', { count })}
+ // @ts-expect-error fix me
items={[
...(!types.trans
? [
- { name: 'view-schedule', text: t('View schedule'), key: 'S' },
- { name: 'post-transaction', text: t('Post transaction') },
- { name: 'skip', text: t('Skip scheduled date') },
+ {
+ name: 'view-schedule',
+ text: t('View schedule'),
+ key: 'S',
+ } as const,
+ {
+ name: 'post-transaction',
+ text: t('Post transaction'),
+ } as const,
+ { name: 'skip', text: t('Skip scheduled date') } as const,
]
: [
- { name: 'show', text: t('Show'), key: 'F' },
+ { name: 'show', text: t('Show'), key: 'F' } as const,
{
name: 'duplicate',
text: t('Duplicate'),
disabled: ambiguousDuplication,
- },
- { name: 'delete', text: t('Delete'), key: 'D' },
+ } as const,
+ { name: 'delete', text: t('Delete'), key: 'D' } as const,
...(linked
? [
{
@@ -199,19 +237,22 @@ export function SelectedTransactionsButton({
text: t('View schedule'),
key: 'S',
disabled: selectedIds.length > 1,
- },
- { name: 'unlink-schedule', text: t('Unlink schedule') },
+ } as const,
+ {
+ name: 'unlink-schedule',
+ text: t('Unlink schedule'),
+ } as const,
]
: [
{
name: 'link-schedule',
text: t('Link schedule'),
key: 'S',
- },
+ } as const,
{
name: 'create-rule',
text: t('Create rule'),
- },
+ } as const,
]),
...(showMakeTransfer
? [
@@ -219,7 +260,7 @@ export function SelectedTransactionsButton({
name: 'set-transfer',
text: t('Make transfer'),
disabled: !canBeTransfer,
- },
+ } as const,
]
: []),
...(canMakeAsSplitTransaction
@@ -227,7 +268,7 @@ export function SelectedTransactionsButton({
{
name: 'make-as-split-transaction',
text: t('Make as split transaction'),
- },
+ } as const,
]
: []),
...(canUnsplitTransactions
@@ -237,18 +278,18 @@ export function SelectedTransactionsButton({
text: t('Unsplit {{count}} transactions', {
count: selectedIds.length,
}),
- },
+ } as const,
]
: []),
Menu.line,
- { type: Menu.label, name: t('Edit field') },
- { name: 'date', text: t('Date') },
- { name: 'account', text: t('Account'), key: 'A' },
- { name: 'payee', text: t('Payee'), key: 'P' },
- { name: 'notes', text: t('Notes'), key: 'N' },
- { name: 'category', text: t('Category'), key: 'C' },
- { name: 'amount', text: t('Amount') },
- { name: 'cleared', text: t('Cleared'), key: 'L' },
+ { type: Menu.label, name: t('Edit field'), text: '' } as const,
+ { name: 'date', text: t('Date') } as const,
+ { name: 'account', text: t('Account'), key: 'A' } as const,
+ { name: 'payee', text: t('Payee'), key: 'P' } as const,
+ { name: 'notes', text: t('Notes'), key: 'N' } as const,
+ { name: 'category', text: t('Category'), key: 'C' } as const,
+ { name: 'amount', text: t('Amount') } as const,
+ { name: 'cleared', text: t('Cleared'), key: 'L' } as const,
]),
]}
onSelect={name => {
@@ -288,6 +329,7 @@ export function SelectedTransactionsButton({
onSetTransfer(selectedIds);
break;
default:
+ // @ts-expect-error fix me
onEdit(name, selectedIds);
}
}}
diff --git a/upcoming-release-notes/3640.md b/upcoming-release-notes/3640.md
new file mode 100644
index 0000000000..cd8ec6273f
--- /dev/null
+++ b/upcoming-release-notes/3640.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [MatissJanis]
+---
+
+TypeScript: migrated account header to TS.