Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

Follow-up to !140: choosing a role's own default exercise is not "Custom"

Duarte Santose59c621fbca4
diff --git a/frontend/src/lib/structuralBalance.js b/frontend/src/lib/structuralBalance.js
index 768c8b2bb..fd687f51d 100644
--- a/frontend/src/lib/structuralBalance.js
+++ b/frontend/src/lib/structuralBalance.js
@@ -189,7 +189,12 @@ export function withOverride(overrides, key, exId, now = Date.now()) {
return { ...(overrides || {}), [key]: { id: exId || null, _ts: now } }
}
-const overrideFor = (S, template, role) => overrideIdOf(S.balanceOverrides?.[overrideKey(template, role)])
+// A choice of the role's own default exercise is the default: not "Custom", and read across the
+// whole whitelist like the default is, rather than narrowed to that one exercise.
+const overrideFor = (S, template, role) => {
+ const id = overrideIdOf(S.balanceOverrides?.[overrideKey(template, role)])
+ return id && id !== role.exerciseIds[0] ? id : null
+}
// The exercise ids to resolve "current" from: the user's chosen override if one exists for this
// role, otherwise the role's curated whitelist.
diff --git a/frontend/src/lib/structuralBalance.test.js b/frontend/src/lib/structuralBalance.test.js
index 48f7aceb3..5294971a7 100644
--- a/frontend/src/lib/structuralBalance.test.js
+++ b/frontend/src/lib/structuralBalance.test.js
@@ -566,6 +566,24 @@ describe('stored overrides', () => {
})
})
+describe('an override of the role\'s own default exercise', () => {
+ it('is not custom, and reads the whole whitelist like the default', () => {
+ const template = TEMPLATES.atg
+ const stepUp = findRole(template, 'stepUp') // 0114 barbell step-up, then 0431 dumbbell step-up
+ const S = {
+ unit: 'kg', body: 'male', bodyweight: [{ d: '2026-01-01', w: 80 }],
+ balanceOverrides: { [overrideKey(template, stepUp)]: { id: '0114', _ts: 5 } },
+ workouts: [workoutAt('0431', NOW, [setDone(40, 15)])],
+ }
+ const row = computeBalance(S, template).find(r => r.roleId === 'stepUp')
+ expect(row).toMatchObject({ isOverridden: false, configuredExerciseId: '0114', mappedExerciseId: '0431' })
+ expect(row.status).toBe(BALANCE_STATUSES.BALANCED)
+
+ S.balanceOverrides = { [overrideKey(template, stepUp)]: { id: '0431', _ts: 6 } } // the fallback is a real choice
+ expect(computeBalance(S, template).find(r => r.roleId === 'stepUp')).toMatchObject({ isOverridden: true, configuredExerciseId: '0431' })
+ })
+})
+
describe('computeBalance — full template end-to-end (Poliquin)', () => {
it('resolves every role in order, mixing logged and unlogged roles', () => {
const template = TEMPLATES.poliquin
diff --git a/frontend/src/views/StructuralBalance.test.jsx b/frontend/src/views/StructuralBalance.test.jsx
index 7c381d4a5..dd1b8d07a 100644
--- a/frontend/src/views/StructuralBalance.test.jsx
+++ b/frontend/src/views/StructuralBalance.test.jsx
@@ -109,6 +109,17 @@ describe('StructuralBalance view', () => {
expect(host.querySelector('[data-role-id="narrowBench"] [data-exercise-name]').textContent).toBe('barbell close-grip bench press')
})
+ it('picking a role\'s own default exercise does not mark it custom', () => {
+ const host = render()
+ const row = host.querySelector('[data-role-id="inclineBench"]')
+ act(() => [...row.querySelectorAll('button')].find(b => b.textContent.includes('Change exercise')).click())
+ const picker = useUI.getState().sheets.at(-1)
+ act(() => picker.render(picker.close).props.onPick({ id: '0047' })) // barbell incline bench press, the role's default
+ const after = host.querySelector('[data-role-id="inclineBench"]')
+ expect(after.textContent).not.toContain('Custom')
+ expect([...after.querySelectorAll('button')].some(b => b.textContent.includes('Use default exercise'))).toBe(false)
+ })
+
it('the back chevron navigates to /stats', () => {
const host = render()
act(() => host.querySelector('.iconbtn').click())