Skip to content

Commit d785e9c

Browse files
committed
Agenda (Calendar) Location filter improvement [CPCN-935]
1 parent 9fc7cdf commit d785e9c

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

assets/agenda/components/LocationFilter.tsx

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import classNames from 'classnames';
44
import {get, debounce} from 'lodash';
55

6-
import {gettext} from 'utils';
6+
import {gettext, getConfig} from 'utils';
77
import server from 'server';
88
import {KEYS} from 'common';
99

@@ -315,9 +315,9 @@ export class LocationFilter extends React.Component<any, any> {
315315
*/
316316
renderRegionSearchResult(item: any, index: any) {
317317
const {selectedIndex} = this.state;
318-
319-
if (item.type === LOCATION_TYPE.CITY) {
320-
return (
318+
const enabledOptions = getConfig('calendar_location_filter_options');
319+
if (item.type === LOCATION_TYPE.CITY && enabledOptions.city) {
320+
return(
321321
<button
322322
key={`city.${item.name}[${index}]`}
323323
data-item-index={index}
@@ -336,7 +336,8 @@ export class LocationFilter extends React.Component<any, any> {
336336
})}
337337
</button>
338338
);
339-
} else if (item.type === LOCATION_TYPE.STATE) {
339+
} else if (item.type === LOCATION_TYPE.STATE && enabledOptions.state) {
340+
const stateLabel = getConfig('location_state_display_label');
340341
return (
341342
<button
342343
key={`state.${item.name}[${index}]`}
@@ -349,13 +350,14 @@ export class LocationFilter extends React.Component<any, any> {
349350
)}
350351
onClick={() => this.onChange(item)}
351352
>
352-
{gettext('{{ name }} (State, {{ country }})', {
353+
{gettext('{{ name }} ({{ label }}, {{ country }})', {
353354
name: item.name,
355+
label: stateLabel,
354356
country: item.country,
355357
})}
356358
</button>
357359
);
358-
} else if (item.type === LOCATION_TYPE.COUNTRY) {
360+
} else if (item.type === LOCATION_TYPE.COUNTRY && enabledOptions.country) {
359361
return (
360362
<button
361363
key={`country.${item.name}[${index}]`}
@@ -371,7 +373,7 @@ export class LocationFilter extends React.Component<any, any> {
371373
{gettext('{{ name }} (Country)', {name: item.name})}
372374
</button>
373375
);
374-
} else {
376+
} else if (enabledOptions.places && !['city', 'state', 'country'].includes(item.type)) {
375377
const results = this.state.results;
376378

377379
return (
@@ -389,6 +391,8 @@ export class LocationFilter extends React.Component<any, any> {
389391
{item}
390392
</button>
391393
);
394+
} else {
395+
return null;
392396
}
393397
}
394398

@@ -432,6 +436,7 @@ export class LocationFilter extends React.Component<any, any> {
432436
render() {
433437
const activeFilter = get(this.props, 'activeFilter.location') || {};
434438
const isActive = activeFilter.type != null;
439+
const isPlaceEnabled = getConfig('calendar_location_filter_options').places;
435440

436441
return (
437442
<div
@@ -522,17 +527,21 @@ export class LocationFilter extends React.Component<any, any> {
522527
</button>
523528
)}
524529

525-
<h6 className="dropdown-menu__section-heading">{gettext('Places')}</h6>
526-
{this.state.results.places.length > 0 ? (
527-
this.state.results.places.map(this.renderRegionSearchResult)
528-
) : (
529-
<button
530-
key="empty-places"
531-
className="dropdown-item disabled"
532-
disabled={true}
533-
>
534-
{gettext('No places found')}
535-
</button>
530+
{isPlaceEnabled && (
531+
<>
532+
<h6 className="dropdown-menu__section-heading">{gettext('Places')}</h6>
533+
{this.state.results.places.length > 0 ? (
534+
this.state.results.places.map(this.renderRegionSearchResult)
535+
) : (
536+
<button
537+
key="empty-places"
538+
className="dropdown-item disabled"
539+
disabled={true}
540+
>
541+
{gettext('No places found')}
542+
</button>
543+
)}
544+
</>
536545
)}
537546
</React.Fragment>
538547
)}

assets/globals.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ interface IClientConfig {
6565
show_user_register?: boolean;
6666
multimedia_website_search_url?: string;
6767
show_default_time_frame_label?: boolean;
68+
calendar_location_filter_options?:{city: boolean, state: boolean, country: boolean, place:boolean};
69+
location_state_display_label?:boolean;
6870
}
6971

7072
interface Window {

newsroom/web/default_settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,13 @@
399399
},
400400
"agenda_sort_events_with_coverage_on_top": False,
401401
"collapsed_search_by_default": False,
402+
"calendar_location_filter_options": {
403+
"city": True,
404+
"state": True,
405+
"country": True,
406+
"place": True,
407+
},
408+
"location_state_display_label": "State",
402409
}
403410

404411
# Enable rendering of the date in the base view

0 commit comments

Comments
 (0)