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

fix deleting rules considering the applied filters #4224

Open
wants to merge 4 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
25 changes: 18 additions & 7 deletions packages/desktop-client/src/components/ManageRules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import * as undo from 'loot-core/src/platform/client/undo';
import { getNormalisedString } from 'loot-core/src/shared/normalisation';
import { mapField, friendlyOp } from 'loot-core/src/shared/rules';
import { describeSchedule } from 'loot-core/src/shared/schedules';
import { type NewRuleEntity } from 'loot-core/src/types/models';
import {
type RuleEntity,
type NewRuleEntity,
} from 'loot-core/src/types/models';

import { useAccounts } from '../hooks/useAccounts';
import { useCategories } from '../hooks/useCategories';
Expand Down Expand Up @@ -110,7 +113,7 @@ export function ManageRules({
payeeId,
setLoading = () => {},
}: ManageRulesProps) {
const [allRules, setAllRules] = useState([]);
const [allRules, setAllRules] = useState<RuleEntity[]>([]);
const [page, setPage] = useState(0);
const [filter, setFilter] = useState('');
const dispatch = useDispatch();
Expand Down Expand Up @@ -197,10 +200,18 @@ export function ManageRules({
setPage(page => page + 1);
}

async function onDeleteSelected() {
const rulesToDelete = useMemo(() => {
const filteredRuleIds = new Set(filteredRules.map(r => r.id));
return new Set(
[...selectedInst.items].filter(item => filteredRuleIds.has(item)),
);
}, [selectedInst.items, filteredRules]);

const onDeleteSelected = useCallback(async () => {
setLoading(true);

const { someDeletionsFailed } = await send('rule-delete-all', [
...selectedInst.items,
...rulesToDelete,
]);

if (someDeletionsFailed) {
Expand All @@ -212,7 +223,7 @@ export function ManageRules({
await loadRules();
selectedInst.dispatch({ type: 'select-none' });
setLoading(false);
}
}, [rulesToDelete]);

async function onDeleteRule(id: string) {
setLoading(true);
Expand Down Expand Up @@ -338,9 +349,9 @@ export function ManageRules({
}}
>
<Stack direction="row" align="center" justify="flex-end" spacing={2}>
{selectedInst.items.size > 0 && (
{rulesToDelete.size > 0 && (
<Button onPress={onDeleteSelected}>
Delete {selectedInst.items.size} rules
Delete {rulesToDelete.size} rules
</Button>
)}
<Button variant="primary" onPress={onCreateRule}>
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/4224.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [harrydigos]
---

Fix deleting rules considering the applied filters
Loading