Skip to content

Commit

Permalink
Fix sorting editable list by program code (indico#5582)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasr8 authored Nov 24, 2022
1 parent fa2db1e commit fc7e6db
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Bugfixes
- Fix always-disabled submit button when submitting an agreement response
on someone's behalf (:pr:`5574`)
- Disallow nonsensical retention periods and visibility durations (:pr:`5576`)
- Fix sorting by program code in editable list (:pr:`5582`)

Internal Changes
^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {useNumericParam} from 'indico/react/util/routing';
import {indicoAxios, handleAxiosError} from 'indico/utils/axios';
import {camelizeKeys} from 'indico/utils/case';
import Palette from 'indico/utils/palette';
import {natSortCompare} from 'indico/utils/sort';

import StateIndicator from '../../editing/timeline/StateIndicator';
import {userPropTypes} from '../../editing/timeline/util';
Expand Down Expand Up @@ -201,25 +202,33 @@ function EditableListDisplay({
['editor', Translate.string('Editor'), 400],
];

const sortEditor = contribution =>
const programCodeKey = contribution => contribution.code;
const titleKey = contribution => contribution.title.toLowerCase();
const revisionKey = contribution => contribution.editable && contribution.editable.revisionCount;
const statusKey = contribution =>
contribution.editable && contribution.editable.state.toLowerCase();
const editorKey = contribution =>
contribution.editable &&
contribution.editable.editor &&
contribution.editable.editor.fullName.toLowerCase();
const sortStatus = contribution =>
contribution.editable && contribution.editable.state.toLowerCase();
const sortTitle = contribution => contribution.title.toLowerCase();

const sortKeys = {
code: programCodeKey,
title: titleKey,
revision: revisionKey,
status: statusKey,
editor: editorKey,
};

const sortFuncs = {
title: sortTitle,
revision: contribution => contribution.editable && contribution.editable.revisionCount,
status: sortStatus,
editor: sortEditor,
code: (arr, key) => [...arr].sort((a, b) => natSortCompare(key(a), key(b))),
};

// eslint-disable-next-line no-shadow
const _sortList = (sortBy, sortDirection, filteredResults) => {
const fn = sortFuncs[sortBy] || (x => x);
const newList = _.sortBy(contribList, fn);
const sortKey = sortKeys[sortBy] || (x => x[sortBy]);
const sortFn = sortFuncs[sortBy] || ((arr, key) => _.sortBy(arr, key));
const newList = sortFn(contribList, sortKey);
if (sortDirection === SortDirection.DESC) {
newList.reverse();
}
Expand Down

0 comments on commit fc7e6db

Please sign in to comment.