fix: block empty progression step saves

This commit is contained in:
Manuel authored and mflova committed 2026-08-29 22:39:15 +00:00
1 parent 9216aa2f02
commit 0ab0f47259
4 files changed
+43 -17

No files matched your search

+2 -2
View File
@@ -115,13 +115,13 @@ export function Segmented({ options, value, onChange, className = '' }) {
/* ============================ stepper ============================ */
export function Stepper({ value, step = 1, onChange, decimal = true, className = '', label, unit }) {
export function Stepper({ value, step = 1, onChange, decimal = true, className = '', label, unit, invalid = false }) {
const set = v => onChange(Math.max(0, Math.round((v || 0) * 100) / 100))
const inner = (
<div className={'stp ' + className}>
<button onClick={() => set((+value || 0) - step)} aria-label="Decrease"><Icon name="minus" /></button>
<span className="val">
<NumberField value={value} decimal={decimal} onChange={onChange} />
<NumberField value={value} decimal={decimal} onChange={onChange} aria-invalid={invalid ? 'true' : undefined} />
{unit && <i>{unit}</i>}
</span>
<button onClick={() => set((+value || 0) + step)} aria-label="Increase"><Icon name="plus" /></button>
+1
View File
@@ -526,6 +526,7 @@ h4.sec{
-moz-appearance:textfield;appearance:textfield;
}
.stp .num::-webkit-inner-spin-button{display:none}
.stp.invalid{box-shadow:inset 0 0 0 1px var(--red)}
/* --- slider --- */
.sld{position:relative;height:32px;display:flex;align-items:center;cursor:pointer;touch-action:none}
+16 -3
View File
@@ -547,12 +547,18 @@ export const equipmentProfileSheet = profile => ui().openSheet(close => <Equipme
// Progression settings for one exercise (issue #17). Shown inside the config sheet because
// "how does this lift go up" belongs next to sets and reps, not in a separate screen. Left
// on "follow the routine" it inherits, so most people never touch it.
const progressionStepOf = (c, mode, ex, unit) =>
c.inc >= 0 ? c.inc : (mode === 'time' ? 5 : defaultIncrement(ex.id, unit))
const progressionStepIsValid = (step, policy) =>
policy === 'off' || (Number.isFinite(step) && step > 0)
function ProgressionFields({ ex, mode, c, setC, routine, unit }) {
const options = POLICIES_FOR[mode] || ['off']
if (options.length < 2) return null
const inherited = policyFor({ id: ex.id }, routine, mode)
const active = policyFor({ ...c, id: ex.id }, routine, mode)
const inc = c.inc >= 0 ? c.inc : (mode === 'time' ? 5 : defaultIncrement(ex.id, unit))
const inc = progressionStepOf(c, mode, ex, unit)
const invalid = !progressionStepIsValid(inc, active)
return <>
<h4 className="sec">{t('Progression')}</h4>
<div className="sect-b" style={{ marginBottom: 8 }}>
@@ -563,10 +569,14 @@ function ProgressionFields({ ex, mode, c, setC, routine, unit }) {
<div className="small dim" style={{ marginBottom: active === 'off' ? 18 : 10 }}>{t(POLICY_DESC[active])}</div>
{active !== 'off' && <div className="row cfgrow" style={{ marginBottom: 18 }}>
<Stepper label={mode === 'time' ? t('Step (seconds)') : t('Step ({0})', unit)} value={inc}
step={mode === 'time' ? 5 : 1.25} decimal={mode !== 'time'} onChange={v => setC(x => ({ ...x, inc: v }))} />
step={mode === 'time' ? 5 : 1.25} decimal={mode !== 'time'} invalid={invalid} className={invalid ? 'invalid' : ''}
onChange={v => setC(x => ({ ...x, inc: v }))} />
{active === 'double' && <Stepper label={t('Reps from')} value={c.repsMin || Math.max(1, (c.reps || 10) - 2)}
step={1} decimal={false} onChange={v => setC(x => ({ ...x, repsMin: v }))} />}
</div>}
{invalid && <div className="small" role="alert" style={{ color: 'var(--red)', marginTop: -10, marginBottom: 18 }}>
{t('Enter a positive step to use this progression rule.')}
</div>}
</>
}
@@ -580,9 +590,12 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) {
// Both default from the dataset and are then whatever the config says — see isBw.
const bw = !cardio && isBw({ ...c, id: ex.id })
const perSide = isPerSide(c)
const progressionPolicy = policyFor({ ...c, id: ex.id }, routine, mode)
const progressionStepInvalid = !progressionStepIsValid(progressionStepOf(c, mode, ex, st.unit), progressionPolicy)
// Keep whatever the other mode already had (sets, weight) and fill only what is missing.
const setMode = m => setC(x => ({ ...defaultConfig(ex.id, m), ...x, mode: m }))
const save = () => {
if (progressionStepInvalid) return
close()
const sets = Math.max(1, Math.round(c.sets) || (cardio ? 1 : 3))
// Only carry progression settings that differ from the inherited default, so a plan file
@@ -756,7 +769,7 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) {
<textarea className="input" rows={3} maxLength={500} style={{ marginBottom: 18 }}
placeholder={t('Note (optional) — loading cues, "bar only then +1 plate/side each set", anything worth remembering here')}
value={c.note || ''} onChange={e => setC(x => ({ ...x, note: e.target.value }))} />
<Button variant="primary" onClick={save}>{existing ? t('Save') : t('Add to routine')}</Button>
<Button variant="primary" disabled={progressionStepInvalid} onClick={save}>{existing ? t('Save') : t('Add to routine')}</Button>
{ex.custom && <><div style={{ height: 8 }} /><Button icon="pencil" onClick={() => { close(); customExSheet(ex) }}>{t('Edit or delete this exercise')}</Button></>}
{onDelete && <><div style={{ height: 8 }} /><Button variant="danger" onClick={() => { close(); onDelete() }}>{t('Remove from routine')}</Button></>}
</>
+24 -12
View File
@@ -51,19 +51,31 @@ describe('exercise configuration progression step', () => {
expect(step.value).toBe('0.5')
})
it('persists a positive decimal but omits a cleared progression increment', () => {
const positive = renderConfig()
act(() => { type(positive.step, '0,5') })
const positiveSave = [...positive.host.querySelectorAll('button')]
it('blocks saving without a positive progression step but accepts a positive decimal', () => {
const config = renderConfig()
const save = [...config.host.querySelectorAll('button')]
.find(b => /^(save|add to routine)$/i.test(b.textContent.trim()))
act(() => { positiveSave.click() })
expect(positive.onSave).toHaveBeenCalledWith(expect.objectContaining({ inc: 0.5 }))
const empty = renderConfig()
act(() => { type(empty.step, '') })
const emptySave = [...empty.host.querySelectorAll('button')]
.find(b => /^(save|add to routine)$/i.test(b.textContent.trim()))
act(() => { emptySave.click() })
expect(empty.onSave.mock.calls[0][0]).not.toHaveProperty('inc')
act(() => { type(config.step, '') })
expect(config.step.value).toBe('')
expect(config.step.getAttribute('aria-invalid')).toBe('true')
expect(save.disabled).toBe(true)
expect(config.host.textContent).toContain('Enter a positive step to use this progression rule.')
act(() => { save.click() })
expect(config.onSave).not.toHaveBeenCalled()
expect(useUI.getState().sheets).toHaveLength(1)
act(() => { type(config.step, '0') })
expect(save.disabled).toBe(true)
act(() => { type(config.step, '0,5') })
expect(config.step.value).toBe('0.5')
expect(config.step.getAttribute('aria-invalid')).not.toBe('true')
expect(save.disabled).toBe(false)
act(() => { save.click() })
expect(config.onSave).toHaveBeenCalledWith(expect.objectContaining({ inc: 0.5 }))
expect(useUI.getState().sheets).toHaveLength(0)
})
})