From f7944dd393511869fedf643ef83f5b5cdb92fe1d Mon Sep 17 00:00:00 2001 From: Petr Jasek Date: Wed, 15 May 2024 09:09:17 +0200 Subject: [PATCH 1/4] implement ui config for hiding item type filters in agenda STTNHUB-238 --- assets/agenda/components/AgendaApp.tsx | 6 --- assets/agenda/components/AgendaFilters.tsx | 51 ++++++++++--------- .../components/AgendaItemTypeFilter.tsx | 40 ++++++++------- assets/agenda/selectors.ts | 10 ++-- assets/interfaces/agenda.ts | 10 +++- assets/interfaces/configs.ts | 10 +++- 6 files changed, 73 insertions(+), 54 deletions(-) diff --git a/assets/agenda/components/AgendaApp.tsx b/assets/agenda/components/AgendaApp.tsx index be73266f9..860b3ba3a 100644 --- a/assets/agenda/components/AgendaApp.tsx +++ b/assets/agenda/components/AgendaApp.tsx @@ -234,13 +234,11 @@ class AgendaApp extends SearchBase {
{!this.props.bookmarks && ( )} { @@ -350,7 +348,6 @@ AgendaApp.propTypes = { closePreview: PropTypes.func, navigations: PropTypes.array.isRequired, activeNavigation: PropTypes.arrayOf(PropTypes.string), - aggregations: PropTypes.object, toggleDropdownFilter: PropTypes.func, selectDate: PropTypes.func, activeDate: PropTypes.number, @@ -365,7 +362,6 @@ AgendaApp.propTypes = { eventsOnlyAccess: PropTypes.bool, restrictCoverageInfo: PropTypes.bool, itemTypeFilter: PropTypes.string, - locators: PropTypes.array, searchParams: PropTypes.object, showSaveTopic: PropTypes.bool, previewConfig: PropTypes.object, @@ -395,7 +391,6 @@ const mapStateToProps = (state: any) => ({ activeTopic: activeTopicSelector(state), activeNavigation: searchNavigationSelector(state), bookmarks: state.bookmarks, - aggregations: state.aggregations, activeDate: get(state, 'agenda.activeDate'), activeGrouping: get(state, 'agenda.activeGrouping'), eventsOnlyAccess: get(state, 'agenda.eventsOnlyAccess', false), @@ -406,7 +401,6 @@ const mapStateToProps = (state: any) => ({ userSections: state.userSections, featuredOnly: get(state, 'agenda.featuredOnly'), context: state.context, - locators: get(state, 'locators.items', []), setQuery: PropTypes.func.isRequired, searchParams: searchParamsSelector(state), showSaveTopic: showSaveTopicSelector(state), diff --git a/assets/agenda/components/AgendaFilters.tsx b/assets/agenda/components/AgendaFilters.tsx index b100d002d..8ec98d689 100644 --- a/assets/agenda/components/AgendaFilters.tsx +++ b/assets/agenda/components/AgendaFilters.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import PropTypes from 'prop-types'; import {connect} from 'react-redux'; import {get} from 'lodash'; @@ -12,6 +11,8 @@ import AgendaCoverageExistsFilter from './AgendaCoverageExistsFilter'; import AgendaItemTypeFilter from './AgendaItemTypeFilter'; import {AgendaCalendarAgendaFilter} from './AgendaCalendarAgendaFilter'; import {LocationFilter} from './LocationFilter'; +import {IAgendaState} from 'interfaces/agenda'; +import {ISearchState} from 'interfaces/search'; export const transformFilterBuckets = (filter: any, aggregations: any, props: any) => { if (!filter.transformBuckets) { @@ -21,17 +22,18 @@ export const transformFilterBuckets = (filter: any, aggregations: any, props: an return filter.transformBuckets(filter, aggregations, props); }; -const renderFilter: any = { - item_type: (props: any) => ( +const renderFilter = { + item_type: (props: IProps) => ( ), - calendar: (props: any) => ( + calendar: (props: IProps) => ( ), - location: (props: any) => ( + location: (props: IProps) => ( !['events', 'combined'].includes(props.itemTypeFilter || 'combined') ? null : ( ) ), - region: (props: any) => ( + region: (props: IProps) => ( !['events', 'planning', 'combined'].includes(props.itemTypeFilter || 'combined') ? null : ( ) ), - coverage_type: (props: any) => ( + coverage_type: (props: IProps) => ( !['planning', 'combined'].includes(props.itemTypeFilter || 'combined') ? null : ( ) ), - coverage_status: (props: any) => ( + coverage_status: (props: IProps) => ( (props.eventsOnlyAccess || props.itemTypeFilter === 'events') ? null : ( - {props.filtersConfig.map((filterName: any) => ( + {props.filtersConfig.map((filterName) => ( renderFilter[filterName](props) ))}
); } -AgendaFiltersComponent.propTypes = { - aggregations: PropTypes.object, - toggleFilter: PropTypes.func, - activeFilter: PropTypes.object, - eventsOnlyAccess: PropTypes.bool, - restrictCoverageInfo: PropTypes.bool, - itemTypeFilter: PropTypes.string, - locators: PropTypes.arrayOf(PropTypes.object), - filtersConfig: PropTypes.arrayOf(PropTypes.string), -}; +interface IOwnProps { + toggleFilter: (fieldName: string, value?: string | null) => void; + activeFilter: ISearchState['activeFilter']; + eventsOnlyAccess: boolean; + restrictCoverageInfo: boolean; + itemTypeFilter?: 'events' | 'planning' | 'combined'; +} -const mapStateToProps = (state: any) => ({ +const mapStateToProps = (state: IAgendaState) => ({ + aggregations: state.aggregations, filtersConfig: agendaFiltersConfigSelector(state), + locators: state.locators?.items || [], + itemTypeFilterConfig: state.uiConfig.subnav?.item_type || {}, + subnavConfig: state, }); -const AgendaFilters: React.ComponentType = connect(mapStateToProps)(AgendaFiltersComponent); +type StateProps = ReturnType; + +type IProps = StateProps & IOwnProps; -export default AgendaFilters; +export default connect(mapStateToProps)(AgendaFiltersComponent); diff --git a/assets/agenda/components/AgendaItemTypeFilter.tsx b/assets/agenda/components/AgendaItemTypeFilter.tsx index 788316f62..a68f269cd 100644 --- a/assets/agenda/components/AgendaItemTypeFilter.tsx +++ b/assets/agenda/components/AgendaItemTypeFilter.tsx @@ -1,9 +1,17 @@ import React from 'react'; -import PropTypes from 'prop-types'; import {gettext} from 'utils'; import {AgendaDropdown} from './AgendaDropdown'; +import {ItemTypeFilterConfig} from 'interfaces/configs'; -function AgendaItemTypeFilter ({toggleFilter, itemTypeFilter, eventsOnlyAccess, restrictCoverageInfo}: any) { +interface IProps { + toggleFilter: (filedName: string, value: string | null) => void; + itemTypeFilter?: 'events' | 'planning' | 'combined'; + eventsOnlyAccess: boolean; + restrictCoverageInfo: boolean; + config?: ItemTypeFilterConfig; +} + +function AgendaItemTypeFilter ({toggleFilter, itemTypeFilter, eventsOnlyAccess, restrictCoverageInfo, config}: IProps) { if (eventsOnlyAccess) { return null; } @@ -16,7 +24,7 @@ function AgendaItemTypeFilter ({toggleFilter, itemTypeFilter, eventsOnlyAccess, ] }; - const filter: any = { + const filter = { label: gettext('Events & Coverages'), field: 'itemType', }; @@ -32,14 +40,16 @@ function AgendaItemTypeFilter ({toggleFilter, itemTypeFilter, eventsOnlyAccess, //dropdownMenuHeader={gettext('Item Types')} hideLabelOnMobile > - - {restrictCoverageInfo ? null : ( + {config?.events_only === false ? null : ( + + )} + {restrictCoverageInfo || config?.planning_only === false ? null : (