Skip to content

Commit

Permalink
fix event date grouping with restricted coverage info enabled (#706)
Browse files Browse the repository at this point in the history
the coverage date info is removed when restricted coverage
is enabled but then it gets `undefined` which adds a current
date to the list of item extra dates and make each event with
planning data show up as starting today.

STTNHUB-305
  • Loading branch information
petrjasek authored Dec 20, 2023
1 parent 2cf3e62 commit f47bf4a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions assets/agenda/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ export function getHighlightedDescription(item: any, plan: any) {
* @param {Object} item
* @return {Array} list of dates
*/
export function getExtraDates(item: any) {
export function getExtraDates(item: any): Array<moment.Moment> {
return getDisplayDates(item).map((ed: any) => moment(ed.date));
}

Expand All @@ -636,7 +636,7 @@ export function getExtraDates(item: any) {
* @param item: Event or Planning item
* @returns {Array.<{date: moment.Moment}>}
*/
export function getDisplayDates(item: any) {
export function getDisplayDates(item: any): Array<{date: string}> {
const matchedPlanning = get(item, '_hits.matched_planning_items');

if (matchedPlanning == null) {
Expand All @@ -658,7 +658,7 @@ export function getDisplayDates(item: any) {

const coverages = (get(plan, 'coverages') || []).filter((coverage: any) => coverage.scheduled);

if (!coverages.length) {
if (!coverages.length && plan.planning_date != null) {
dates.push({date: plan.planning_date});
return;
}
Expand All @@ -668,7 +668,11 @@ export function getDisplayDates(item: any) {
return;
}

dates.push({date: coverage.planning.scheduled});
if (coverage.planning?.scheduled != null) {
// when restricted coverage is enabled
// there might be no date
dates.push({date: coverage.planning.scheduled});
}
});
});

Expand Down Expand Up @@ -763,7 +767,7 @@ export function groupItems(items: any, activeDate: any, activeGrouping: any, fea
for (const day = start.clone(); day.isSameOrBefore(end, 'day'); day.add(1, 'd')) {
const isBetween = isBetweenDay(day, itemStartDate, itemEndDate, item.dates.all_day, item.dates.no_end_time);
const containsExtra = containsExtraDate(item, day);
const addGroupItem = (item.event == null || get(item, '_hits.matched_planning_items') != null) ?
const addGroupItem = (item.event == null || get(item, '_hits.matched_planning_items') != null) && itemExtraDates.length ?
containsExtra :
isBetween || containsExtra;

Expand Down

0 comments on commit f47bf4a

Please sign in to comment.