diff --git a/src/site/filters/liquid.js b/src/site/filters/liquid.js index 0e8dfad5f2..a3901471db 100644 --- a/src/site/filters/liquid.js +++ b/src/site/filters/liquid.js @@ -1109,6 +1109,31 @@ module.exports = function registerFilters() { }); }; + //* Filters and Sorts event dates (fieldDatetimeRangeTimezone) starting with the most upcoming event. + liquid.filters.filterAndSortEvents = data => { + if (!data) return null; + const currentTimestamp = moment().unix(); + + const filteredEvents = data.filter(event => { + const occurrenceArray = event.fieldDatetimeRangeTimezone.map( + occurrence => { + return occurrence.value; + }, + ); + const futureOccurrences = occurrenceArray.filter( + occurrence => occurrence >= currentTimestamp, + ); + + return futureOccurrences.length > 0; + }); + + return liquid.filters.sortByDateKey( + filteredEvents, + 'fieldDatetimeRangeTimezone', + false, + ); + }; + //* paginatePages has limitations, it is not yet fully operational. liquid.filters.paginatePages = (page, items, aria) => { const perPage = 10; diff --git a/src/site/layouts/health_care_region_page.drupal.liquid b/src/site/layouts/health_care_region_page.drupal.liquid index 2a415871ec..b52d748521 100644 --- a/src/site/layouts/health_care_region_page.drupal.liquid +++ b/src/site/layouts/health_care_region_page.drupal.liquid @@ -186,7 +186,7 @@ {% elsif eventTeasersAll.entities.0.reverseFieldListingNode.entities.length %} {% assign upcomingEvents = eventTeasersAll.entities.0.reverseFieldListingNode.entities %} - {% assign sortedEvents = upcomingEvents | sortByDateKey: 'fieldDatetimeRangeTimezone', false %} + {% assign sortedEvents = upcomingEvents | filterAndSortEvents %}

diff --git a/src/site/stages/build/drupal/graphql/healthCareRegionPage.graphql.js b/src/site/stages/build/drupal/graphql/healthCareRegionPage.graphql.js index afc59ed962..20020ff070 100644 --- a/src/site/stages/build/drupal/graphql/healthCareRegionPage.graphql.js +++ b/src/site/stages/build/drupal/graphql/healthCareRegionPage.graphql.js @@ -105,7 +105,7 @@ const nodeHealthCareRegionPage = ` eventTeasersAll: reverseFieldOfficeNode(limit: 1, filter: {conditions: [{field: "type", value: "event_listing"}]}) { entities { ... on NodeEventListing { - reverseFieldListingNode(sort: {field: "field_datetime_range_timezone", direction: ASC }, limit: 10, filter: {conditions: [{field: "type", value: "event"}, {field: "status", value: "1"}, { field: "field_datetime_range_timezone", value: [$today], operator: GREATER_THAN}]}) { + reverseFieldListingNode(sort: {field: "field_datetime_range_timezone", direction: ASC }, limit: 1000, filter: {conditions: [{field: "type", value: "event"}, {field: "status", value: "1"}]}) { entities { ... nodeEventWithoutBreadcrumbs } @@ -116,7 +116,7 @@ const nodeHealthCareRegionPage = ` eventTeasersFeatured: reverseFieldOfficeNode(limit: 1000, filter: {conditions: [{field: "type", value: "event_listing"}]}) { entities { ... on NodeEventListing { - reverseFieldListingNode(limit: 5000, filter: {conditions: [{field: "type", value: "event"}, {field: "status", value: "1"}, {field: "field_featured", value: "1"}, { field: "field_datetime_range_timezone", value: [$today], operator: GREATER_THAN}]}) { + reverseFieldListingNode(limit: 5000, filter: {conditions: [{field: "type", value: "event"}, {field: "status", value: "1"}, {field: "field_featured", value: "1"}]}) { entities { ... nodeEventWithoutBreadcrumbs }