Fix handling of undefined printer items in AddLocalPrinterScrollView

This commit addresses an issue wherein undefined current items were not properly handled in the AddLocalPrinterScrollView module. We've changed the code so that it now checks if currentItem and currentItem.name exist before attempting to assign. If they don't exist, we now set default values to avoid null or undefined references. This prevents potential errors or inconsistent behaviors in the UI.

CURA-11003
This commit is contained in:
Saumya Jain 2024-04-10 17:24:55 +02:00
parent 3908db7696
commit 1457569aeb

View file

@ -32,7 +32,7 @@ Item
onCurrentItemChanged: onCurrentItemChanged:
{ {
printerName = currentItem == null ? "" : currentItem.name printerName = currentItem && currentItem.name? currentItem.name: ""
} }
function updateCurrentItemUponSectionChange(section) function updateCurrentItemUponSectionChange(section)
@ -53,12 +53,18 @@ Item
{ {
machineList.currentIndex = index; machineList.currentIndex = index;
currentItem = machineList.model.getItem(index); currentItem = machineList.model.getItem(index);
if (currentItem != undefined) if (currentItem && currentItem.name)
{ {
machineName.text = currentItem.name machineName.text = currentItem.name
manufacturer.text = currentItem.metadata["manufacturer"] manufacturer.text = currentItem.metadata["manufacturer"]
author.text = currentItem.metadata["author"] author.text = currentItem.metadata["author"]
} }
else
{
machineName.text = "No printers Found"
manufacturer.text = ""
author.text = ""
}
} }
Component.onCompleted: Component.onCompleted:
@ -93,7 +99,6 @@ Item
id: background id: background
color: UM.Theme.getColor("main_background") color: UM.Theme.getColor("main_background")
radius: 2 radius: 2
border.width: 1
border.color: UM.Theme.getColor("primary_button") border.color: UM.Theme.getColor("primary_button")
} }
height: UM.Theme.getSize("small_button_icon").height*2 height: UM.Theme.getSize("small_button_icon").height*2