From 3cebf934531075717a1e09e2456c7611c596ad39 Mon Sep 17 00:00:00 2001 From: Mark Pittaway Date: Tue, 26 Nov 2024 13:50:09 +1100 Subject: [PATCH 1/2] [STTNHUB-379] fix: Planning items not shown in event preview with AGENDA_DEFAULT_FILTER_HIDE_PLANNING config --- assets/agenda/actions.ts | 4 ++-- assets/agenda/utils.ts | 18 +++++++++++++++--- assets/globals.d.ts | 1 + newsroom/agenda/__init__.py | 4 ++++ newsroom/agenda/agenda.py | 2 +- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/assets/agenda/actions.ts b/assets/agenda/actions.ts index afb577ab5..82f249d23 100644 --- a/assets/agenda/actions.ts +++ b/assets/agenda/actions.ts @@ -335,7 +335,7 @@ function setListGroupsAndLoadHiddenItems(items: Array, next?: boole // If there are groups shown, then load the hidden items for those groups const state = getState(); - const {activeGrouping, featuredOnly} = state.agenda; + const {activeGrouping, featuredOnly, itemType} = state.agenda; const {fromDate, toDate, searchParams} = getAgendaSearchParamsFromState(state); let minDate: moment.Moment | undefined; @@ -376,7 +376,7 @@ function setListGroupsAndLoadHiddenItems(items: Array, next?: boole } const groups: Array = (searchParams.sortQuery ?? '') === '' ? - groupItems(items, minDate, maxDate, activeGrouping, featuredOnly) : + groupItems(items, minDate, maxDate, activeGrouping, featuredOnly, itemType) : [{ date: '', items: items.map((item) => item._id), diff --git a/assets/agenda/utils.ts b/assets/agenda/utils.ts index dd0db0144..fa7336b55 100644 --- a/assets/agenda/utils.ts +++ b/assets/agenda/utils.ts @@ -1,7 +1,15 @@ import {get, isEmpty, keyBy, sortBy} from 'lodash'; import moment from 'moment/moment'; -import {IAgendaItem, IPlanningItem, IAgendaListGroup, IAgendaListGroupItem, ICoverage, IUser} from 'interfaces'; +import { + IAgendaItem, + IPlanningItem, + IAgendaListGroup, + IAgendaListGroupItem, + ICoverage, + IUser, + IAgendaState +} from 'interfaces'; import { formatDate, formatMonth, @@ -701,8 +709,12 @@ export function groupItems( minDate: moment.Moment | undefined, maxDate: moment.Moment | undefined, activeGrouping: string, - featuredOnly?: boolean + featuredOnly?: boolean, + itemTypeFilter?: IAgendaState['agenda']['itemType'] ): Array { + const excludePlanningExtraDates = (itemTypeFilter == null || itemTypeFilter === 'events') && + window.newsroom.client_config.agenda_default_filter_hide_planning === true; + if (items.length === 0) { return []; } @@ -719,7 +731,7 @@ export function groupItems( item._hits?.matched_coverages?.length )) .forEach((item) => { - const itemExtraDates = getExtraDates(item); + const itemExtraDates = excludePlanningExtraDates ? [] : getExtraDates(item); const itemStartDate = getStartDate(item); let start: moment.Moment; diff --git a/assets/globals.d.ts b/assets/globals.d.ts index 2015be61b..88f577d75 100644 --- a/assets/globals.d.ts +++ b/assets/globals.d.ts @@ -65,6 +65,7 @@ interface IClientConfig { show_user_register?: boolean; multimedia_website_search_url?: string; show_default_time_frame_label?: boolean; + agenda_default_filter_hide_planning: boolean; } interface Window { diff --git a/newsroom/agenda/__init__.py b/newsroom/agenda/__init__.py index ea08bfbd9..e263668df 100644 --- a/newsroom/agenda/__init__.py +++ b/newsroom/agenda/__init__.py @@ -83,3 +83,7 @@ def init_app(app): if app.config.get("AGENDA_HIDE_COVERAGE_ASSIGNEES"): PRIVATE_FIELDS.extend(["*.assigned_desk_*", "*.assigned_user_*"]) + + app.config["CLIENT_CONFIG"]["agenda_default_filter_hide_planning"] = app.config.get( + "AGENDA_DEFAULT_FILTER_HIDE_PLANNING", False + ) diff --git a/newsroom/agenda/agenda.py b/newsroom/agenda/agenda.py index e116f2ce6..271f5b847 100644 --- a/newsroom/agenda/agenda.py +++ b/newsroom/agenda/agenda.py @@ -993,7 +993,7 @@ def apply_filters(self, search: SearchQuery, section_filters=None): }, } ) - _remove_fields(search.source, ["planning_items", "display_dates"]) + _remove_fields(search.source, ["display_dates"]) else: # Don't include Planning items that are associated with an Event search.query["bool"]["filter"].append( From cd7b743e68d1627f5d1bb75b1336ee742fe192a2 Mon Sep 17 00:00:00 2001 From: Mark Pittaway Date: Wed, 27 Nov 2024 07:23:08 +1100 Subject: [PATCH 2/2] fix tests: add agenda_default_filter_hide_planning to client_config --- assets/tests.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/assets/tests.ts b/assets/tests.ts index 17d3882ea..f0d34798e 100644 --- a/assets/tests.ts +++ b/assets/tests.ts @@ -94,6 +94,7 @@ window.newsroom = { }, system_alert_recipients: '', wire_time_limit_days: 0, + agenda_default_filter_hide_planning: false, }, };