diff --git a/src/store/index.js b/src/store/index.js index 5a153e731..aa1979e0a 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -2172,7 +2172,8 @@ export const actions = { }, saveSupportingItems(context, supportingItems) { - if (!deepEqual(supportingItems, context.state.order.lineItems.supportingItems)) { + syncLineItemIds(supportingItems, context.state.order.lineItems.supportingItems); + if (!supportingItemsEqual(supportingItems, context.state.order.lineItems.supportingItems)) { context.dispatch(storeActions.RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES); } addGuidToLineItemsIfNotAlreadyThere(supportingItems); @@ -2969,6 +2970,7 @@ function syncLineItemIds(lineItemsWithoutIds, lineItemsWithIds) { } }); if (matchedLineItemIndex > -1) { + // Remove the matched line item clonedLineItemsWithIds.splice(matchedLineItemIndex, 1); } }); @@ -2985,6 +2987,29 @@ function providersEqual(providerA, providerB) { //TODO: Change back to deepEqual once zipCodeCtu is added to saveSession. } +function supportingItemsEqual(supportingItemsA, supportingItemsB) { + if (typeof supportingItemsA !== typeof supportingItemsB) { + return false; + } + if (supportingItemsA === null || supportingItemsB === null) { + return supportingItemsA === supportingItemsB; + } + if (supportingItemsA.length != supportingItemsB.length) { + return false; + } + const sortedA = supportingItemsA.slice().sort(); + const sortedB = supportingItemsB.slice().sort(); + for (let i = 0; i < sortedA.length; i++) { + if ( + sortedA[i].partNumber != sortedB[i].partNumber || + sortedA[i].partType != sortedB[i].partType + ) { + return false; + } + } + return true; +} + // This function will verify schedule info is still valid. // check to see if we have an appointment date on the order object. // if so, make sure it's not in the past. if in the past, clear schedule info in store.