refactor: improve code formatting and consistency in StatisticsPage and TopExpensesList components; standardize quotation marks and enhance readability across various sections
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m57s

This commit is contained in:
Julien Froidefond
2025-12-23 11:49:31 +01:00
parent c57daa9cc8
commit f295e86fc2
2 changed files with 336 additions and 21 deletions

View File

@@ -59,15 +59,15 @@ export default function StatisticsPage() {
// Persister les filtres dans le localStorage
const [period, setPeriod] = useLocalStorage<Period>(
"statistics-period",
"6months",
"6months"
);
const [selectedAccounts, setSelectedAccounts] = useLocalStorage<string[]>(
"statistics-selected-accounts",
["all"],
["all"]
);
const [selectedCategories, setSelectedCategories] = useLocalStorage<string[]>(
"statistics-selected-categories",
["all"],
["all"]
);
const [excludeInternalTransfers, setExcludeInternalTransfers] =
useLocalStorage("statistics-exclude-internal-transfers", true);
@@ -83,11 +83,11 @@ export default function StatisticsPage() {
// Convertir les ISO strings en Date
const customStartDate = useMemo(
() => (customStartDateISO ? new Date(customStartDateISO) : undefined),
[customStartDateISO],
[customStartDateISO]
);
const customEndDate = useMemo(
() => (customEndDateISO ? new Date(customEndDateISO) : undefined),
[customEndDateISO],
[customEndDateISO]
);
// Fonctions pour mettre à jour les dates avec persistance
@@ -145,7 +145,7 @@ export default function StatisticsPage() {
const internalTransferCategory = useMemo(() => {
if (!data) return null;
return data.categories.find(
(c) => c.name.toLowerCase() === "virement interne",
(c) => c.name.toLowerCase() === "virement interne"
);
}, [data]);
@@ -261,7 +261,7 @@ export default function StatisticsPage() {
// Filter by accounts
if (!selectedAccounts.includes("all")) {
transactions = transactions.filter((t) =>
selectedAccounts.includes(t.accountId),
selectedAccounts.includes(t.accountId)
);
}
@@ -271,7 +271,7 @@ export default function StatisticsPage() {
transactions = transactions.filter((t) => !t.categoryId);
} else {
transactions = transactions.filter(
(t) => t.categoryId && selectedCategories.includes(t.categoryId),
(t) => t.categoryId && selectedCategories.includes(t.categoryId)
);
}
}
@@ -279,7 +279,7 @@ export default function StatisticsPage() {
// Exclude "Virement interne" category if checkbox is checked
if (excludeInternalTransfers && internalTransferCategory) {
transactions = transactions.filter(
(t) => t.categoryId !== internalTransferCategory.id,
(t) => t.categoryId !== internalTransferCategory.id
);
}
@@ -352,7 +352,7 @@ export default function StatisticsPage() {
});
const categoryChartDataByParent = Array.from(
categoryTotalsByParent.entries(),
categoryTotalsByParent.entries()
)
.map(([groupId, total]) => {
const category = data.categories.find((c) => c.id === groupId);
@@ -368,7 +368,7 @@ export default function StatisticsPage() {
// Top expenses by top parent categories - deduplicate by ID
const uniqueTransactions = Array.from(
new Map(transactions.map((t) => [t.id, t])).values(),
new Map(transactions.map((t) => [t.id, t])).values()
);
const expenses = uniqueTransactions.filter((t) => t.amount < 0);
@@ -425,7 +425,7 @@ export default function StatisticsPage() {
// Balance evolution - Aggregated (using filtered transactions)
const sortedFilteredTransactions = [...transactions].sort(
(a, b) => new Date(a.date).getTime() - new Date(b.date).getTime(),
(a, b) => new Date(a.date).getTime() - new Date(b.date).getTime()
);
// Calculate starting balance: initialBalance + transactions before startDate
@@ -437,7 +437,7 @@ export default function StatisticsPage() {
// Start with initial balances
runningBalance = accountsToUse.reduce(
(sum, acc) => sum + (acc.initialBalance || 0),
0,
0
);
// Add all transactions before the start date for these accounts
@@ -474,7 +474,7 @@ export default function StatisticsPage() {
});
const aggregatedBalanceData = Array.from(
aggregatedBalanceByDate.entries(),
aggregatedBalanceByDate.entries()
).map(([date, balance]) => ({
date: new Date(date).toLocaleDateString("fr-FR", {
day: "2-digit",
@@ -697,6 +697,7 @@ export default function StatisticsPage() {
aggregatedBalanceData,
perAccountBalanceData,
transactionCount: transactions.length,
transactions, // Toutes les transactions filtrées pour le graphique
savingsTrendData,
categoryTrendData,
categoryTrendDataByParent,
@@ -931,7 +932,7 @@ export default function StatisticsPage() {
onRemoveAccount={(id) => {
const newAccounts = selectedAccounts.filter((a) => a !== id);
setSelectedAccounts(
newAccounts.length > 0 ? newAccounts : ["all"],
newAccounts.length > 0 ? newAccounts : ["all"]
);
}}
onClearAccounts={() => setSelectedAccounts(["all"])}
@@ -939,7 +940,7 @@ export default function StatisticsPage() {
onRemoveCategory={(id) => {
const newCategories = selectedCategories.filter((c) => c !== id);
setSelectedCategories(
newCategories.length > 0 ? newCategories : ["all"],
newCategories.length > 0 ? newCategories : ["all"]
);
}}
onClearCategories={() => setSelectedCategories(["all"])}
@@ -1129,17 +1130,17 @@ export default function StatisticsPage() {
onRemoveAccount={(id) => {
const newAccounts = selectedAccounts.filter((a) => a !== id);
setSelectedAccounts(
newAccounts.length > 0 ? newAccounts : ["all"],
newAccounts.length > 0 ? newAccounts : ["all"]
);
}}
onClearAccounts={() => setSelectedAccounts(["all"])}
selectedCategories={selectedCategories}
onRemoveCategory={(id) => {
const newCategories = selectedCategories.filter(
(c) => c !== id,
(c) => c !== id
);
setSelectedCategories(
newCategories.length > 0 ? newCategories : ["all"],
newCategories.length > 0 ? newCategories : ["all"]
);
}}
onClearCategories={() => setSelectedCategories(["all"])}
@@ -1244,6 +1245,7 @@ export default function StatisticsPage() {
expensesByCategory={stats.topExpensesByCategory}
categories={data.categories}
formatCurrency={formatCurrency}
allTransactions={stats.transactions}
/>
</div>
</section>
@@ -1289,7 +1291,7 @@ function ActiveFilters({
const selectedAccs = accounts.filter((a) => selectedAccounts.includes(a.id));
const selectedCats = categories.filter((c) =>
selectedCategories.includes(c.id),
selectedCategories.includes(c.id)
);
const isUncategorized = selectedCategories.includes("uncategorized");