bug - missing shifts display ¶
CATS-637
background ¶
shift data is pulled down without related ‘site’ information. a ‘site id’
is on a shift, and a single set of site info is pulled down once.
ScheduleMixin.js has a loadShifts() call which will iterate
over returned shift data and merge in related ‘site’ info client-side,
saving duplication of loading/merging/transmitting redundant data
potentially multiple times.
The shift data includes a site_id, but currently the get shifts call does not check if a site is ‘active’ or not. The initial ‘get sites’ call will only return ‘active’ sites, so when the client side merging in loadShifts() is looking for, say site_id 4494300, and that site is non-active and therefore not in the list, the shift’s site is ‘undefined’.
problem ¶
Filtering code in Schedule.vue was aware of the potential problem, checking for shift.site truthiness, but did it backwards.
this.selectedSites.length === 0
|| _.find(this.selectedSites, (f) => {
const selectedSiteIdMatches = parseInt(f.id, 10) === parseInt(shift.site.id, 10);
return (shift.site
&& shift.site.id
&& selectedSiteIdMatches);
}))
This still was potentially using shift.site even if it didn’t exist.
fix ¶
Patched code
this.selectedSites.length === 0
|| _.find(this.selectedSites, (f) => {
const selectedSiteIdMatches = shift.site
&& (parseInt(f.id, 10) === parseInt(shift.site.id, 10));
return (shift.site
&& shift.site.id
&& selectedSiteIdMatches);
}))