Skip to content

Commit

Permalink
fix: sort by sim title in alphabetical order rather than lexical
Browse files Browse the repository at this point in the history
See #331.

Part of phetsims/qa#869.
  • Loading branch information
liammulh committed Feb 8, 2023
1 parent cb7cbea commit f233b39
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/client/components/TranslationReportTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const TranslationReportTable = ( { locale, localeName, wantsUntranslated } ) =>
<th>Sim Title
{
reportPopulated && reportRows.length > 1
? <SortButton onClick={() => handleSortButtonClick( 'simName' )}/>
? <SortButton onClick={() => handleSortButtonClick( 'simTitle' )}/>
: <></>
}
</th>
Expand Down
25 changes: 22 additions & 3 deletions src/client/jsx/getSortedTranslationReportRows.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { Link } from 'react-router-dom';
import getMinutesElapsed from '../../common/getMinutesElapsed.js';
import publicConfig from '../../common/publicConfig.js';
import alertErrorMessage from '../js/alertErrorMessage.js';

/**
* Return an array of translation report objects (i.e. stats used to make translation report rows) that have
Expand Down Expand Up @@ -49,13 +50,31 @@ const getReportObjectsWithPercentages = reportObjects => {
*/
const sortReportObjectsWithPercentages = ( reportObjectsWithPercentages, sortDirection, sortKey ) => {
return reportObjectsWithPercentages.sort( ( a, b ) => {

let sortResult = 0;

// Parameter checking.
if ( typeof a[ sortKey ] !== typeof b[ sortKey ] ) {
alertErrorMessage( 'Values being sorted are not the same type.' );
}
const valuesAreStrings = typeof a[ sortKey ] === 'string' && typeof b[ sortKey ] === 'string';
if ( sortDirection === 'ascending' ) {
return a[ sortKey ] > b[ sortKey ] ? 1 : -1;
if ( valuesAreStrings ) {
sortResult = a[ sortKey ].toLowerCase() > b[ sortKey ].toLowerCase() ? 1 : -1;
}
else {
sortResult = a[ sortKey ] > b[ sortKey ] ? 1 : -1;
}
}
else if ( sortDirection === 'descending' ) {
return a[ sortKey ] > b[ sortKey ] ? -1 : 1;
if ( valuesAreStrings ) {
sortResult = a[ sortKey ].toLowerCase() > b[ sortKey ].toLowerCase() ? -1 : 1;
}
else {
sortResult = a[ sortKey ] > b[ sortKey ] ? -1 : 1;
}
}
return 0;
return sortResult;
} );
};

Expand Down

0 comments on commit f233b39

Please sign in to comment.