Merge pull request #3234 from Safelite/feature/CASH-2752

refactor | scheduling | extract appendDays helper and document index key stability
This commit is contained in:
scottkiener-at-safelite 2026-06-22 10:36:36 -04:00 committed by GitHub
commit cbf3f239f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -88,6 +88,20 @@ function toDateString(offsetDays, base = new Date()) {
const SCHEDULE_FETCH_DAYS = 15; const SCHEDULE_FETCH_DAYS = 15;
const SCHEDULING_RADIO_GROUP_NAME = "schedulingTimeSlot"; 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. * Returns a promise for inshop time slots for a single provider.
* @param {{ startDate: string, endDate: string, providerNumber: string, pageNameToLog: string }} params * @param {{ startDate: string, endDate: string, providerNumber: string, pageNameToLog: string }} params
@ -326,29 +340,13 @@ export default {
const resultMap = await settleAllPromises(promiseResultMap); const resultMap = await settleAllPromises(promiseResultMap);
// Provider order is fixed after beforeRouteEnter, so index keys are stable.
this.inShopProvidersAndTimeslots.forEach((entry, index) => { this.inShopProvidersAndTimeslots.forEach((entry, index) => {
const newSlots = resultMap[`inshopTimeSlots_${index}`]; appendDays(entry, resultMap[`inshopTimeSlots_${index}`]);
if (!newSlots) return;
if (!entry.timeSlots) {
entry.timeSlots = newSlots;
} else {
entry.timeSlots.days = [
...(entry.timeSlots.days ?? []),
...(newSlots.days ?? []),
];
}
}); });
if (this.mobileProviderAndTimeSlot && resultMap.mobileTimeSlots) { if (this.mobileProviderAndTimeSlot) {
const newSlots = resultMap.mobileTimeSlots; appendDays(this.mobileProviderAndTimeSlot, resultMap.mobileTimeSlots);
if (!this.mobileProviderAndTimeSlot.timeSlots) {
this.mobileProviderAndTimeSlot.timeSlots = newSlots;
} else {
this.mobileProviderAndTimeSlot.timeSlots.days = [
...(this.mobileProviderAndTimeSlot.timeSlots.days ?? []),
...(newSlots.days ?? []),
];
}
} }
this.datePickerEndDate = newEndDate; this.datePickerEndDate = newEndDate;