Skip to content

Commit

Permalink
fix agenda sort options (#1027)
Browse files Browse the repository at this point in the history
CPCN-911
  • Loading branch information
petrjasek authored Aug 13, 2024
1 parent 204ac8f commit 562ee02
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 99 deletions.
2 changes: 1 addition & 1 deletion assets/agenda/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ function setListGroupsAndLoadHiddenItems(items: Array<IAgendaItem>, next?: boole
}
}

const groups: Array<IAgendaListGroup> = (searchParams.sortQuery ?? '_score') === '_score' ?
const groups: Array<IAgendaListGroup> = (searchParams.sortQuery ?? '') === '' ?
groupItems(items, minDate, maxDate, activeGrouping, featuredOnly) :
[{
date: '',
Expand Down
7 changes: 6 additions & 1 deletion assets/agenda/components/AgendaApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,12 @@ class AgendaApp extends SearchBase<any> {
setQuery={this.props.setQuery}
setSortQuery={this.props.setSortQuery}
showSortDropdown={true}
defaultSortValue="_score"
sortOptions={[
{label: gettext('Date'), value: ''},
{label: gettext('Newest updates'), value: 'versioncreated:desc'},
{label: gettext('Oldest updates'), value: 'versioncreated:asc'},
{label: gettext('Relevance'), value: '_score'},
]}
/>
)
}
Expand Down
2 changes: 1 addition & 1 deletion assets/agenda/components/AgendaMetaTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function AgendaMetaTime({item, borderRight, isRecurring, group, i
{'m-0': onlyDates})}
>
{format(item, onlyDates === true)}
{itemDays <= 1 ? null : (
{itemDays <= 1 || group === '' ? null : (
<MultiDayListLabel
current={diffDays}
days={itemDays}
Expand Down
2 changes: 1 addition & 1 deletion assets/components/cards/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const CARD_TYPES: Array<ICardUnified> = [
},
{
_id: 'wire-list',
text: gettext('wire-list'),
text: gettext('Wire list'),
editComponent: ConfigWireList,
dashboardComponent: WireListCard,
size: 4,
Expand Down
2 changes: 1 addition & 1 deletion assets/interfaces/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {ITopic} from './topic';
import {INavigation} from './navigation';
import {IProduct} from './product';

export type ISearchSortValue = 'versioncreated:desc' | 'versioncreated:asc' | '_score';
export type ISearchSortValue = 'versioncreated:desc' | 'versioncreated:asc' | '_score' | '';

export interface ICreatedFilter {
from?: string;
Expand Down
52 changes: 28 additions & 24 deletions assets/search/components/SearchResultsBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import {Dropdown} from './../../../components/Dropdown';
import {SearchResultTagsList} from './SearchResultTagsList';
import {IDateFilter} from 'interfaces/common';

interface ISortOption {
label: string;
value: ISearchSortValue;
}

interface IReduxStoreProps {
user: IUser;
searchParams: ISearchParams;
Expand All @@ -44,16 +49,20 @@ interface IDispatchProps {
resetFilter(): void;
}

function getSortValueLabel(sortValue: ISearchSortValue): string {
switch (sortValue) {
case 'versioncreated:desc':
return gettext('Newest first');
case 'versioncreated:asc':
return gettext('Oldest first');
case '_score':
return gettext('Relevance');
}
}
const defaultSortOptions: ISortOption[] = [
{
value: '', // versioncreated:desc is default
label: gettext('Newest first'),
},
{
value: 'versioncreated:asc',
label: gettext('Oldest first'),
},
{
value: '_score',
label: gettext('Relevance'),
},
];

interface IOwnProps {
initiallyOpen?: boolean;
Expand All @@ -66,7 +75,7 @@ interface IOwnProps {
activeTopic: ITopic;
topicType: ITopic['topic_type'];
saveMyTopic?: (params: ISearchParams) => void;
defaultSortValue?: ISearchSortValue;
sortOptions?: ISortOption[];

refresh(): void;
onClearAll?(): void;
Expand All @@ -79,7 +88,6 @@ type IProps = IReduxStoreProps & IDispatchProps & IOwnProps;

interface IState {
isTagSectionShown: boolean;
sortValue: ISearchSortValue;
}


Expand All @@ -98,7 +106,6 @@ class SearchResultsBarComponent extends React.Component<IProps, IState> {
this.topicNotNull = new URLSearchParams(window.location.search).get('topic') != null;
this.state = {
isTagSectionShown: this.props.initiallyOpen || this.topicNotNull,
sortValue: this.props.defaultSortValue ?? 'versioncreated:desc',
};

this.toggleTagSection = this.toggleTagSection.bind(this);
Expand Down Expand Up @@ -173,11 +180,9 @@ class SearchResultsBarComponent extends React.Component<IProps, IState> {
render() {
const {isTagSectionShown} = this.state;
const numberFormatter = (new Intl.NumberFormat(undefined, {style: 'decimal'}));
const sortValues: Array<ISearchSortValue> = [
'versioncreated:desc',
'versioncreated:asc',
'_score',
];

const sortOptions = this.props.sortOptions || defaultSortOptions;
const selectedSortOption = sortOptions.find((option) => option.value === (this.props.searchParams.sortQuery || ''));

return (
<React.Fragment>
Expand All @@ -201,21 +206,20 @@ class SearchResultsBarComponent extends React.Component<IProps, IState> {
{this.props.showSortDropdown !== true ? null : (
<Dropdown
label={gettext('Sort by:')}
value={getSortValueLabel(this.state.sortValue)}
value={selectedSortOption?.label}
className={'sorting-dropdown'}
dropdownMenuHeader={gettext('Sort results by')}
>
{sortValues.map((sortValue) => (
{sortOptions.map((sortOption) => (
<button
key={sortValue}
key={sortOption.value}
type="button"
className="dropdown-item"
onClick={() => {
this.setSortQuery(sortValue);
this.setState({sortValue: sortValue});
this.setSortQuery(sortOption.value);
}}
>
{getSortValueLabel(sortValue)}
{sortOption.label}
</button>
))}
</Dropdown>
Expand Down
Loading

0 comments on commit 562ee02

Please sign in to comment.