feat: implement hierarchical category management with parent-child relationships and enhance category creation dialog

This commit is contained in:
Julien Froidefond
2025-11-27 10:29:59 +01:00
parent d7374e4129
commit 7314cb6716
9 changed files with 1048 additions and 260 deletions

View File

@@ -5,11 +5,49 @@ import { defaultCategories, defaultRootFolder } from "./defaults"
const STORAGE_KEY = "banking-app-data"
// Convertir les CategoryDefinition en Category pour le localStorage
function buildCategoriesFromDefaults(): Category[] {
const slugToId = new Map<string, string>()
const categories: Category[] = []
// D'abord les parents
const parents = defaultCategories.filter((c) => c.parentSlug === null)
parents.forEach((cat, index) => {
const id = `cat-${index + 1}`
slugToId.set(cat.slug, id)
categories.push({
id,
name: cat.name,
color: cat.color,
icon: cat.icon,
keywords: cat.keywords,
parentId: null,
})
})
// Puis les enfants
const children = defaultCategories.filter((c) => c.parentSlug !== null)
children.forEach((cat, index) => {
const id = `cat-${parents.length + index + 1}`
slugToId.set(cat.slug, id)
categories.push({
id,
name: cat.name,
color: cat.color,
icon: cat.icon,
keywords: cat.keywords,
parentId: cat.parentSlug ? slugToId.get(cat.parentSlug) || null : null,
})
})
return categories
}
const defaultData: BankingData = {
accounts: [],
transactions: [],
folders: [defaultRootFolder],
categories: defaultCategories.map((cat, index) => ({ ...cat, id: `cat-${index + 1}` })),
categories: buildCategoriesFromDefaults(),
categoryRules: [],
}