Fix "Clear Plate" button shown on printers without matching filament color (#486)

When a print was queued to "any printer" with a filament color override
(e.g., white PETG), the "Clear Plate & Start Next" button appeared on
printers that had the right type but wrong color. The backend scheduler
already rejected color mismatches, but the frontend only checked filament
types. Now passes loaded type+color pairs from AMS status to the widget
and filters against filament_overrides, mirroring the backend's
_count_override_color_matches() logic.
This commit is contained in:
maziggy
2026-02-27 08:03:21 +01:00
parent 2c8fbf3e33
commit ad6108c8a7
6 changed files with 314 additions and 110 deletions
+20 -5
View File
@@ -13,9 +13,10 @@ interface PrinterQueueWidgetProps {
printerState?: string | null;
plateCleared?: boolean;
loadedFilamentTypes?: Set<string>;
loadedFilaments?: Set<string>; // "TYPE:rrggbb" pairs for filament override color matching
}
export function PrinterQueueWidget({ printerId, printerModel, printerState, plateCleared, loadedFilamentTypes }: PrinterQueueWidgetProps) {
export function PrinterQueueWidget({ printerId, printerModel, printerState, plateCleared, loadedFilamentTypes, loadedFilaments }: PrinterQueueWidgetProps) {
const { t } = useTranslation();
const queryClient = useQueryClient();
const { showToast } = useToast();
@@ -38,11 +39,25 @@ export function PrinterQueueWidget({ printerId, printerModel, printerState, plat
},
});
// Filter queue to items this printer can actually print (filament type check)
// Filter queue to items this printer can actually print (filament type + color check)
const compatibleQueue = queue?.filter(item => {
if (!item.required_filament_types?.length) return true;
if (!loadedFilamentTypes?.size) return true;
return item.required_filament_types.every((t: string) => loadedFilamentTypes.has(t.toUpperCase()));
// Type check: all required filament types must be loaded
if (item.required_filament_types?.length && loadedFilamentTypes?.size) {
if (!item.required_filament_types.every((t: string) => loadedFilamentTypes.has(t.toUpperCase()))) {
return false;
}
}
// Color check: if filament overrides specify colors, at least one must match
// Mirrors backend _count_override_color_matches() logic
if (item.filament_overrides?.length && loadedFilaments?.size) {
const hasColorMatch = item.filament_overrides.some(o => {
const oType = (o.type || '').toUpperCase();
const oColor = (o.color || '').replace('#', '').toLowerCase().slice(0, 6);
return loadedFilaments.has(`${oType}:${oColor}`);
});
if (!hasColorMatch) return false;
}
return true;
});
const nextItem = compatibleQueue?.[0];