Просмотр исходного кода

fix(spool-form): improve handling of core_weight_catalog_id and catalog ID selection logic

Matteo Parenti 3 месяцев назад
Родитель
Сommit
87c6bfe672

+ 3 - 5
frontend/src/__tests__/components/SpoolFormModal.test.tsx

@@ -258,10 +258,8 @@ describe('SpoolFormModal weightTouched', () => {
     fireEvent.focus(weightPicker!);
     fireEvent.focus(weightPicker!);
 
 
     // Click on "Bambu Lab 250g" option
     // Click on "Bambu Lab 250g" option
-    await waitFor(() => {
-      const bambuOption = screen.queryByText('Bambu Lab 250g');
-      if (bambuOption) fireEvent.click(bambuOption);
-    });
+    const bambuOption = await screen.findByText('Bambu Lab 250g');
+    fireEvent.click(bambuOption);
 
 
     // Click the add spool button
     // Click the add spool button
     const addButtons = screen.getAllByRole('button', { name: /add spool/i });
     const addButtons = screen.getAllByRole('button', { name: /add spool/i });
@@ -317,7 +315,7 @@ describe('SpoolFormModal weightTouched', () => {
       const bambuFound = weightInputs.some(input =>
       const bambuFound = weightInputs.some(input =>
         input.value === 'Bambu Lab 250g' || input.getAttribute('value') === 'Bambu Lab 250g'
         input.value === 'Bambu Lab 250g' || input.getAttribute('value') === 'Bambu Lab 250g'
       );
       );
-      expect(bambuFound || screen.queryByText('Bambu Lab 250g')).toBeTruthy();
+      expect(bambuFound).toBeTruthy();
     });
     });
   });
   });
 });
 });

+ 1 - 1
frontend/src/components/SpoolFormModal.tsx

@@ -171,7 +171,7 @@ export function SpoolFormModal({ isOpen, onClose, spool, printersWithCalibration
           rgba: spool.rgba || '808080FF',
           rgba: spool.rgba || '808080FF',
           label_weight: spool.label_weight || 1000,
           label_weight: spool.label_weight || 1000,
           core_weight: spool.core_weight || 250,
           core_weight: spool.core_weight || 250,
-          core_weight_catalog_id: spool.core_weight_catalog_id || null,
+          core_weight_catalog_id: spool.core_weight_catalog_id ?? null,
           weight_used: spool.weight_used || 0,
           weight_used: spool.weight_used || 0,
           slicer_filament: spool.slicer_filament || '',
           slicer_filament: spool.slicer_filament || '',
           note: spool.note || '',
           note: spool.note || '',

+ 2 - 3
frontend/src/components/spool-form/AdditionalSection.tsx

@@ -54,9 +54,8 @@ function SpoolWeightPicker({
     if (matches.length === 1) {
     if (matches.length === 1) {
       onCatalogIdChange(matches[0].id);
       onCatalogIdChange(matches[0].id);
     } else if (matches.length === 0) {
     } else if (matches.length === 0) {
-      // No matches, clear selection only if we don't have a catalogId
-      // (to avoid clearing valid IDs when catalog hasn't loaded yet)
-      if (!catalogId) {
+      // No matches, clear selection to prevent stale catalog ID
+      if (catalogId !== null) {
         onCatalogIdChange(null);
         onCatalogIdChange(null);
       }
       }
     }
     }