Skip to content

Commit

Permalink
feat: use enum for sort keys
Browse files Browse the repository at this point in the history
Part of #332.

Also part of phetsims/qa#869.
  • Loading branch information
liammulh committed Feb 8, 2023
1 parent 2ed69f1 commit 98229df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/client/components/TranslationReportTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* eslint-disable indent */

import SortKeyEnum from '../js/SortKeyEnum.js';
import { useContext, useState } from 'react';
import useTranslatedAndUntranslatedSims from '../hooks/useTranslatedAndUntranslatedSims.jsx';
import useTranslationReportObjects from '../hooks/useTranslationReportObjects.jsx';
Expand Down Expand Up @@ -36,7 +37,7 @@ const TranslationReportTable = ( { locale, localeName, wantsUntranslated } ) =>
);

// State variables used in sorting the table.
const [ sortKey, setSortKey ] = useState( 'simTitle' );
const [ sortKey, setSortKey ] = useState( SortKeyEnum.SIM_TITLE );
const [ sortDirection, setSortDirection ] = useState( 'ascending' );

const translatedAndUntranslatedSims = useTranslatedAndUntranslatedSims( locale );
Expand Down Expand Up @@ -77,21 +78,21 @@ const TranslationReportTable = ( { locale, localeName, wantsUntranslated } ) =>
<th>Sim Title
{
reportPopulated && reportRows.length > 1
? <SortButton onClick={() => handleSortButtonClick( 'simTitle' )}/>
? <SortButton onClick={() => handleSortButtonClick( SortKeyEnum.SIM_TITLE )}/>
: <></>
}
</th>
<th>Sim-Specific Strings
{
reportPopulated && reportRows.length > 1
? <SortButton onClick={() => handleSortButtonClick( 'simSpecificPercent' )}/>
? <SortButton onClick={() => handleSortButtonClick( SortKeyEnum.SIM_SPECIFIC_PERCENT )}/>
: <></>
}
</th>
<th>Common Strings
{
reportPopulated && reportRows.length > 1
? <SortButton onClick={() => handleSortButtonClick( 'commonPercent' )}/>
? <SortButton onClick={() => handleSortButtonClick( SortKeyEnum.COMMON_PERCENT )}/>
: <></>
}
</th>
Expand Down
17 changes: 17 additions & 0 deletions src/client/js/SortKeyEnum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2022, University of Colorado Boulder

/**
* Export a sort key enum.
*
* @author Liam Mulhall <liammulh@gmail.com>
*/

const SortKeyEnum = {
SIM_TITLE: 'simTitle',
SIM_SPECIFIC_PERCENT: 'simSpecificPercent',
COMMON_PERCENT: 'commonPercent'
};

Object.freeze( SortKeyEnum );

export default SortKeyEnum;

0 comments on commit 98229df

Please sign in to comment.