feat(firmware): pre-fill Min FW on upload from the previous release

A new release almost always keeps the previous release's upgrade-chain
floor, so the upload form now defaults Min FW to the newest existing
release for the same board (same channel preferred, any channel as
fallback; bespoke matched by UID). Empty when no previous release set one.
It re-derives when board/channel change until the user edits the field,
and a hint shows which release the value came from. Edit mode unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-08 21:34:38 +02:00
co-authored by Claude Opus 5.5
parent 3636556ae7
commit 565aca4d56
@@ -117,6 +117,28 @@ function FirmwareFormModal({ initial, onClose, onSaved }) {
const [error, setError] = useState('') const [error, setError] = useState('')
const fileInputRef = useRef(null) const fileInputRef = useRef(null)
const elfInputRef = useRef(null) const elfInputRef = useRef(null)
// Min FW on a new upload defaults to whatever the previous release for the
// same board carried — an upgrade-chain floor rarely changes between
// releases. Re-derived when board/channel change, until the user edits it.
const minFwTouched = useRef(false)
const [minFwSource, setMinFwSource] = useState(null) // release the default came from
useEffect(() => {
if (isEdit || minFwTouched.current) return
if (hwType === 'bespoke' && !bespokeUid.trim()) return
let cancelled = false
api.get(`/firmware?hw_type=${encodeURIComponent(hwType)}`).then(data => {
if (cancelled || minFwTouched.current) return
// Newest first (backend sorts by uploaded_at desc). Prefer the same
// channel; fall back to the board's newest release on any channel.
const pool = (data?.firmware || []).filter(fw =>
hwType !== 'bespoke' || fw.bespoke_uid === bespokeUid.trim())
const prev = pool.find(fw => fw.channel === channel) || pool[0] || null
setMinFw(prev?.min_fw_version || '')
setMinFwSource(prev?.min_fw_version ? prev : null)
}).catch(() => { /* no default — field just stays empty */ })
return () => { cancelled = true }
}, [isEdit, hwType, channel, bespokeUid])
const handleSubmit = async (e) => { const handleSubmit = async (e) => {
e.preventDefault() e.preventDefault()
@@ -198,7 +220,10 @@ function FirmwareFormModal({ initial, onClose, onSaved }) {
{CHANNELS.map((c) => <option key={c} value={c}>{c}</option>)} {CHANNELS.map((c) => <option key={c} value={c}>{c}</option>)}
</FormField> </FormField>
<FormField label="Version" name="version" value={version} onChange={(e) => setVersion(e.target.value)} placeholder="1.5" required /> <FormField label="Version" name="version" value={version} onChange={(e) => setVersion(e.target.value)} placeholder="1.5" required />
<FormField label="Min FW" name="min_fw" value={minFw} onChange={(e) => setMinFw(e.target.value)} placeholder="e.g. 1.2" /> <FormField label="Min FW" name="min_fw" value={minFw}
onChange={(e) => { minFwTouched.current = true; setMinFwSource(null); setMinFw(e.target.value) }}
placeholder="e.g. 1.2"
hint={minFwSource ? `From v${minFwSource.version} (${minFwSource.channel})` : undefined} />
</div> </div>
<div> <div>
<p style={{ fontSize: 'var(--font-size-xs)', fontWeight: 'var(--font-weight-medium)', color: 'var(--color-text-muted)', marginBottom: 'var(--space-2)' }}>Update Type</p> <p style={{ fontSize: 'var(--font-size-xs)', fontWeight: 'var(--font-weight-medium)', color: 'var(--color-text-muted)', marginBottom: 'var(--space-2)' }}>Update Type</p>