mirror of
https://github.com/Zproger/Aurum.git
synced 2026-11-05 23:37:23 +07:00
fix: show full category path (parent · subcategory) everywhere, group filters by hierarchy
Транзакция на подкатегории показывала только её имя — непонятно было, что это подкатегория и к какой родительской категории она относится. Фильтры по категории в Транзакциях и Отчётах тоже перечисляли подкатегории наравне с родительскими, без иерархии. - categoryLabels.ts: categoryPath() и buildHierarchicalCategories() — общая логика, вынесенная из TransactionFormModal. - Список транзакций и «Последние транзакции» на Dashboard показывают счёт, затем родителя, затем подкатегорию. - Фильтр категорий в Транзакциях сгруппирован по типу (как в Отчётах); оба списка показывают подкатегорию с отступом под родителем.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user