From 996ad3cc58758531d521becef0a25cb2c6ba3a18 Mon Sep 17 00:00:00 2001 From: scottkiener-at-safelite Date: Mon, 22 Jun 2026 10:24:59 -0400 Subject: [PATCH] refactor(scheduling): extract appendDays helper and document index key stability Replace duplicated init-or-concat logic in handleRequestMoreDates with a shared appendDays function. Add a comment clarifying that inshopTimeSlots_N keys are safe to use by index because provider order is fixed after beforeRouteEnter. --- src/layouts/scheduling/scheduling.vue | 38 +++++++++++++-------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/layouts/scheduling/scheduling.vue b/src/layouts/scheduling/scheduling.vue index 7cca53596..b889826c8 100644 --- a/src/layouts/scheduling/scheduling.vue +++ b/src/layouts/scheduling/scheduling.vue @@ -88,6 +88,20 @@ function toDateString(offsetDays, base = new Date()) { const SCHEDULE_FETCH_DAYS = 15; const SCHEDULING_RADIO_GROUP_NAME = "schedulingTimeSlot"; +/** + * Appends days from newSlots into entry.timeSlots, initializing it if absent. + * @param {{ timeSlots: { days: any[] } | null }} entry + * @param {{ days: any[] } | null | undefined} newSlots + */ +function appendDays(entry, newSlots) { + if (!newSlots) return; + if (!entry.timeSlots) { + entry.timeSlots = newSlots; + } else { + entry.timeSlots.days = [...(entry.timeSlots.days ?? []), ...(newSlots.days ?? [])]; + } +} + /** * Returns a promise for inshop time slots for a single provider. * @param {{ startDate: string, endDate: string, providerNumber: string, pageNameToLog: string }} params @@ -326,29 +340,13 @@ export default { const resultMap = await settleAllPromises(promiseResultMap); + // Provider order is fixed after beforeRouteEnter, so index keys are stable. this.inShopProvidersAndTimeslots.forEach((entry, index) => { - const newSlots = resultMap[`inshopTimeSlots_${index}`]; - if (!newSlots) return; - if (!entry.timeSlots) { - entry.timeSlots = newSlots; - } else { - entry.timeSlots.days = [ - ...(entry.timeSlots.days ?? []), - ...(newSlots.days ?? []), - ]; - } + appendDays(entry, resultMap[`inshopTimeSlots_${index}`]); }); - if (this.mobileProviderAndTimeSlot && resultMap.mobileTimeSlots) { - const newSlots = resultMap.mobileTimeSlots; - if (!this.mobileProviderAndTimeSlot.timeSlots) { - this.mobileProviderAndTimeSlot.timeSlots = newSlots; - } else { - this.mobileProviderAndTimeSlot.timeSlots.days = [ - ...(this.mobileProviderAndTimeSlot.timeSlots.days ?? []), - ...(newSlots.days ?? []), - ]; - } + if (this.mobileProviderAndTimeSlot) { + appendDays(this.mobileProviderAndTimeSlot, resultMap.mobileTimeSlots); } this.datePickerEndDate = newEndDate;