diff --git a/frontend/src/components/AssignSpoolModal.tsx b/frontend/src/components/AssignSpoolModal.tsx index 45692a3c0..860229d31 100644 --- a/frontend/src/components/AssignSpoolModal.tsx +++ b/frontend/src/components/AssignSpoolModal.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { useTranslation } from 'react-i18next'; import { X, Loader2, Package, Search } from 'lucide-react'; @@ -27,7 +27,11 @@ export function AssignSpoolModal({ isOpen, onClose, printerId, amsId, trayId, tr const { t } = useTranslation(); const queryClient = useQueryClient(); const { showToast } = useToast(); + const [disableFiltering, setDisableFiltering] = useState(false); const [selectedSpoolId, setSelectedSpoolId] = useState(null); + useEffect(() => { + setSelectedSpoolId(null); + }, [disableFiltering]); const [searchFilter, setSearchFilter] = useState(''); const [pendingAssignId, setPendingAssignId] = useState(null); const [showMismatchConfirm, setShowMismatchConfirm] = useState(false); @@ -39,6 +43,12 @@ export function AssignSpoolModal({ isOpen, onClose, printerId, amsId, trayId, tr trayProfile?: string; } | null>(null); + useEffect(() => { + if (isOpen) { + setDisableFiltering(false); + } + }, [isOpen]); + const { data: spools, isLoading } = useQuery({ queryKey: ['inventory-spools'], queryFn: () => api.getSpools(), @@ -128,16 +138,28 @@ export function AssignSpoolModal({ isOpen, onClose, printerId, amsId, trayId, tr !assignedSpoolIds.has(spool.id) && (isExternalSlot || (!spool.tag_uid && !spool.tray_uuid)) ); - const filteredSpools = manualSpools?.filter((spool: InventorySpool) => { - if (!searchFilter) return true; + // Filtering logic with toggle: search filter always applies, AMS tray profile filter is optional + let filteredSpools = manualSpools; + if (!disableFiltering) { + if (trayInfo?.profile || trayInfo?.type) { + const trayProfile = normalizeValue(trayInfo.profile || trayInfo.type); + filteredSpools = filteredSpools?.filter((spool: InventorySpool) => { + const spoolProfile = normalizeValue(spool.slicer_filament_name || spool.slicer_filament); + return trayProfile && spoolProfile && spoolProfile === trayProfile; + }); + } + } + if (searchFilter && filteredSpools) { const q = searchFilter.toLowerCase(); - return ( - spool.material.toLowerCase().includes(q) || - (spool.brand?.toLowerCase().includes(q) ?? false) || - (spool.color_name?.toLowerCase().includes(q) ?? false) || - (spool.subtype?.toLowerCase().includes(q) ?? false) - ); - }); + filteredSpools = filteredSpools.filter((spool: InventorySpool) => { + return ( + spool.material.toLowerCase().includes(q) || + (spool.brand?.toLowerCase().includes(q) ?? false) || + (spool.color_name?.toLowerCase().includes(q) ?? false) || + (spool.subtype?.toLowerCase().includes(q) ?? false) + ); + }); + } const handleAssign = () => { if (!selectedSpoolId) return; @@ -192,13 +214,13 @@ export function AssignSpoolModal({ isOpen, onClose, printerId, amsId, trayId, tr return ( <> -
+
-
+
{/* Header */}
@@ -214,7 +236,7 @@ export function AssignSpoolModal({ isOpen, onClose, printerId, amsId, trayId, tr
{/* Content */} -
+
{/* Tray info */} {trayInfo && (
@@ -295,27 +317,41 @@ export function AssignSpoolModal({ isOpen, onClose, printerId, amsId, trayId, tr
- {/* Footer */} -
- - + {/* Footer with filtering toggle */} +
+
+ setDisableFiltering(v => !v)} + className="accent-bambu-green w-4 h-4 rounded focus:ring-0 border-bambu-dark-tertiary" + /> + +
+
+ + +
diff --git a/frontend/src/i18n/locales/de.ts b/frontend/src/i18n/locales/de.ts index 22cb8e795..cd02290c4 100644 --- a/frontend/src/i18n/locales/de.ts +++ b/frontend/src/i18n/locales/de.ts @@ -3028,6 +3028,7 @@ export default { assigned: 'Zugewiesen', assigning: 'Wird zugewiesen...', searchSpools: 'Spulen suchen...', + showAllSpools: 'Alle Spulen anzeigen', allMaterials: 'Alle Materialien', filterByBrand: 'Nach Marke filtern...', showArchived: 'Archivierte anzeigen', diff --git a/frontend/src/i18n/locales/en.ts b/frontend/src/i18n/locales/en.ts index e2d73b0b1..4c6d2bbda 100644 --- a/frontend/src/i18n/locales/en.ts +++ b/frontend/src/i18n/locales/en.ts @@ -3029,6 +3029,7 @@ export default { assigned: 'Assigned', assigning: 'Assigning...', searchSpools: 'Search spools...', + showAllSpools: 'Show all spools', allMaterials: 'All Materials', filterByBrand: 'Filter by brand...', showArchived: 'Show archived', diff --git a/frontend/src/i18n/locales/fr.ts b/frontend/src/i18n/locales/fr.ts index b56429a69..d879f77b6 100644 --- a/frontend/src/i18n/locales/fr.ts +++ b/frontend/src/i18n/locales/fr.ts @@ -3015,6 +3015,7 @@ export default { assigned: 'Assigné', assigning: 'Assignation...', searchSpools: 'Chercher bobines...', + showAllSpools: 'Afficher toutes les bobines', allMaterials: 'Tous Matériaux', filterByBrand: 'Filtrer par marque...', showArchived: 'Afficher archivées', diff --git a/frontend/src/i18n/locales/it.ts b/frontend/src/i18n/locales/it.ts index 50e7847e3..c9b45284b 100644 --- a/frontend/src/i18n/locales/it.ts +++ b/frontend/src/i18n/locales/it.ts @@ -3014,6 +3014,7 @@ export default { assigned: 'Assegnato', assigning: 'Assegnazione...', searchSpools: 'Cerca bobine...', + showAllSpools: 'Mostra tutte le bobine', allMaterials: 'Tutti i Materiali', filterByBrand: 'Filtra per marchio...', showArchived: 'Mostra archiviate', diff --git a/frontend/src/i18n/locales/ja.ts b/frontend/src/i18n/locales/ja.ts index dd7b6b678..4cae23ec4 100644 --- a/frontend/src/i18n/locales/ja.ts +++ b/frontend/src/i18n/locales/ja.ts @@ -3027,6 +3027,7 @@ export default { assigned: '割り当て済み', assigning: '割り当て中...', searchSpools: 'スプールを検索...', + showAllSpools: 'すべてのスプールを表示', allMaterials: 'すべての素材', filterByBrand: 'ブランドで絞り込み...', showArchived: 'アーカイブ済みを表示', diff --git a/frontend/src/i18n/locales/pt-BR.ts b/frontend/src/i18n/locales/pt-BR.ts index 26dbe70f3..283626b9d 100644 --- a/frontend/src/i18n/locales/pt-BR.ts +++ b/frontend/src/i18n/locales/pt-BR.ts @@ -3014,6 +3014,7 @@ export default { assigned: 'Atribuído', assigning: 'Atribuindo...', searchSpools: 'Pesquisar carretéis...', + showAllSpools: 'Mostrar todos os carretéis', allMaterials: 'Todos os Materiais', filterByBrand: 'Filtrar por marca...', showArchived: 'Mostrar arquivados', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 8a0b25887..05312c5b9 100644 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -3019,6 +3019,7 @@ export default { assigned: '已分配', assigning: '分配中...', searchSpools: '搜索耗材...', + showAllSpools: '显示所有耗材', allMaterials: '所有材料', filterByBrand: '按品牌筛选...', showArchived: '显示已归档',