From 1884262268847e3a753c201c4758f262e710a043 Mon Sep 17 00:00:00 2001 From: Andre Henriques <andr3h3nriqu3s@gmail.com> Date: Tue, 1 Apr 2025 21:26:14 +0100 Subject: [PATCH] chore: improve data display --- site/src/routes/SmartApplicationList.svelte | 35 ++++++++++++--------- site/src/routes/graphs/+page.svelte | 8 +++-- site/src/routes/graphs/Pie.svelte | 26 ++++++++------- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/site/src/routes/SmartApplicationList.svelte b/site/src/routes/SmartApplicationList.svelte index 0d1c8bd..d5cd4f8 100644 --- a/site/src/routes/SmartApplicationList.svelte +++ b/site/src/routes/SmartApplicationList.svelte @@ -15,28 +15,33 @@ return i.status_id === status_id; }) ); + + let internal = $derived( + sorted.filter((i) => { + if (!filter) { + return true; + } + const f = new RegExp(filter, 'ig'); + + let x = i.title; + + if (i.company) { + x = `${x} @ ${i.company}`; + } + + return x.match(f); + }) + ); </script> {#if sorted.length > 0} <div class="card p-3 rounded-lg"> <h1 class="flex gap-2"> - {title} <input bind:value={filter} placeholder="search" class="flex-grow text-blue-500" /> + {title} ({internal.length}) + <input bind:value={filter} placeholder="search" class="flex-grow text-blue-500" /> </h1> <div class="flex flex-wrap gap-4"> - {#each sorted.filter((i) => { - if (!filter) { - return true; - } - const f = new RegExp(filter, 'ig'); - - let x = i.title; - - if (i.company) { - x = `${x} @ ${i.company}`; - } - - return x.match(f); - }) as item} + {#each internal as item} <button class="card p-2 my-2 bg-slate-100 text-left" onclick={async () => { diff --git a/site/src/routes/graphs/+page.svelte b/site/src/routes/graphs/+page.svelte index 2731241..d3110b0 100644 --- a/site/src/routes/graphs/+page.svelte +++ b/site/src/routes/graphs/+page.svelte @@ -125,14 +125,18 @@ data={[...statusStore.nodes, 'Created' as const].reduce( (acc, item) => { if (item === 'Created') { - acc[item] = applicationStore.all.filter( + const count = applicationStore.all.filter( (a) => a.status_id === null ).length; + if (count === 0) return acc; + acc[item] = count; return acc; } - acc[item.name] = applicationStore.all.filter( + const count = applicationStore.all.filter( (a) => item.id === a.status_id ).length; + if (count === 0) return acc; + acc[item.name] = count; return acc; }, {} as Record<string, number> diff --git a/site/src/routes/graphs/Pie.svelte b/site/src/routes/graphs/Pie.svelte index 92a2095..116ddcb 100644 --- a/site/src/routes/graphs/Pie.svelte +++ b/site/src/routes/graphs/Pie.svelte @@ -35,20 +35,22 @@ const other = dataf.filter((v) => v.value / sum < sensitivity); - dataf = dataf.filter((f) => f.value / sum > sensitivity); + if (other.length > 1) { + dataf = dataf.filter((f) => f.value / sum > sensitivity); - const otherSum = other.reduce((acc, v) => { - return acc + v.value; - }, 0); + const otherSum = other.reduce((acc, v) => { + return acc + v.value; + }, 0); - if (otherSum > 0) { - dataf.push({ - value: otherSum, - name: 'Other', - title: `Other: ${otherSum}\n${other - .toSorted((a, b) => b.value - a.value) - .reduce((acc, a) => `${acc}${a.name}: ${a.value}\n`, '')}` - }); + if (otherSum > 0) { + dataf.push({ + value: otherSum, + name: 'Other', + title: `Other: ${otherSum}\n${other + .toSorted((a, b) => b.value - a.value) + .reduce((acc, a) => `${acc}${a.name}: ${a.value}\n`, '')}` + }); + } } dataf = dataf.toSorted((a, b) => a.value - b.value);