fix: show full category path (parent · subcategory) everywhere, group filters by hierarchy

Транзакция на подкатегории показывала только её имя — непонятно было,
что это подкатегория и к какой родительской категории она относится.
Фильтры по категории в Транзакциях и Отчётах тоже перечисляли
подкатегории наравне с родительскими, без иерархии.

- categoryLabels.ts: categoryPath() и buildHierarchicalCategories() —
  общая логика, вынесенная из TransactionFormModal.
- Список транзакций и «Последние транзакции» на Dashboard показывают
  счёт, затем родителя, затем подкатегорию.
- Фильтр категорий в Транзакциях сгруппирован по типу (как в Отчётах);
  оба списка показывают подкатегорию с отступом под родителем.
This commit is contained in:
ZProger
2026-08-30 19:30:49 +03:00
parent 87b37a10ff
commit dbae7938da
6 changed files with 111 additions and 28 deletions

View File

@@ -8,9 +8,9 @@ import { useAccounts } from "@/hooks/useAccounts";
import { useCategories } from "@/hooks/useCategories";
import { useCreateTransaction, useUpdateTransaction } from "@/hooks/useTransactions";
import { useTranslation } from "@/lib/i18n";
import { translateCategoryName } from "@/lib/categoryLabels";
import { buildHierarchicalCategories, translateCategoryName } from "@/lib/categoryLabels";
import { formatCurrency } from "@/lib/format";
import type { Category, Tag, Transaction, TransactionInput, TransactionSplitInput, TransactionType } from "@/types";
import type { Tag, Transaction, TransactionInput, TransactionSplitInput, TransactionType } from "@/types";
interface TransactionFormModalProps {
open: boolean;
@@ -114,19 +114,13 @@ export function TransactionFormModal({ open, onClose, transaction }: Transaction
setError(null);
}, [open, transaction, accounts]);
const kindCategories = (categories ?? []).filter((category) =>
form.type === "income" ? category.kind === "income" : category.kind === "expense"
);
// Subcategories are listed right under their parent (not scattered by
// sort_order) so the hierarchy set up on the Categories page reads the
// same way here.
const kindCategories = (categories ?? [])
.filter((category) => (form.type === "income" ? category.kind === "income" : category.kind === "expense"))
.sort((a, b) => translateCategoryName(a.name).localeCompare(translateCategoryName(b.name), language));
const relevantCategories: (Category & { indented?: boolean })[] = [];
for (const parent of kindCategories.filter((category) => category.parent_id === null)) {
relevantCategories.push(parent);
for (const child of kindCategories.filter((category) => category.parent_id === parent.id)) {
relevantCategories.push({ ...child, indented: true });
}
}
// name) so the hierarchy set up on the Categories page reads the same way
// here.
const relevantCategories = buildHierarchicalCategories(kindCategories, language);
const isSaving = createTransaction.isPending || updateTransaction.isPending;