From 20cef12ae2fecf2787f4fac06e9d1e150bd3bc8e Mon Sep 17 00:00:00 2001 From: Raphaelle Cantin Date: Mon, 18 Mar 2024 12:04:02 +0000 Subject: [PATCH] Find true bucket to get count --- .../services/wellcome/common/filters.ts | 19 ++++++++++++------- .../services/wellcome/content/types/api.ts | 3 ++- content/webapp/services/wellcome/index.ts | 5 +++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/content/webapp/services/wellcome/common/filters.ts b/content/webapp/services/wellcome/common/filters.ts index 9c5c44fb6e..c534e60df7 100644 --- a/content/webapp/services/wellcome/common/filters.ts +++ b/content/webapp/services/wellcome/common/filters.ts @@ -630,13 +630,18 @@ const eventsAudienceFilter = ({ const eventsIsAvailableOnlineFilter = ({ events, props, -}: EventsFilterProps): BooleanFilter => ({ - type: 'boolean', - id: 'isAvailableOnline', - label: 'Catch-up events only', - count: events?.aggregations?.isAvailableOnline?.buckets?.[1]?.count || 0, - isSelected: !!props.isAvailableOnline, -}); +}: EventsFilterProps): BooleanFilter => { + const isAvailableOnlineTrueBucket = + events?.aggregations?.isAvailableOnline.buckets.find(b => b.data.value); + + return { + type: 'boolean', + id: 'isAvailableOnline', + label: 'Catch-up events only', + count: isAvailableOnlineTrueBucket?.count || 0, + isSelected: !!props.isAvailableOnline, + }; +}; // TODO re-add when https://github.com/wellcomecollection/content-api/issues/106 is done // const eventsInterpretationFilter = ({ diff --git a/content/webapp/services/wellcome/content/types/api.ts b/content/webapp/services/wellcome/content/types/api.ts index bb5be0b750..922630f54e 100644 --- a/content/webapp/services/wellcome/content/types/api.ts +++ b/content/webapp/services/wellcome/content/types/api.ts @@ -1,5 +1,6 @@ import { ArticleFormatId } from '@weco/content/data/content-format-ids'; import { + BooleanBucketData, WellcomeAggregation, WellcomeResultList, } from '@weco/content/services/wellcome'; @@ -116,7 +117,7 @@ export type ArticleAggregations = BasicAggregations & { export type EventAggregations = BasicAggregations & { audience: WellcomeAggregation; interpretation: WellcomeAggregation; - isAvailableOnline: WellcomeAggregation; + isAvailableOnline: WellcomeAggregation; }; // Results diff --git a/content/webapp/services/wellcome/index.ts b/content/webapp/services/wellcome/index.ts index e75cc21d78..70fa3cdbeb 100644 --- a/content/webapp/services/wellcome/index.ts +++ b/content/webapp/services/wellcome/index.ts @@ -55,9 +55,14 @@ export type UnidentifiedBucketData = { type: string; }; +export type BooleanBucketData = UnidentifiedBucketData & { + value: boolean; +}; + export type WellcomeAggregation< BucketData extends | IdentifiedBucketData + | BooleanBucketData | UnidentifiedBucketData = IdentifiedBucketData, > = { buckets: {