Fix multi-printer filament mapping ignoring nozzle on dual-nozzle printers (#624)

The per-printer InlineMappingEditor showed filaments from both nozzles
  on H2D printers. The single-printer FilamentMapping dropdown was fixed
  in 29e9593 but the multi-printer code path was missed. Added nozzle_id
  filtering to both auto-match logic and dropdown options via shared
  autoMatchFilament() and filterFilamentsByNozzle() functions in
  amsHelpers.ts, with 10 regression tests.
This commit is contained in:
maziggy
2026-03-05 15:38:37 +01:00
parent becc4669b1
commit 1bc3da3fad
6 changed files with 565 additions and 404 deletions
@@ -16,6 +16,8 @@ import { getColorName } from '../../utils/colors';
import {
normalizeColorForCompare,
colorsAreSimilar,
autoMatchFilament,
filterFilamentsByNozzle,
} from '../../utils/amsHelpers';
import type { PrinterSelectorProps, AssignmentMode } from './types';
import type { PrinterMappingResult, PerPrinterConfig } from '../../hooks/useMultiPrinterFilamentMapping';
@@ -101,30 +103,8 @@ function InlineMappingEditor({
loaded = printerResult.loadedFilaments.find((f) => f.globalTrayId === currentMapping);
isManual = true;
} else {
// Auto-match logic
const usedTrayIds = new Set<number>(Object.values(printerResult.config.manualMappings));
const exactMatch = printerResult.loadedFilaments.find(
(f) =>
!usedTrayIds.has(f.globalTrayId) &&
f.type?.toUpperCase() === req.type?.toUpperCase() &&
normalizeColorForCompare(f.color) === normalizeColorForCompare(req.color)
);
const similarMatch = exactMatch
? undefined
: printerResult.loadedFilaments.find(
(f) =>
!usedTrayIds.has(f.globalTrayId) &&
f.type?.toUpperCase() === req.type?.toUpperCase() &&
colorsAreSimilar(f.color, req.color)
);
const typeOnlyMatch =
exactMatch || similarMatch
? undefined
: printerResult.loadedFilaments.find(
(f) => !usedTrayIds.has(f.globalTrayId) && f.type?.toUpperCase() === req.type?.toUpperCase()
);
loaded = exactMatch ?? similarMatch ?? typeOnlyMatch;
loaded = autoMatchFilament(req, printerResult.loadedFilaments, usedTrayIds) as LoadedFilament | undefined;
}
// Determine status
@@ -188,7 +168,8 @@ function InlineMappingEditor({
<option value="" className="bg-bambu-dark text-bambu-gray">
-- Select slot --
</option>
{printerResult.loadedFilaments.map((f) => (
{filterFilamentsByNozzle(printerResult.loadedFilaments, req.nozzle_id)
.map((f) => (
<option key={f.globalTrayId} value={f.globalTrayId} className="bg-bambu-dark text-white">
{f.label}: {f.type} ({f.colorName})
</option>