From c63bfd3859ac8a8caa9643a0b3a1deee047bccab Mon Sep 17 00:00:00 2001 From: Pouzor Date: Sat, 8 Aug 2026 01:14:35 +0200 Subject: [PATCH] fix(rack): keep Import links usable after a run that matched nothing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit importCablesFromNetwork latched networkImportDone whatever the outcome. Click Import links before racking anything and the toast says "No matching link found — rack the devices first", then the button is disabled for the rest of the session: it asks for a retry and forbids it. Only a design switch or a reload cleared the flag. It now latches on success only. ha-relevant: no --- frontend/src/rack/__tests__/store.test.ts | 13 +++++++++++++ frontend/src/rack/store.ts | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/frontend/src/rack/__tests__/store.test.ts b/frontend/src/rack/__tests__/store.test.ts index a25634b..55ffb0e 100644 --- a/frontend/src/rack/__tests__/store.test.ts +++ b/frontend/src/rack/__tests__/store.test.ts @@ -423,6 +423,19 @@ describe('cables', () => { expect(store().importCablesFromNetwork(demoNetworkLinks())).toBe(0) }) + it('stays available after an import that matched nothing', () => { + // Nothing racked for these hints yet: the run creates nothing, and the user + // is told to rack the devices first — so the button has to survive it. + expect(store().importCablesFromNetwork([ + { from: 'node-nowhere-a', to: 'node-nowhere-b', type: 'ethernet' }, + ])).toBe(0) + expect(store().networkImportDone).toBe(false) + + store().mountFromInventory('inv-sw8', 'rack-main', { uStart: 4 }) + expect(store().importCablesFromNetwork(demoNetworkLinks())).toBeGreaterThan(0) + expect(store().networkImportDone).toBe(true) + }) + it('skips hints whose devices are not racked', () => { // inv-jbod is never mounted in the demo, so its hint cannot resolve. store().importCablesFromNetwork(demoNetworkLinks()) diff --git a/frontend/src/rack/store.ts b/frontend/src/rack/store.ts index 3fb0fc2..6ad60ac 100644 --- a/frontend/src/rack/store.ts +++ b/frontend/src/rack/store.ts @@ -673,7 +673,10 @@ export const useRackStore = create((set, get) => { ) if (id) created++ } - set({ networkImportDone: true }) + // Only latch on success. An import run before anything is racked matches + // nothing and says so — disabling the button then would kill the retry the + // toast just asked for. + if (created > 0) set({ networkImportDone: true }) return created },