mirror of
https://github.com/Zproger/Aurum.git
synced 2026-11-18 08:02:49 +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:
@@ -3,7 +3,9 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/Card";
|
||||
import { getCategoryIcon } from "@/lib/icons";
|
||||
import { formatCurrency, formatTransactionDate } from "@/lib/format";
|
||||
import { useTranslation } from "@/lib/i18n";
|
||||
import { categoryPath, translateCategoryName } from "@/lib/categoryLabels";
|
||||
import { useTransactions } from "@/hooks/useTransactions";
|
||||
import { useCategories } from "@/hooks/useCategories";
|
||||
|
||||
interface RecentTransactionsCardProps {
|
||||
year: number;
|
||||
@@ -13,6 +15,7 @@ interface RecentTransactionsCardProps {
|
||||
export function RecentTransactionsCard({ year, month }: RecentTransactionsCardProps) {
|
||||
const { t } = useTranslation();
|
||||
const { data, isLoading } = useTransactions({ year, month, page: 1, page_size: 6 });
|
||||
const { data: categories } = useCategories();
|
||||
|
||||
return (
|
||||
<Card>
|
||||
@@ -33,10 +36,16 @@ export function RecentTransactionsCard({ year, month }: RecentTransactionsCardPr
|
||||
) : (
|
||||
<ul className="divide-y divide-gridline">
|
||||
{data.items.map((tx) => {
|
||||
const isSplit = tx.splits.length > 0;
|
||||
const Icon = getCategoryIcon(tx.category?.icon);
|
||||
const isTransfer = tx.type === "transfer";
|
||||
const isExpense = tx.type === "expense";
|
||||
const color = tx.category?.color ?? "var(--text-muted)";
|
||||
const categoryLabel = isSplit
|
||||
? tx.splits.map((split) => (split.category ? translateCategoryName(split.category.name) : "?")).join(" + ")
|
||||
: tx.category
|
||||
? categoryPath(tx.category, categories)
|
||||
: null;
|
||||
return (
|
||||
<li key={tx.id} className="flex items-center gap-3 py-2.5 first:pt-0 last:pb-0">
|
||||
<span
|
||||
@@ -47,8 +56,9 @@ export function RecentTransactionsCard({ year, month }: RecentTransactionsCardPr
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-sm text-text-primary">{tx.description}</span>
|
||||
<span className="block text-xs text-text-muted">
|
||||
<span className="block truncate text-xs text-text-muted">
|
||||
{formatTransactionDate(tx.date)} · {tx.account.name}
|
||||
{categoryLabel ? ` · ${categoryLabel}` : ""}
|
||||
</span>
|
||||
</span>
|
||||
<span
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@ import { Dialog } from "@/components/ui/Dialog";
|
||||
import { getCategoryIcon } from "@/lib/icons";
|
||||
import { formatCurrency, formatTransactionDate } from "@/lib/format";
|
||||
import { useTranslation } from "@/lib/i18n";
|
||||
import { translateCategoryName } from "@/lib/categoryLabels";
|
||||
import { categoryPath, translateCategoryName } from "@/lib/categoryLabels";
|
||||
import { useCategories } from "@/hooks/useCategories";
|
||||
import type { Transaction } from "@/types";
|
||||
|
||||
interface TransactionsTableProps {
|
||||
@@ -19,6 +20,7 @@ interface TransactionsTableProps {
|
||||
|
||||
export function TransactionsTable({ items, onEdit, onDelete, onJumpToMonth }: TransactionsTableProps) {
|
||||
const { t } = useTranslation();
|
||||
const { data: categories } = useCategories();
|
||||
const [noteTransaction, setNoteTransaction] = useState<Transaction | null>(null);
|
||||
|
||||
if (items.length === 0) {
|
||||
@@ -41,7 +43,7 @@ export function TransactionsTable({ items, onEdit, onDelete, onJumpToMonth }: Tr
|
||||
const categoryLabel = isSplit
|
||||
? tx.splits.map((split) => (split.category ? translateCategoryName(split.category.name) : "?")).join(" + ")
|
||||
: tx.category
|
||||
? translateCategoryName(tx.category.name)
|
||||
? categoryPath(tx.category, categories)
|
||||
: null;
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user