feat: per-operator filter in the statistics dashboard
New Operator picker next to the contest picker, populated with the operators actually present in the log. Selecting one recomputes every statistic for that operator — QSO/DXCC totals, top countries, continent split, by band/mode, and the rate/best-60. "— Station owner —" buckets QSOs logged with no OPERATOR set. Shown only when the log has more than one operator. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { BarChart3, Loader2, RefreshCw, Table2 } from 'lucide-react';
|
||||
import { GetLogStats, GetContestRuns } from '../../wailsjs/go/main/App';
|
||||
import { GetLogStats, GetContestRuns, GetOperators } from '../../wailsjs/go/main/App';
|
||||
import { useI18n } from '@/lib/i18n';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
@@ -491,10 +491,14 @@ export function StatsPanel() {
|
||||
// that contest AND lets the window derive from its own span — no date typing.
|
||||
const [runs, setRuns] = useState<ContestRun[]>([]);
|
||||
const [contest, setContest] = useState('');
|
||||
// Operator picker: '' = all operators, "—" = station owner (empty OPERATOR).
|
||||
const [operators, setOperators] = useState<string[]>([]);
|
||||
const [operator, setOperator] = useState('');
|
||||
|
||||
useEffect(() => { GetContestRuns().then((r: any) => setRuns((r ?? []) as ContestRun[])).catch(() => {}); }, []);
|
||||
useEffect(() => { GetOperators().then((o: any) => setOperators((o ?? []) as string[])).catch(() => {}); }, []);
|
||||
|
||||
const load = async (p: Period = period, f = from, t2 = to, c = contest) => {
|
||||
const load = async (p: Period = period, f = from, t2 = to, c = contest, op = operator) => {
|
||||
// A contest defines its own window (its first→last QSO), so we send no dates
|
||||
// with it — the backend derives them. Sending a period as well would be two
|
||||
// filters fighting over the same axis.
|
||||
@@ -502,7 +506,7 @@ export function StatsPanel() {
|
||||
const [a, b] = c ? ['', ''] : periodRange(p, f, t2);
|
||||
setBusy(true); setErr('');
|
||||
try {
|
||||
const raw = (await GetLogStats(a, b, cid, parseInt(cyr, 10) || 0)) as any;
|
||||
const raw = (await GetLogStats(a, b, cid, parseInt(cyr, 10) || 0, op)) as any;
|
||||
// Harden the boundary: a Go nil slice arrives as JSON null, and a single
|
||||
// .length on null unmounts the whole React tree — a white screen. Normalise
|
||||
// once, here, rather than guarding at every use site and missing one.
|
||||
@@ -523,9 +527,9 @@ export function StatsPanel() {
|
||||
// are set — otherwise every keystroke in the date box would re-scan the log.
|
||||
useEffect(() => {
|
||||
if (!contest && period === 'custom' && !(from && to)) return;
|
||||
load(period, from, to, contest);
|
||||
load(period, from, to, contest, operator);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [period, from, to, contest]);
|
||||
}, [period, from, to, contest, operator]);
|
||||
|
||||
// The rate / off-air block belongs to a CONTEST-shaped effort, and nowhere else.
|
||||
// Over a year it degenerates into nonsense — "4 156 h off air", a 94-hour "break"
|
||||
@@ -570,6 +574,20 @@ export function StatsPanel() {
|
||||
))}
|
||||
</select>
|
||||
|
||||
{/* Operator picker — narrows every stat (totals, DXCC, top countries,
|
||||
continent split, rate) to one operator from the log. "—" = the
|
||||
station owner (QSOs logged with no OPERATOR set). */}
|
||||
{operators.length > 1 && (
|
||||
<select value={operator} onChange={(e) => setOperator(e.target.value)}
|
||||
className="h-7 rounded-md border border-input bg-background px-1.5 text-xs max-w-[180px]"
|
||||
title={t('stats.operatorTip')}>
|
||||
<option value="">{t('stats.allOperators')}</option>
|
||||
{operators.map((op) => (
|
||||
<option key={op} value={op}>{op === '—' ? t('stats.stationOwner') : op}</option>
|
||||
))}
|
||||
</select>
|
||||
)}
|
||||
|
||||
<div className={cn('inline-flex rounded-md border border-border overflow-hidden', contest && 'opacity-40 pointer-events-none')}>
|
||||
{([
|
||||
['all', t('stats.pAll')], ['ytd', t('stats.pYTD')],
|
||||
|
||||
Reference in New Issue
Block a user