Skip to content

Commit

Permalink
Fixed: both the item change buttons becomes active after changing tab
Browse files Browse the repository at this point in the history
As we are using indexOf method for finding the product index, but if we already have a current product set, then in that case the product from state is used for finging the index from the filteredItems list, but as the object do not have a common reference, so in this case it always return -1, resulting in buttons being in wrong state.
Improved code to find the selected current product first in the filtered items list and then finding its index, so that it has a common reference
  • Loading branch information
ymaheshwari1 committed Oct 29, 2024
1 parent cdcb9a6 commit fa2126a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/views/CountDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ function updateFilteredItems() {
});
}
if (filteredItems.value.length > 0) {
const updatedProduct = Object.keys(product.value)?.length ? product.value : filteredItems.value[0]
// As we want to get the index of the product, if we directly store the product in the updatedProduct variable it does not return the index
// as both the object becomes different because of the reference, so if we have a product, then first finding it in the filtered list to have a common reference and then getting the index
const updatedProduct = Object.keys(product.value)?.length ? filteredItems.value.find((item) => item.productId === product.value.productId && item.importItemSeqId === product.value.importItemSeqId) : filteredItems.value[0]
store.dispatch("product/currentProduct", updatedProduct);
updateNavigationState(filteredItems.value.indexOf(updatedProduct));
} else {
Expand Down

0 comments on commit fa2126a

Please sign in to comment.