Skip to content

Commit

Permalink
VACMS-10176: Fix Featured events when no featured event is live on He…
Browse files Browse the repository at this point in the history
…alth Care Region Pages (#1811)

* update featured events to pull 1000 events and filtering is done by FE


---------

Co-authored-by: Chris Kim <[email protected]>
  • Loading branch information
chriskim2311 and Chris Kim authored Nov 30, 2023
1 parent bf47d27 commit 2e90691
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
25 changes: 25 additions & 0 deletions src/site/filters/liquid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/site/layouts/health_care_region_page.drupal.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
</section>
{% elsif eventTeasersAll.entities.0.reverseFieldListingNode.entities.length %}
{% assign upcomingEvents = eventTeasersAll.entities.0.reverseFieldListingNode.entities %}
{% assign sortedEvents = upcomingEvents | sortByDateKey: 'fieldDatetimeRangeTimezone', false %}
{% assign sortedEvents = upcomingEvents | filterAndSortEvents %}
<section>
<h2
class="vads-u-margin-top--4 vads-u-margin-bottom--2 medium-screen:vads-u-margin-bottom--2p5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 2e90691

Please sign in to comment.