Skip to content

Commit

Permalink
Merge pull request #10741 from wellcomecollection/isavailable-changes
Browse files Browse the repository at this point in the history
`IsAvailableOnline` event filter; Find true bucket to get count
  • Loading branch information
rcantin-w committed Mar 18, 2024
2 parents 6d6ee51 + 20cef12 commit d6ab428
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
19 changes: 12 additions & 7 deletions content/webapp/services/wellcome/common/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,13 +630,18 @@ const eventsAudienceFilter = ({
const eventsIsAvailableOnlineFilter = ({
events,
props,
}: EventsFilterProps): BooleanFilter<keyof EventsProps> => ({
type: 'boolean',
id: 'isAvailableOnline',
label: 'Catch-up events only',
count: events?.aggregations?.isAvailableOnline?.buckets?.[1]?.count || 0,
isSelected: !!props.isAvailableOnline,
});
}: EventsFilterProps): BooleanFilter<keyof EventsProps> => {
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 = ({
Expand Down
3 changes: 2 additions & 1 deletion content/webapp/services/wellcome/content/types/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ArticleFormatId } from '@weco/content/data/content-format-ids';
import {
BooleanBucketData,
WellcomeAggregation,
WellcomeResultList,
} from '@weco/content/services/wellcome';
Expand Down Expand Up @@ -116,7 +117,7 @@ export type ArticleAggregations = BasicAggregations & {
export type EventAggregations = BasicAggregations & {
audience: WellcomeAggregation;
interpretation: WellcomeAggregation;
isAvailableOnline: WellcomeAggregation;
isAvailableOnline: WellcomeAggregation<BooleanBucketData>;
};

// Results
Expand Down
5 changes: 5 additions & 0 deletions content/webapp/services/wellcome/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit d6ab428

Please sign in to comment.