feat(awards): a reference's number can be corrected in the editor
The one field the editor would not let you touch, and the one that was wrong on WAJA. Every other property of a reference — its name, pattern, entity list, validity window — was editable; the code was rendered readOnly, so correcting a number meant deleting all 47 references and importing a new list, throwing away anything the operator had adjusted in it. A rename in the store, not a delete plus an insert: everything the reference carries travels with it, which is the whole point of correcting a number rather than replacing an entry. A number already in use is refused — REPLACE INTO would have let one reference silently swallow another, discovered much later as a prefecture quietly missing from the list. The typed code is held apart from the selection. The list and every field patch key off the selected code, so editing it in place made the editor lose the reference mid-edit. SaveAwardReference now recomputes the log like Delete and Replace already did. A reference's name is what the award column SHOWS for awards displaying by name, and its pattern is part of what matches at all — so editing one changes rows, and the grid was left showing the old label until something else happened to trigger a pass. Changelog: the three TCI-sharing lines are merged into one. The server and the two fixes made to it while building are one unreleased feature, and an operator only ever meets the finished thing. The TCI-client PTT line stays separate — it is OpsLog driving a SunSDR, the other direction entirely.
This commit is contained in:
@@ -14,7 +14,7 @@ import { useI18n } from '@/lib/i18n';
|
||||
import {
|
||||
GetAwardDefs, SaveAwardDefs, ResetAwardDefs, AwardFields,
|
||||
GetAwardReferenceMeta, UpdateAwardReferenceList,
|
||||
ListAwardReferences, SearchAwardReferences, SaveAwardReference, DeleteAwardReference,
|
||||
ListAwardReferences, SearchAwardReferences, SaveAwardReference, DeleteAwardReference, RenameAwardReference,
|
||||
ImportAwardReferencesText, GetAwardPresets, ApplyAwardPreset,
|
||||
ListCountries, DXCCForCountry, DXCCName,
|
||||
PopulateBuiltinReferences, HasBuiltinReferences,
|
||||
@@ -915,6 +915,10 @@ function ReferencesPanel({ code, presets, meta, awardValidFrom, awardValidTo, on
|
||||
const [refs, setRefs] = useState<AwardRef[]>([]);
|
||||
const [q, setQ] = useState('');
|
||||
const [selCode, setSelCode] = useState<string | null>(null);
|
||||
// The code as TYPED. The list and every patch key off selCode, so editing the
|
||||
// code in place would make the editor lose the reference mid-edit; the draft
|
||||
// is applied as a rename when the operator saves.
|
||||
const [codeDraft, setCodeDraft] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [bulk, setBulk] = useState('');
|
||||
const [showBulk, setShowBulk] = useState(false);
|
||||
@@ -952,6 +956,7 @@ function ReferencesPanel({ code, presets, meta, awardValidFrom, awardValidTo, on
|
||||
}
|
||||
|
||||
const sel = refs.find((r) => r.code === selCode) || null;
|
||||
useEffect(() => { setCodeDraft(selCode ?? ''); }, [selCode]);
|
||||
// Large lists are already filtered by the server; small lists filter locally.
|
||||
const filtered = useMemo(() => {
|
||||
if (large) return refs;
|
||||
@@ -965,6 +970,27 @@ function ReferencesPanel({ code, presets, meta, awardValidFrom, awardValidTo, on
|
||||
try { await SaveAwardReference(code, r as any); load(); onChanged(); }
|
||||
catch (e: any) { setErr(String(e?.message ?? e)); }
|
||||
}
|
||||
// Save the selected reference, renumbering it first when the code was edited.
|
||||
//
|
||||
// The rename has to come first and has to be a rename: saving under the new
|
||||
// code would simply create a second reference and leave the old one behind,
|
||||
// which is how a list quietly grows duplicates.
|
||||
async function saveSelected(r: AwardRef) {
|
||||
const next = codeDraft.trim().toUpperCase();
|
||||
if (!next) { setErr(t('awed.refCodeEmpty')); return; }
|
||||
if (next !== r.code) {
|
||||
try {
|
||||
await RenameAwardReference(code, r.code, next);
|
||||
} catch (e: any) {
|
||||
// Most often the number is already taken by another reference. Said
|
||||
// here rather than swallowed: the save has NOT happened.
|
||||
setErr(String(e?.message ?? e));
|
||||
return;
|
||||
}
|
||||
setSelCode(next);
|
||||
}
|
||||
await saveRef({ ...r, code: next });
|
||||
}
|
||||
async function addRef() {
|
||||
const c = prompt(t('awed.newRefCodePrompt'))?.trim().toUpperCase();
|
||||
if (!c) return;
|
||||
@@ -1046,7 +1072,13 @@ function ReferencesPanel({ code, presets, meta, awardValidFrom, awardValidTo, on
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Input className="h-8 w-28 font-mono font-semibold" value={sel.code} readOnly />
|
||||
{/* Editable, because a shipped list can be wrong about it: WAJA
|
||||
went out carrying Japan's civil prefecture numbers instead of
|
||||
the JARL's, and correcting that meant deleting all 47
|
||||
references and importing a new list. */}
|
||||
<Input className="h-8 w-28 font-mono font-semibold" value={codeDraft}
|
||||
title={t('awed.refCodeTip')}
|
||||
onChange={(e) => setCodeDraft(e.target.value)} />
|
||||
<label className="flex items-center gap-1.5 text-xs cursor-pointer"><Checkbox checked={sel.valid} onCheckedChange={(c) => patchSel({ valid: !!c })} /> {t('awed.valid')}</label>
|
||||
<div className="flex-1" />
|
||||
<button className="text-muted-foreground hover:text-destructive" onClick={() => delRef(sel.code)}><Trash2 className="size-4" /></button>
|
||||
@@ -1084,7 +1116,7 @@ function ReferencesPanel({ code, presets, meta, awardValidFrom, awardValidTo, on
|
||||
? t('awed.refValidHintAward', { from: openEnded(awardValidFrom), to: openEnded(awardValidTo) })
|
||||
: t('awed.refValidHint')}
|
||||
</p>
|
||||
<div className="flex justify-end pt-1"><Button size="sm" className="h-7" onClick={() => sel && saveRef(sel)}><Save className="size-3.5 mr-1" /> {t('awed.saveReference')}</Button></div>
|
||||
<div className="flex justify-end pt-1"><Button size="sm" className="h-7" onClick={() => sel && saveSelected(sel)}><Save className="size-3.5 mr-1" /> {t('awed.saveReference')}</Button></div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user