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

Add option to unmark imported transactions #3810

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions packages/desktop-client/src/components/accounts/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,31 @@ class AccountInternal extends PureComponent<
});
};

onUnmarkTransactionsAsImported = async (ids: string[]) => {
this.setState({ workingHard: true });

const { data } = await runQuery(
q('transactions')
.filter({ id: { $oneof: ids } })
.select('*')
.options({ splits: 'grouped' }),
);

const transactions: TransactionEntity[] = data;

if (!transactions || transactions.length === 0) {
return;
}

const importedTransactionIds = transactions
.filter(t => t.imported_payee)
.map(t => t.id);

this.onBatchEdit('imported_payee', importedTransactionIds);

this.refetchTransactions();
};
csenel marked this conversation as resolved.
Show resolved Hide resolved

Comment on lines +1140 to +1164
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joel-jeremy will know better than me on this, is this okay here or should it be moved to packages/desktop-client/src/hooks/useTransactionBatchActions.ts?

checkForReconciledTransactions = async (
ids: string[],
confirmReason: string,
Expand Down Expand Up @@ -1744,6 +1769,9 @@ class AccountInternal extends PureComponent<
onSetTransfer={this.onSetTransfer}
onMakeAsSplitTransaction={this.onMakeAsSplitTransaction}
onMakeAsNonSplitTransactions={this.onMakeAsNonSplitTransactions}
onUnmarkTransactionsAsImported={
this.onUnmarkTransactionsAsImported
}
/>

<View style={{ flex: 1 }}>
Expand Down
3 changes: 3 additions & 0 deletions packages/desktop-client/src/components/accounts/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ type AccountHeaderProps = {
| 'onSetTransfer'
| 'onMakeAsSplitTransaction'
| 'onMakeAsNonSplitTransactions'
| 'onUnmarkTransactionsAsImported'
> &
Pick<
ComponentProps<typeof FiltersStack>,
Expand Down Expand Up @@ -179,6 +180,7 @@ export function AccountHeader({
onSetTransfer,
onMakeAsSplitTransaction,
onMakeAsNonSplitTransactions,
onUnmarkTransactionsAsImported,
}: AccountHeaderProps) {
const { t } = useTranslation();
const [menuOpen, setMenuOpen] = useState(false);
Expand Down Expand Up @@ -367,6 +369,7 @@ export function AccountHeader({
showMakeTransfer={showMakeTransfer}
onMakeAsSplitTransaction={onMakeAsSplitTransaction}
onMakeAsNonSplitTransactions={onMakeAsNonSplitTransactions}
onUnmarkTransactionsAsImported={onUnmarkTransactionsAsImported}
/>
)}
<View style={{ flex: '0 0 auto' }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type SelectedTransactionsButtonProps = {
showMakeTransfer: boolean;
onMakeAsSplitTransaction: (selectedIds: string[]) => void;
onMakeAsNonSplitTransactions: (selectedIds: string[]) => void;
onUnmarkTransactionsAsImported: (selectedIds: string[]) => void;
};

export function SelectedTransactionsButton({
Expand All @@ -55,6 +56,7 @@ export function SelectedTransactionsButton({
showMakeTransfer,
onMakeAsSplitTransaction,
onMakeAsNonSplitTransactions,
onUnmarkTransactionsAsImported,
}: SelectedTransactionsButtonProps) {
const { t } = useTranslation();
const dispatch = useDispatch();
Expand Down Expand Up @@ -145,6 +147,19 @@ export function SelectedTransactionsButton({
return areNoReconciledTransactions && areAllSplitTransactions;
}, [selectedIds, types, getTransaction]);

const canUnmarkTransactionsAsImported = useMemo(() => {
if (selectedIds.length === 0 || types.preview) {
return false;
}

const transactions = selectedIds.map(id => getTransaction(id));

const areSomeImportedTransactions = transactions.some(
tx => tx && tx.imported_payee,
);
return areSomeImportedTransactions;
}, [selectedIds, types, getTransaction]);
csenel marked this conversation as resolved.
Show resolved Hide resolved

function onViewSchedule() {
const firstId = selectedIds[0];
let scheduleId;
Expand Down Expand Up @@ -281,6 +296,14 @@ export function SelectedTransactionsButton({
} as const,
]
: []),
...(canUnmarkTransactionsAsImported
? [
{
name: 'unmark-transactions-as-imported',
text: t('Unmark as imported'),
} as const,
]
: []),
Menu.line,
{ type: Menu.label, name: t('Edit field'), text: '' } as const,
{ name: 'date', text: t('Date') } as const,
Expand Down Expand Up @@ -309,6 +332,9 @@ export function SelectedTransactionsButton({
case 'unsplit-transactions':
onMakeAsNonSplitTransactions(selectedIds);
break;
case 'unmark-transactions-as-imported':
onUnmarkTransactionsAsImported(selectedIds);
break;
case 'post-transaction':
case 'skip':
onScheduleAction(name, selectedIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ export function useTransactionBatchActions() {
// Cleared just toggles it on/off and it depends on the data
// loaded. Need to clean this up in the future.
onChange('cleared', null);
} else if (name === 'imported_payee') {
// Unmark as imported transaction by setting imported payee to empty string.
onChange('imported_payee', '');
} else if (name === 'category') {
pushCategoryAutocompleteModal();
} else if (name === 'payee') {
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3810.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [csenel]
---

Add option to unmark imported transactions.
Loading