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

This commit is contained in:
Matteo Parenti
2026-02-18 12:02:55 +01:00
parent e17b55fe22
commit 87c6bfe672
3 changed files with 6 additions and 9 deletions
@@ -258,10 +258,8 @@ describe('SpoolFormModal weightTouched', () => {
fireEvent.focus(weightPicker!);
// 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
const addButtons = screen.getAllByRole('button', { name: /add spool/i });
@@ -317,7 +315,7 @@ describe('SpoolFormModal weightTouched', () => {
const bambuFound = weightInputs.some(input =>
input.value === 'Bambu Lab 250g' || input.getAttribute('value') === 'Bambu Lab 250g'
);
expect(bambuFound || screen.queryByText('Bambu Lab 250g')).toBeTruthy();
expect(bambuFound).toBeTruthy();
});
});
});
+1 -1
View File
@@ -171,7 +171,7 @@ export function SpoolFormModal({ isOpen, onClose, spool, printersWithCalibration
rgba: spool.rgba || '808080FF',
label_weight: spool.label_weight || 1000,
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,
slicer_filament: spool.slicer_filament || '',
note: spool.note || '',
@@ -54,9 +54,8 @@ function SpoolWeightPicker({
if (matches.length === 1) {
onCatalogIdChange(matches[0].id);
} 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);
}
}