cospend: filter recent activity by chart category selection
All checks were successful
CI / update (push) Successful in 1m27s

Clicking a category on the bar chart now filters the recent activity
list to show only payments in that category. Includes a clear filter
button and empty state message. Also increases recent splits from 10
to 30 for better coverage when filtering.
This commit is contained in:
2026-02-04 16:57:44 +01:00
parent 8776ab894b
commit 83de5fed34
3 changed files with 92 additions and 6 deletions

View File

@@ -2,7 +2,7 @@
import { onMount } from 'svelte';
import { Chart, registerables } from 'chart.js';
let { data = { labels: [], datasets: [] }, title = '', height = '400px' } = $props<{ data?: any, title?: string, height?: string }>();
let { data = { labels: [], datasets: [] }, title = '', height = '400px', onFilterChange = null } = $props<{ data?: any, title?: string, height?: string, onFilterChange?: ((categories: string[] | null) => void) | null }>();
let canvas = $state();
let chart = $state();
@@ -42,6 +42,19 @@
return categoryColorMap[category] || nordColors[index % nordColors.length];
}
function emitFilter() {
if (!onFilterChange || !chart) return;
const allVisible = chart.data.datasets.every((_, idx) => !chart.getDatasetMeta(idx).hidden);
if (allVisible) {
onFilterChange(null);
} else {
const visible = chart.data.datasets
.filter((_, idx) => !chart.getDatasetMeta(idx).hidden)
.map(ds => ds.label.toLowerCase());
onFilterChange(visible);
}
}
function createChart() {
if (!canvas || !data.datasets) return;
@@ -135,7 +148,6 @@
},
onClick: (event, legendItem, legend) => {
const datasetIndex = legendItem.datasetIndex;
const clickedMeta = chart.getDatasetMeta(datasetIndex);
// Check if only this dataset is currently visible
const onlyThisVisible = chart.data.datasets.every((dataset, idx) => {
@@ -156,6 +168,7 @@
}
chart.update();
emitFilter();
}
},
title: {
@@ -229,6 +242,7 @@
}
chart.update();
emitFilter();
}
}
},