mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-06 14:11:35 +02:00
The edit dialog offered a printer picker and target-model dropdown for an item with alternatives. Saving left a row with variants AND a printer_id, and the scheduler's fixed-printer branch wins that race, so it dispatched a row whose library_file_id is still null and failed in the upload. PATCH now refuses printer/model changes on such an item — comparing against the current value, since the dialog re-sends target_model unchanged — and the route eager-loads variants, without which the guard could not see them and every PATCH response dropped the alternatives from its payload. Names come from a shared helper now. A cross-model item holds neither archive_id nor library_file_id until dispatch, so five separate inlined fallbacks all rendered "File #null"; they now read "x1c.gcode.3mf +1 more". The queue also grouped these under "Any H2D" — the first candidate mirrored onto the row — filing a job under a printer it might never run on. It groups as "Any H2D / X1C", matching the row beneath it.
77 lines
3.4 KiB
TypeScript
77 lines
3.4 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { Clock, Calendar, ChevronRight } from 'lucide-react';
|
|
import { Link } from 'react-router-dom';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { api } from '../api/client';
|
|
import { formatRelativeTime } from '../utils/date';
|
|
import { filterCompatibleQueueItems } from '../utils/printer';
|
|
import { queueItemDisplayName } from '../utils/queueItemName';
|
|
|
|
interface PrinterQueueWidgetProps {
|
|
printerId: number;
|
|
printerModel?: string | null;
|
|
loadedFilamentTypes?: Set<string>;
|
|
loadedFilaments?: Set<string>; // "TYPE:rrggbb" pairs for filament override color matching
|
|
loadedVariants?: Set<string>; // "TYPE:rrggbb:idx" triples for PLA sub-variant matching (#2650)
|
|
variant?: 'card' | 'panelExtension';
|
|
}
|
|
|
|
export function PrinterQueueWidget({ printerId, printerModel, loadedFilamentTypes, loadedFilaments, loadedVariants, variant = 'card' }: PrinterQueueWidgetProps) {
|
|
const { t } = useTranslation();
|
|
const { data: queue } = useQuery({
|
|
queryKey: ['queue', printerId, 'pending', printerModel],
|
|
queryFn: () => api.getQueue(printerId, 'pending', printerModel || undefined),
|
|
refetchInterval: 30000,
|
|
});
|
|
|
|
// Filter queue to items this printer can actually print (filament type + color check)
|
|
const compatibleQueue = queue ? filterCompatibleQueueItems(queue, loadedFilamentTypes, loadedFilaments, loadedVariants) : undefined;
|
|
const totalPending = compatibleQueue?.length || 0;
|
|
|
|
if (totalPending === 0) {
|
|
return null;
|
|
}
|
|
|
|
const nextItem = compatibleQueue?.[0];
|
|
|
|
// Passive next-in-queue preview. Plate-clear acknowledgment is handled by the
|
|
// card-level "Mark plate as cleared" button (PrintersPage.tsx). Having a
|
|
// second button in this widget caused the two controls to overlap whenever
|
|
// the plate-clear gate was up with auto-dispatch items queued — both POSTed
|
|
// to the same /clear-plate endpoint, so the widget button was pure noise.
|
|
const linkClassName = variant === 'panelExtension'
|
|
? 'block mt-2 border-t border-bambu-dark-tertiary pt-2 pl-1 hover:opacity-90 transition-opacity'
|
|
: 'block mb-3 p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors';
|
|
|
|
return (
|
|
<Link
|
|
to="/queue"
|
|
className={linkClassName}
|
|
>
|
|
<div className="flex items-center justify-between gap-3">
|
|
<div className="flex items-center gap-3 min-w-0 flex-1">
|
|
<Calendar className="w-5 h-5 text-yellow-600 dark:text-yellow-400 flex-shrink-0" />
|
|
<div className="min-w-0 flex-1">
|
|
<p className="text-xs text-bambu-gray">{t('queue.nextInQueue')}</p>
|
|
<p className="text-sm text-white truncate">
|
|
{nextItem ? queueItemDisplayName(nextItem) : ''}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div className="flex items-center gap-2 flex-shrink-0">
|
|
<span className="text-xs text-bambu-gray flex items-center gap-1">
|
|
<Clock className="w-3 h-3" />
|
|
{nextItem?.scheduled_time ? formatRelativeTime(nextItem.scheduled_time, 'system', t) : t('time.waiting')}
|
|
</span>
|
|
{totalPending > 1 && (
|
|
<span className="text-xs px-1.5 py-0.5 bg-yellow-100 dark:bg-yellow-400/20 text-yellow-700 dark:text-yellow-400 rounded">
|
|
+{totalPending - 1}
|
|
</span>
|
|
)}
|
|
<ChevronRight className="w-4 h-4 text-bambu-gray" />
|
|
</div>
|
|
</div>
|
|
</Link>
|
|
);
|
|
}
|