|
@@ -5,7 +5,7 @@ import { Circle, Check, AlertTriangle, RefreshCw, ChevronDown, ChevronUp, Palett
|
|
|
import { api } from '../../api/client';
|
|
import { api } from '../../api/client';
|
|
|
import type { SlotSpoolIdentity } from '../../api/client';
|
|
import type { SlotSpoolIdentity } from '../../api/client';
|
|
|
import { useFilamentMapping } from '../../hooks/useFilamentMapping';
|
|
import { useFilamentMapping } from '../../hooks/useFilamentMapping';
|
|
|
-import { getGlobalTrayId, effectivePreferLowest, FTS_INLET_SIDE, normalizeColorForCompare } from '../../utils/amsHelpers';
|
|
|
|
|
|
|
+import { effectivePreferLowest, FTS_INLET_SIDE, normalizeColorForCompare } from '../../utils/amsHelpers';
|
|
|
import { disambiguateColorNames, getColorName } from '../../utils/colors';
|
|
import { disambiguateColorNames, getColorName } from '../../utils/colors';
|
|
|
import { SlotPicker } from './SlotPicker';
|
|
import { SlotPicker } from './SlotPicker';
|
|
|
import { displayHex } from './displayHex';
|
|
import { displayHex } from './displayHex';
|
|
@@ -98,12 +98,6 @@ export function FilamentMapping({
|
|
|
enabled: !!printerId,
|
|
enabled: !!printerId,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- const { data: assignments } = useQuery({
|
|
|
|
|
- queryKey: ['spool-assignments', printerId],
|
|
|
|
|
- queryFn: () => api.getAssignments(printerId),
|
|
|
|
|
- enabled: !!printerId,
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
// Settings + inventory map drive the same prefer-lowest + AMS-backup gate
|
|
// Settings + inventory map drive the same prefer-lowest + AMS-backup gate
|
|
|
// the dispatcher uses (#1766). Without this, the per-slot dropdown's
|
|
// the dispatcher uses (#1766). Without this, the per-slot dropdown's
|
|
|
// auto-suggestion could disagree with what actually gets dispatched.
|
|
// auto-suggestion could disagree with what actually gets dispatched.
|
|
@@ -167,30 +161,25 @@ export function FilamentMapping({
|
|
|
// resolved — never blanks out the required row.
|
|
// resolved — never blanks out the required row.
|
|
|
const filamentLabels = useFilamentLabels(filamentReqs?.filaments);
|
|
const filamentLabels = useFilamentLabels(filamentReqs?.filaments);
|
|
|
|
|
|
|
|
|
|
+ // Price and grams left per slot, from the mode-aware bindings above. The
|
|
|
|
|
+ // built-in assignment table these came from holds nothing in Spoolman mode,
|
|
|
|
|
+ // or rows from before the switch, so the estimate priced a Spoolman print at
|
|
|
|
|
+ // the default rate or at a spool the printer is not drawing on.
|
|
|
const trayCostMap = useMemo(() => {
|
|
const trayCostMap = useMemo(() => {
|
|
|
const map = new Map<number, number | null>();
|
|
const map = new Map<number, number | null>();
|
|
|
- for (const assignment of assignments || []) {
|
|
|
|
|
- const isExternal = assignment.ams_id === 255;
|
|
|
|
|
- const globalTrayId = getGlobalTrayId(assignment.ams_id, assignment.tray_id, isExternal);
|
|
|
|
|
- map.set(globalTrayId, assignment.spool?.cost_per_kg ?? null);
|
|
|
|
|
|
|
+ for (const slot of inventoryRemain?.slot_materials ?? []) {
|
|
|
|
|
+ map.set(slot.global_tray_id, slot.cost_per_kg ?? null);
|
|
|
}
|
|
}
|
|
|
return map;
|
|
return map;
|
|
|
- }, [assignments]);
|
|
|
|
|
|
|
+ }, [inventoryRemain]);
|
|
|
|
|
|
|
|
const trayRemainingWeightMap = useMemo(() => {
|
|
const trayRemainingWeightMap = useMemo(() => {
|
|
|
const map = new Map<number, number | null>();
|
|
const map = new Map<number, number | null>();
|
|
|
- for (const assignment of assignments || []) {
|
|
|
|
|
- const isExternal = assignment.ams_id === 255;
|
|
|
|
|
- const globalTrayId = getGlobalTrayId(assignment.ams_id, assignment.tray_id, isExternal);
|
|
|
|
|
- const spool = assignment.spool;
|
|
|
|
|
- if (!spool) {
|
|
|
|
|
- map.set(globalTrayId, null);
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- map.set(globalTrayId, Math.max(0, Math.round((spool.label_weight ?? 0) - (spool.weight_used ?? 0))));
|
|
|
|
|
|
|
+ for (const slot of inventoryRemain?.slot_materials ?? []) {
|
|
|
|
|
+ map.set(slot.global_tray_id, Math.max(0, Math.round(slot.remaining_g)));
|
|
|
}
|
|
}
|
|
|
return map;
|
|
return map;
|
|
|
- }, [assignments]);
|
|
|
|
|
|
|
+ }, [inventoryRemain]);
|
|
|
|
|
|
|
|
const totalCost = useMemo(() => {
|
|
const totalCost = useMemo(() => {
|
|
|
let total = 0;
|
|
let total = 0;
|