fix(rack): keep Import links usable after a run that matched nothing

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
This commit is contained in:
Pouzor
2026-08-09 20:35:23 +02:00
committed by Pouzor - Rémy Jardient
parent 2af6f728d7
commit c63bfd3859
2 changed files with 17 additions and 1 deletions
+13
View File
@@ -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())
+4 -1
View File
@@ -673,7 +673,10 @@ export const useRackStore = create<RackState>((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
},